public CalendarSelectionPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    List<Pair<String, Boolean>> allCalendars = CalendarExtension.getAllCalendars(context);
    Set<String> allVisibleCalendarsSet = new HashSet<String>();
    for (Pair<String, Boolean> pair : allCalendars) {
      if (pair.second) {
        allVisibleCalendarsSet.add(pair.first);
      }
    }

    mSelectedCalendars =
        new HashSet<String>(
            PreferenceManager.getDefaultSharedPreferences(context)
                .getStringSet(CalendarExtension.PREF_SELECTED_CALENDARS, allVisibleCalendarsSet));

    mAdapter = new CalendarListAdapter(context);
    mQueryHandler = new QueryHandler(context, mAdapter);

    mQueryHandler.startQuery(
        0,
        null,
        CalendarContract.Calendars.CONTENT_URI,
        CalendarQuery.PROJECTION,
        CalendarContract.Calendars.SYNC_EVENTS + "=1",
        null,
        CalendarContract.Calendars.CALENDAR_DISPLAY_NAME);
  }
  /**
   * Internal method to query for contacts with a given display name.
   *
   * @param contactDisplayName the display name to look for.
   */
  private void startDisambiguationQuery(String contactDisplayName) {
    // Apply a limit of 1 result to the query because we only need to
    // determine whether or not at least one other contact has the same
    // name. We don't need to find ALL other contacts with the same name.
    final Builder builder = Contacts.CONTENT_URI.buildUpon();
    builder.appendQueryParameter("limit", String.valueOf(1));
    final Uri uri = builder.build();

    final String displayNameSelection;
    final String[] selectionArgs;
    if (TextUtils.isEmpty(contactDisplayName)) {
      displayNameSelection = Contacts.DISPLAY_NAME_PRIMARY + " IS NULL";
      selectionArgs = new String[] {String.valueOf(mContactId)};
    } else {
      displayNameSelection = Contacts.DISPLAY_NAME_PRIMARY + " = ?";
      selectionArgs = new String[] {contactDisplayName, String.valueOf(mContactId)};
    }
    mQueryHandler.startQuery(
        TOKEN_DISAMBIGUATION_QUERY,
        null,
        uri,
        new String[] {Contacts._ID} /* unused projection but a valid one was needed */,
        displayNameSelection
            + " AND "
            + Contacts.PHOTO_ID
            + " IS NULL AND "
            + Contacts._ID
            + " <> ?",
        selectionArgs,
        null);
  }
