Search in sources :

Example 31 with Builder

use of android.net.Uri.Builder in project android_packages_apps_Dialer by LineageOS.

the class PhoneNumberListAdapter method configureLoader.

@Override
public void configureLoader(CursorLoader loader, long directoryId) {
    String query = getQueryString();
    if (query == null) {
        query = "";
    }
    if (isExtendedDirectory(directoryId)) {
        final DirectoryPartition directory = getExtendedDirectoryFromId(directoryId);
        final String contentUri = directory.getContentUri();
        if (contentUri == null) {
            throw new IllegalStateException("Extended directory must have a content URL: " + directory);
        }
        final Builder builder = Uri.parse(contentUri).buildUpon();
        builder.appendPath(query);
        builder.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY, String.valueOf(getDirectoryResultLimit(directory)));
        loader.setUri(builder.build());
        loader.setProjection(PhoneQuery.PROJECTION_PRIMARY);
    } else {
        final boolean isRemoteDirectoryQuery = DirectoryCompat.isRemoteDirectoryId(directoryId);
        final Builder builder;
        if (isSearchMode()) {
            final Uri baseUri;
            if (isRemoteDirectoryQuery) {
                baseUri = PhoneCompat.getContentFilterUri();
            } else if (mUseCallableUri) {
                baseUri = CallableCompat.getContentFilterUri();
            } else {
                baseUri = PhoneCompat.getContentFilterUri();
            }
            builder = baseUri.buildUpon();
            // Builder will encode the query
            builder.appendPath(query);
            builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId));
            if (isRemoteDirectoryQuery) {
                builder.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY, String.valueOf(getDirectoryResultLimit(getDirectoryById(directoryId))));
            }
        } else {
            Uri baseUri = mUseCallableUri ? Callable.CONTENT_URI : Phone.CONTENT_URI;
            builder = baseUri.buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT));
            if (isSectionHeaderDisplayEnabled()) {
                builder.appendQueryParameter(Phone.EXTRA_ADDRESS_BOOK_INDEX, "true");
            }
            applyFilter(loader, builder, directoryId, getFilter());
        }
        // Ignore invalid phone numbers that are too long. These can potentially cause freezes
        // in the UI and there is no reason to display them.
        final String prevSelection = loader.getSelection();
        final String newSelection;
        if (!TextUtils.isEmpty(prevSelection)) {
            newSelection = prevSelection + " AND " + IGNORE_NUMBER_TOO_LONG_CLAUSE;
        } else {
            newSelection = IGNORE_NUMBER_TOO_LONG_CLAUSE;
        }
        loader.setSelection(newSelection);
        // Remove duplicates when it is possible.
        builder.appendQueryParameter(ContactsContract.REMOVE_DUPLICATE_ENTRIES, "true");
        loader.setUri(builder.build());
        // TODO a projection that includes the search snippet
        if (getContactNameDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY) {
            loader.setProjection(PhoneQuery.PROJECTION_PRIMARY);
        } else {
            loader.setProjection(PhoneQuery.PROJECTION_ALTERNATIVE);
        }
        if (getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY) {
            loader.setSortOrder(Phone.SORT_KEY_PRIMARY);
        } else {
            loader.setSortOrder(Phone.SORT_KEY_ALTERNATIVE);
        }
    }
}
Also used : Builder(android.net.Uri.Builder) Uri(android.net.Uri)

Example 32 with Builder

use of android.net.Uri.Builder in project packages_apps_Contacts by AOKP.

the class MultiPickContactActivity method getContactsFilterUri.

/**
 * Just get the uri we need to query contacts.
 *
 * @return uri with account info parameter if explicit request contacts fit
 *         current account, else just search contacts fit specified keyword.
 */
private Uri getContactsFilterUri() {
    Uri filterUri = Contacts.CONTENT_FILTER_URI;
    // To confirm if the search rule must contain account limitation.
    Intent intent = getIntent();
    ContactListFilter filter = (ContactListFilter) intent.getParcelableExtra(AccountFilterActivity.KEY_EXTRA_CONTACT_LIST_FILTER);
    int operation = getIntent().getIntExtra(ADD_MOVE_GROUP_MEMBER_KEY, -1);
    long groupId = getIntent().getLongExtra(KEY_GROUP_ID, -1);
    String accountName = getIntent().getStringExtra(SimContactsConstants.ACCOUNT_NAME);
    String accountType = getIntent().getStringExtra(SimContactsConstants.ACCOUNT_TYPE);
    switch(operation) {
        case ACTION_ADD_GROUP_MEMBER:
        case ACTION_MOVE_GROUP_MEMBER:
            Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
            builder.appendQueryParameter(ADD_GROUP_MEMBERS, String.valueOf(operation == ACTION_ADD_GROUP_MEMBER));
            builder.appendQueryParameter(Groups._ID, String.valueOf(groupId));
            builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
            builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
            return builder.build();
    }
    if (filter != null && filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) {
        // Need consider account info limitation, construct the uri with
        // account info query parameter.
        Builder builder = filterUri.buildUpon();
        filter.addAccountQueryParameterToUrl(builder);
        return builder.build();
    }
    if (!isShowSIM()) {
        filterUri = filterUri.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimAccountType.ACCOUNT_TYPE).appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, "true").build();
    }
    // with "filter" path.
    return filterUri;
}
Also used : Builder(android.net.Uri.Builder) Intent(android.content.Intent) Uri(android.net.Uri) ContactListFilter(com.android.contacts.common.list.ContactListFilter)

Example 33 with Builder

use of android.net.Uri.Builder in project packages_apps_Contacts by AOKP.

the class PostalAddressListAdapter method configureLoader.

