Example usage for android.provider ContactsContract LIMIT_PARAM_KEY

List of usage examples for android.provider ContactsContract LIMIT_PARAM_KEY

Introduction

In this page you can find the example usage for android.provider ContactsContract LIMIT_PARAM_KEY.

Prototype

String LIMIT_PARAM_KEY

To view the source code for android.provider ContactsContract LIMIT_PARAM_KEY.

Click Source Link

Document

A query parameter that limits the number of results returned for supported URIs.

Usage

From source file:com.android.contacts.DynamicShortcuts.java

public List<ShortcutInfo> getStrequentShortcuts() {
    // The limit query parameter doesn't seem to work for this uri but we'll leave it because in
    // case it does work on some phones or platform versions.
    final Uri uri = Contacts.CONTENT_STREQUENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY, String.valueOf(MAX_SHORTCUTS)).build();
    final Cursor cursor = mContentResolver.query(uri, PROJECTION, null, null, null);

    if (cursor == null)
        return Collections.emptyList();

    final List<ShortcutInfo> result = new ArrayList<>();

    try {//from ww w .  ja v  a 2  s  .co  m
        int i = 0;
        while (i < MAX_SHORTCUTS && cursor.moveToNext()) {
            final ShortcutInfo shortcut = createShortcutFromRow(cursor);
            if (shortcut == null) {
                continue;
            }
            result.add(shortcut);
            i++;
        }
    } finally {
        cursor.close();
    }
    return result;
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

private static Cursor doQuery(CharSequence constraint, int limit, Long directoryId, Account account,
        ContentResolver resolver, Query query) {
    final Uri.Builder builder = query.getContentFilterUri().buildUpon().appendPath(constraint.toString())
            .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                    String.valueOf(limit + BaseRecipientAdapter.ALLOWANCE_FOR_DUPLICATES));
    if (directoryId != null) {
        builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
    }//from   ww w  . j  av a 2  s .  c om
    if (account != null) {
        builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_NAME, account.name);
        builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_TYPE, account.type);
    }
    final Cursor cursor = resolver.query(builder.build(), query.getProjection(), null, null, null);
    return cursor;
}

From source file:cm.confide.ex.chips.BaseRecipientAdapter.java

private Cursor doQuery(CharSequence constraint, int limit, Long directoryId) {
    final Uri.Builder builder = mQuery.getContentFilterUri().buildUpon().appendPath(constraint.toString())
            .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                    String.valueOf(limit + ALLOWANCE_FOR_DUPLICATES));
    if (directoryId != null) {
        builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
    }/*from  www  .j a  v a 2s . c  o m*/
    if (mAccount != null) {
        builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME, mAccount.name);
        builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE, mAccount.type);
    }
    final long start = System.currentTimeMillis();
    final Cursor cursor = mContentResolver.query(builder.build(), mQuery.getProjection(), null, null, null);
    final long end = System.currentTimeMillis();
    if (DEBUG) {
        Log.d(TAG,
                "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId
                        + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): "
                        + (end - start) + " ms");
    }
    return cursor;
}

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

private Cursor doQuery(CharSequence constraint, int limit, Long directoryId) {
    final Uri.Builder builder = Phone.CONTENT_FILTER_URI.buildUpon().appendPath(constraint.toString())
            .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                    String.valueOf(limit + ALLOWANCE_FOR_DUPLICATES));
    if (directoryId != null) {
        builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
    }//from  w  w w .j  av a 2s .c om
    if (mAccount != null) {
        builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME, mAccount.name);
        builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE, mAccount.type);
    }
    final long start = System.currentTimeMillis();
    final Cursor cursor = mContentResolver.query(builder.build(), EmailQuery.PROJECTION, null, null, null);
    final long end = System.currentTimeMillis();
    if (DEBUG) {
        Log.d(TAG,
                "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId
                        + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): "
                        + (end - start) + " ms");
    }
    return cursor;
}