Exemple #3
0
  /**
   * Common method for performing a query of the music database, called for both top-level queries
   * and filtering.
   *
   * @param sync If true, this query should be done synchronously and the resulting cursor returned.
   *     If false, it will be done asynchronously and null returned.
   * @param filterstring If non-null, this is a filter to apply to the query.
   */
  Cursor doQuery(boolean sync, String filterstring) {
    // Cancel any pending queries
    mQueryHandler.cancelOperation(MY_QUERY_TOKEN);

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Media.TITLE + " != ''");

    // We want to show all audio files, even recordings.  Enforcing the
    // following condition would hide recordings.
    // where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");

    Uri uri = mBaseUri;
    if (!TextUtils.isEmpty(filterstring)) {
      uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filterstring)).build();
    }

    if (sync) {
      try {
        return getContentResolver().query(uri, CURSOR_COLS, where.toString(), null, mSortOrder);
      } catch (UnsupportedOperationException ex) {
      }
    } else {
      mAdapter.setLoading(true);
      setProgressBarIndeterminateVisibility(true);
      mQueryHandler.startQuery(
          MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
    }
    return null;
  }
  /**
   * startContactQuery
   *
   * <p>internal method to query contact by Uri.
   *
   * @param contactUri the contact uri
   * @param resetQueryHandler whether to use a new AsyncQueryHandler or not
   */
  private void startContactQuery(Uri contactUri, boolean resetQueryHandler) {
    if (resetQueryHandler) {
      resetAsyncQueryHandler();
    }

    mQueryHandler.startQuery(
        TOKEN_CONTACT_INFO, null, contactUri, ContactQuery.COLUMNS, null, null, null);
  }
 /** Internal method to query for extra data fields for this contact. */
 private void startExtraInfoQuery() {
   mQueryHandler.startQuery(
       TOKEN_EXTRA_INFO_QUERY,
       null,
       Data.CONTENT_URI,
       ExtraInfoQuery.COLUMNS,
       RawContacts.CONTACT_ID + " = ?",
       new String[] {String.valueOf(mContactId)},
       null);
 }
 /**
  * Internal method to query contact photo by photo id and uri.
  *
  * @param photoId the photo id.
  * @param lookupKey the lookup uri.
  */
 private void startPhotoQuery(long photoId, Uri lookupKey) {
   mQueryHandler.startQuery(
       TOKEN_PHOTO_QUERY,
       lookupKey,
       ContentUris.withAppendedId(Data.CONTENT_URI, photoId),
       PhotoQuery.COLUMNS,
       null,
       null,
       null);
 }
  /**
   * Convenience method for binding all available data from an existing contact.
   *
   * @param number The phone number used to do a reverse lookup in the contacts database. If more
   *     than one contact contains this phone number, one of them will be chosen to bind to.
   */
  public void bindFromPhoneNumber(String number) {
    resetAsyncQueryHandler();

    mQueryHandler.startQuery(
        TOKEN_PHONE_LOOKUP,
        number,
        Uri.withAppendedPath(TPhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)),
        PHONE_LOOKUP_PROJECTION,
        null,
        null,
        null);
  }
  /**
   * Convenience method for binding all available data from an existing contact.
   *
   * @param emailAddress The email address used to do a reverse lookup in the contacts database. If
   *     more than one contact contains this email address, one of them will be chosen to bind to.
   */
  public void bindFromEmail(String emailAddress) {
    resetAsyncQueryHandler();

    mQueryHandler.startQuery(
        TOKEN_EMAIL_LOOKUP,
        emailAddress,
        Uri.withAppendedPath(TEmail.CONTENT_LOOKUP_URI, Uri.encode(emailAddress)),
        EMAIL_LOOKUP_PROJECTION,
        null,
        null,
        null);
  }
  private void startQuery() {
    mAdapter.setLoading(true);

    // Cancel any pending queries
    mQueryHandler.cancelOperation(QUERY_TOKEN);
    mQueryHandler.startQuery(
        QUERY_TOKEN,
        null,
        Calls.CONTENT_URI,
        CALL_LOG_PROJECTION,
        null,
        null,
        Calls.DEFAULT_SORT_ORDER);
  }
 public void query() {
   mLoadingBar.setVisibility(View.VISIBLE);
   // 查询类型为游戏的所有数据
   String selectionString = AppData.App.TYPE + "=?";
   String args[] = {"" + AppManager.ZHAOYAN_APP};
   mQueryHandler.startQuery(
       11,
       null,
       AppData.App.CONTENT_URI,
       PROJECTION,
       selectionString,
       args,
       AppData.App.SORT_ORDER_LABEL);
 }
  /**
   * startPhotoQuery
   *
   * <p>internal method to query contact photo by photo id and uri.
   *
   * @param photoId the photo id.
   * @param lookupKey the lookup uri.
   * @param resetQueryHandler whether to use a new AsyncQueryHandler or not.
   */
  protected void startPhotoQuery(long photoId, Uri lookupKey, boolean resetQueryHandler) {
    if (resetQueryHandler) {
      resetAsyncQueryHandler();
    }

    mQueryHandler.startQuery(
        TOKEN_PHOTO_QUERY,
        lookupKey,
        ContentUris.withAppendedId(TData.CONTENT_URI, photoId),
        PhotoQuery.COLUMNS,
        null,
        null,
        null);
  }
  @Override
  protected void onResume() {
    super.onResume();

    // If the cursor is null, start the async handler. If it is not null just requery.
    if (mCursor == null) {
      Uri uri = CalendarAlerts.CONTENT_URI_BY_INSTANCE;
      mQueryHandler.startQuery(
          0,
          null,
          uri,
          PROJECTION,
          SELECTION,
          SELECTIONARG,
          CalendarContract.CalendarAlerts.DEFAULT_SORT_ORDER);
    } else {
      if (!mCursor.requery()) {
        Log.w(TAG, "Cursor#requery() failed.");
        mCursor.close();
        mCursor = null;
      }
    }
  }
 /**
  * Internal method to query contact by Uri.
  *
  * @param contactUri the contact uri
  */
 private void startContactQuery(Uri contactUri) {
   mQueryHandler.startQuery(
       TOKEN_CONTACT_INFO, contactUri, contactUri, ContactQuery.COLUMNS, null, null, null);
 }