@Override
public void configureLoader(CursorLoader loader, long directoryId) {
    final Builder builder = StructuredPostal.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.REMOVE_DUPLICATE_ENTRIES, "true");
    if (isSectionHeaderDisplayEnabled()) {
        builder.appendQueryParameter(StructuredPostal.EXTRA_ADDRESS_BOOK_INDEX, "true");
    }
    loader.setUri(builder.build());
    if (getContactNameDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY) {
        loader.setProjection(PostalQuery.PROJECTION_PRIMARY);
    } else {
        loader.setProjection(PostalQuery.PROJECTION_ALTERNATIVE);
    }
    if (getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY) {
        loader.setSortOrder(StructuredPostal.SORT_KEY_PRIMARY);
    } else {
        loader.setSortOrder(StructuredPostal.SORT_KEY_ALTERNATIVE);
    }
}
Also used : Builder(android.net.Uri.Builder)

Example 34 with Builder

use of android.net.Uri.Builder in project packages_apps_Contacts by AOKP.

the class ContactsFragment method getContactsFilterUri.

/**
 * Just get the uri we need to query contacts.
 *
 * @return uri with account info parameter if explicit request contacts fit current account,
 *         else just search contacts fit specified keyword.
 */
private Uri getContactsFilterUri() {
    Uri filterUri = Contacts.CONTENT_FILTER_URI;
    // To confirm if the search rule must contain account limitation.
    Intent intent = mPickMode.getIntent();
    ContactListFilter filter = (ContactListFilter) intent.getParcelableExtra(AccountFilterActivity.KEY_EXTRA_CONTACT_LIST_FILTER);
    int operation = intent.getIntExtra(ADD_MOVE_GROUP_MEMBER_KEY, -1);
    long groupId = intent.getLongExtra(KEY_GROUP_ID, -1);
    String accountName = intent.getStringExtra(SimContactsConstants.ACCOUNT_NAME);
    String accountType = intent.getStringExtra(SimContactsConstants.ACCOUNT_TYPE);
    switch(operation) {
        case ACTION_ADD_GROUP_MEMBER:
        case ACTION_MOVE_GROUP_MEMBER:
            Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
            builder.appendQueryParameter(ADD_GROUP_MEMBERS, String.valueOf(operation == ACTION_ADD_GROUP_MEMBER));
            builder.appendQueryParameter(Groups._ID, String.valueOf(groupId));
            builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
            builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
            return builder.build();
    }
    if (filter != null && filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) {
        // Need consider account info limitation, construct the uri with
        // account info query parameter.
        Builder builder = filterUri.buildUpon();
        filter.addAccountQueryParameterToUrl(builder);
        return builder.build();
    }
    if (!isShowSIM()) {
        filterUri = filterUri.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimAccountType.ACCOUNT_TYPE).appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, "true").build();
    }
    // with "filter" path.
    return filterUri;
}
Also used : Builder(android.net.Uri.Builder) Intent(android.content.Intent) SpannableString(android.text.SpannableString) Uri(android.net.Uri) ContactListFilter(com.android.contacts.common.list.ContactListFilter)

Example 35 with Builder

use of android.net.Uri.Builder in project packages_apps_Contacts by AOKP.

the class JoinContactListAdapter method configureLoader.

@Override
public void configureLoader(CursorLoader cursorLoader, long directoryId) {
    JoinContactLoader loader = (JoinContactLoader) cursorLoader;
    final Builder builder = Contacts.CONTENT_URI.buildUpon();
    builder.appendEncodedPath(String.valueOf(mTargetContactId));
    builder.appendEncodedPath(AggregationSuggestions.CONTENT_DIRECTORY);
    final String filter = getQueryString();
    if (!TextUtils.isEmpty(filter)) {
        builder.appendEncodedPath(Uri.encode(filter));
    }
    builder.appendQueryParameter("limit", String.valueOf(MAX_SUGGESTIONS));
    builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimContactsConstants.ACCOUNT_TYPE_SIM);
    builder.appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, "true");
    loader.setSuggestionUri(builder.build());
    // TODO simplify projection
    loader.setProjection(getProjection(false));
    final Uri allContactsUri;
    if (!TextUtils.isEmpty(filter)) {
        allContactsUri = buildSectionIndexerUri(Contacts.CONTENT_FILTER_URI).buildUpon().appendEncodedPath(Uri.encode(filter)).appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)).appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimContactsConstants.ACCOUNT_TYPE_SIM).appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, "true").build();
    } else {
        allContactsUri = buildSectionIndexerUri(Contacts.CONTENT_URI).buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)).appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimContactsConstants.ACCOUNT_TYPE_SIM).appendQueryParameter(SimContactsConstants.WITHOUT_SIM_FLAG, "true").build();
    }
    loader.setUri(allContactsUri);
    loader.setSelection(Contacts._ID + "!=?");
    loader.setSelectionArgs(new String[] { String.valueOf(mTargetContactId) });
    if (getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY) {
        loader.setSortOrder(Contacts.SORT_KEY_PRIMARY);
    } else {
        loader.setSortOrder(Contacts.SORT_KEY_ALTERNATIVE);
    }
}
Also used : Builder(android.net.Uri.Builder) Uri(android.net.Uri)

Aggregations

Builder (android.net.Uri.Builder)35 Uri (android.net.Uri)27 ContentValues (android.content.ContentValues)5 Cursor (android.database.Cursor)5 Intent (android.content.Intent)2 SpannableString (android.text.SpannableString)2 ContactListFilter (com.android.contacts.common.list.ContactListFilter)2 AlertDialog (android.app.AlertDialog)1 ContentResolver (android.content.ContentResolver)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 Contact (org.awesomeapp.messenger.model.Contact)1