From source file:com.github.shareme.gwschips.library.BaseRecipientAdapter.java

private Cursor doQuery(CharSequence constraint, int limit, Long directoryId) {
    final Uri.Builder builder = mQuery.getContentFilterUri().buildUpon();
    builder.appendPath(constraint.toString());
    builder.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
            String.valueOf(limit + ALLOWANCE_FOR_DUPLICATES));

    if (directoryId != null) {
        builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
    }/*from   ww w  .ja va 2 s . c  o m*/
    if (mAccount != null) {
        builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME, mAccount.name);
        builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE, mAccount.type);
    }
    String where = (showMobileOnly && mQueryType == QUERY_TYPE_PHONE)
            ? ContactsContract.CommonDataKinds.Phone.TYPE + "="
                    + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE
            : null;
    final long start = System.currentTimeMillis();
    final Cursor cursor = mContentResolver.query(limit == -1 ? mQuery.getContentUri() : builder.build(),
            mQuery.getProjection(), where, null,
            limit == -1 ? ContactsContract.Contacts.DISPLAY_NAME + " ASC" : null);
    final long end = System.currentTimeMillis();
    if (DEBUG) {
        Log.d(TAG,
                "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId
                        + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): "
                        + (end - start) + " ms");
    }
    return cursor;
}

From source file:com.android.mtkex.chips.BaseRecipientAdapter.java

private Cursor doQuery(CharSequence constraint, int limit, Long directoryId) {
    final Uri.Builder builder = mQuery.getContentFilterUri().buildUpon().appendPath(constraint.toString())
            .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                    String.valueOf(limit + ALLOWANCE_FOR_DUPLICATES));
    if (directoryId != null) {
        builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
    }/*from w w  w .  j a  va 2s  . c  o m*/
    if (mAccount != null) {
        builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME, mAccount.name);
        builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE, mAccount.type);
    }
    final long start = System.currentTimeMillis();
    Cursor cursor = mContentResolver.query(/// M: Cursor might be modified later
            builder.build(), mQuery.getProjection(), null, null, Contacts.DISPLAY_NAME);
    final long end = System.currentTimeMillis();
    Log.d(TAG, "[doQuery] 1st query, constraint: " + constraint + ", result count: "
            + (cursor != null ? cursor.getCount() : "null")); /// M: MTK debug log
    if (DEBUG) {
        Log.d(TAG,
                "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId
                        + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): "
                        + (end - start) + " ms");
    }
    /// M: Show phone and email when filtering in phoneQuery. @{
    if ((mQueryType == QUERY_TYPE_PHONE) && mShowPhoneAndEmail) {
        /// M: Save number of current phone query results for checking whether the query result is from phone or email
        mQueryPhoneNum = cursor != null ? cursor.getCount() : 0;

        Queries.Query currentQuery = Queries.EMAIL;

        final Uri.Builder builder2 = currentQuery.getContentFilterUri().buildUpon()
                .appendPath(constraint.toString()).appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                        String.valueOf(limit + ALLOWANCE_FOR_DUPLICATES));
        if (directoryId != null) {
            builder2.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
        }
        if (mAccount != null) {
            builder2.appendQueryParameter(PRIMARY_ACCOUNT_NAME, mAccount.name);
            builder2.appendQueryParameter(PRIMARY_ACCOUNT_TYPE, mAccount.type);
        }

        Cursor cursor2 = mContentResolver.query(builder2.build(), currentQuery.getProjection(), null, null,
                Contacts.DISPLAY_NAME);
        Log.d(TAG, "[doQuery] 2nd query, constraint: " + constraint + ", result count: "
                + (cursor2 != null ? cursor2.getCount() : "null")); /// M: MTK debug log

        Cursor[] cursors = new Cursor[2];
        cursors[0] = cursor;
        cursors[1] = cursor2;
        cursor = new MergeCursor(cursors);
    }
    /// @}

    return cursor;
}