Exemple #14
0
  /**
   * Common method for performing a query of the music database, called for both top-level queries
   * and filtering.
   *
   * @param sync If true, this query should be done synchronously and the resulting cursor returned.
   *     If false, it will be done asynchronously and null returned.
   * @param filterstring If non-null, this is a filter to apply to the query.
   */
  Cursor doQuery(boolean sync, String filterstring) {
    MusicLogUtils.d(TAG, "doQuery(" + sync + ", " + filterstring + ")");
    // Cancel any pending queries
    mQueryHandler.cancelOperation(MY_QUERY_TOKEN);

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Media.TITLE + " != ''");

    /// M: determine the Dim level for query @{
    if (MusicFeatureOption.IS_SUPPORT_DRM) {
      String sIsDrm = MediaStore.Audio.Media.IS_DRM;
      String sDrmMethod = MediaStore.Audio.Media.DRM_METHOD;
      switch (mDrmLevel) {
        case OmaDrmStore.DrmExtra.DRM_LEVEL_FL:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + OmaDrmStore.DrmMethod.METHOD_FL
                  + "))");
          break;

        case OmaDrmStore.DrmExtra.DRM_LEVEL_SD:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + OmaDrmStore.DrmMethod.METHOD_SD
                  + "))");
          break;

        case OmaDrmStore.DrmExtra.DRM_LEVEL_ALL:
          break;

        case -1:
        default:
          // this intent does not contain DRM Extras
          where.append(" AND " + sIsDrm + "!=1");
          break;
      }
      MusicLogUtils.d(TAG, "doQuery: where=" + where);
    }
    /// @}

    // We want to show all audio files, even recordings.  Enforcing the
    // following condition would hide recordings.
    // where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");

    Uri uri = mBaseUri;
    if (!TextUtils.isEmpty(filterstring)) {
      uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filterstring)).build();
    }

    if (sync) {
      try {
        return getContentResolver().query(uri, CURSOR_COLS, where.toString(), null, mSortOrder);
      } catch (UnsupportedOperationException ex) {
      }
    } else {
      mAdapter.setLoading(true);
      mQueryHandler.startQuery(
          MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
    }
    return null;
  }
Exemple #15
0
 private void query() {
   Uri uri = resolveIntent();
   if (DBG) log("query: starting an async query");
   mQueryHandler.startQuery(QUERY_TOKEN, null, uri, COLUMN_NAMES, null, null, null);
   displayProgress(true);
 }
  private void doQuery(QuerySpec queryData) {
    if (!mAdapterInfos.isEmpty()) {
      int start = mAdapterInfos.getFirst().start;
      int end = mAdapterInfos.getLast().end;
      int queryDuration = calculateQueryDuration(start, end);
      switch (queryData.queryType) {
        case QUERY_TYPE_OLDER:
          queryData.end = start - 1;
          queryData.start = queryData.end - queryDuration;
          break;
        case QUERY_TYPE_NEWER:
          queryData.start = end + 1;
          queryData.end = queryData.start + queryDuration;
          break;
      }

      // By "compacting" cursors, this fixes the disco/ping-pong problem
      // b/5311977
      if (mRowCount < 20 && queryData.queryType != QUERY_TYPE_CLEAN) {
        if (DEBUGLOG) {
          Log.e(
              TAG,
              "Compacting cursor: mRowCount="
                  + mRowCount
                  + " totalStart:"
                  + start
                  + " totalEnd:"
                  + end
                  + " query.start:"
                  + queryData.start
                  + " query.end:"
                  + queryData.end);
        }

        queryData.queryType = QUERY_TYPE_CLEAN;

        if (queryData.start > start) {
          queryData.start = start;
        }
        if (queryData.end < end) {
          queryData.end = end;
        }
      }
    }

    if (BASICLOG) {
      Time time = new Time(mTimeZone);
      time.setJulianDay(queryData.start);
      Time time2 = new Time(mTimeZone);
      time2.setJulianDay(queryData.end);
      Log.v(
          TAG,
          "startQuery: "
              + time.toString()
              + " to "
              + time2.toString()
              + " then go to "
              + queryData.goToTime);
    }

    mQueryHandler.cancelOperation(0);
    if (BASICLOG) queryData.queryStartMillis = System.nanoTime();

    Uri queryUri = buildQueryUri(queryData.start, queryData.end, queryData.searchQuery);
    mQueryHandler.startQuery(
        0, queryData, queryUri, PROJECTION, buildQuerySelection(), null, AGENDA_SORT_ORDER);
  }