Example usage for android.provider ContactsContract DIRECTORY_PARAM_KEY

List of usage examples for android.provider ContactsContract DIRECTORY_PARAM_KEY

Introduction

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

Prototype

String DIRECTORY_PARAM_KEY

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

Click Source Link

Document

Query parameter that should be used by the client to access a specific Directory .

Usage

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  w w  w.j  a v a  2  s . co  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));
    }/*w w w .j ava2s. 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;
}