public AgendaWindowAdapter(
      Context context, AgendaListView agendaListView, boolean showEventOnStart) {
    mContext = context;
    mResources = context.getResources();
    mSelectedItemBackgroundColor = mResources.getColor(R.color.agenda_selected_background_color);
    mSelectedItemTextColor = mResources.getColor(R.color.agenda_selected_text_color);
    mItemRightMargin = mResources.getDimension(R.dimen.agenda_item_right_margin);
    mIsTabletConfig = Utils.getConfigBool(mContext, R.bool.tablet_config);

    mTimeZone = Utils.getTimeZone(context, mTZUpdater);
    mAgendaListView = agendaListView;
    mQueryHandler = new QueryHandler(context.getContentResolver());

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    mShowEventOnStart = showEventOnStart;

    // Implies there is no sticky header
    if (!mShowEventOnStart) {
      mStickyHeaderSize = 0;
    }
    mSearchQuery = null;

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mHeaderView = (TextView) inflater.inflate(R.layout.agenda_header_footer, null);
    mFooterView = (TextView) inflater.inflate(R.layout.agenda_header_footer, null);
    mHeaderView.setText(R.string.loading);
    mAgendaListView.addHeaderView(mHeaderView);
  }
  public void refresh(
      Time goToTime, long id, String searchQuery, boolean forced, boolean refreshEventInfo) {
    if (searchQuery != null) {
      mSearchQuery = searchQuery;
    }

    if (DEBUGLOG) {
      Log.e(
          TAG,
          this
              + ": refresh "
              + goToTime.toString()
              + " id "
              + id
              + ((searchQuery != null) ? searchQuery : "")
              + (forced ? " forced" : " not forced")
              + (refreshEventInfo ? " refresh event info" : ""));
    }

    int startDay = Time.getJulianDay(goToTime.toMillis(false), goToTime.gmtoff);

    if (!forced && isInRange(startDay, startDay)) {
      // No need to re-query
      if (!mAgendaListView.isAgendaItemVisible(goToTime, id)) {
        int gotoPosition = findEventPositionNearestTime(goToTime, id);
        if (gotoPosition > 0) {
          mAgendaListView.setSelectionFromTop(gotoPosition + OFF_BY_ONE_BUG, mStickyHeaderSize);
          if (mListViewScrollState == OnScrollListener.SCROLL_STATE_FLING) {
            mAgendaListView.smoothScrollBy(0, 0);
          }
          if (refreshEventInfo) {
            long newInstanceId = findInstanceIdFromPosition(gotoPosition);
            if (newInstanceId != getSelectedInstanceId()) {
              setSelectedInstanceId(newInstanceId);
              mDataChangedHandler.post(mDataChangedRunnable);
              Cursor tempCursor = getCursorByPosition(gotoPosition);
              if (tempCursor != null) {
                int tempCursorPosition = getCursorPositionByPosition(gotoPosition);
                AgendaItem item = buildAgendaItemFromCursor(tempCursor, tempCursorPosition, false);
                mSelectedVH = new AgendaAdapter.ViewHolder();
                mSelectedVH.allDay = item.allDay;
                sendViewEvent(item, goToTime.toMillis(false));
              }
            }
          }
        }

        Time actualTime = new Time(mTimeZone);
        actualTime.set(goToTime);
        CalendarController.getInstance(mContext)
            .sendEvent(this, EventType.UPDATE_TITLE, actualTime, actualTime, -1, ViewType.CURRENT);
      }
      return;
    }

    // If AllInOneActivity is sending a second GOTO event(in OnResume), ignore it.
    if (!mCleanQueryInitiated || searchQuery != null) {
      // Query for a total of MIN_QUERY_DURATION days
      int endDay = startDay + MIN_QUERY_DURATION;

      mSelectedInstanceId = -1;
      mCleanQueryInitiated = true;
      queueQuery(startDay, endDay, goToTime, searchQuery, QUERY_TYPE_CLEAN, id);

      // Pre-fetch more data to overcome a race condition in AgendaListView.shiftSelection
      // Queuing more data with the goToTime set to the selected time skips the call to
      // shiftSelection on refresh.
      mOlderRequests++;
      queueQuery(0, 0, goToTime, searchQuery, QUERY_TYPE_OLDER, id);
      mNewerRequests++;
      queueQuery(0, 0, goToTime, searchQuery, QUERY_TYPE_NEWER, id);
    }
  }