Search in sources :

Example 1 with ContactListAdapter

use of com.android.contacts.common.list.ContactListAdapter in project packages_apps_Contacts by AOKP.

the class ContactBrowseListFragment method selectDefaultContact.

protected void selectDefaultContact() {
    Uri contactUri = null;
    ContactListAdapter adapter = getAdapter();
    if (mLastSelectedPosition != -1) {
        int count = adapter.getCount();
        int pos = mLastSelectedPosition;
        if (pos >= count && count > 0) {
            pos = count - 1;
        }
        contactUri = adapter.getContactUri(pos);
    }
    if (contactUri == null) {
        contactUri = adapter.getFirstContactUri();
    }
    setSelectedContactUri(contactUri, false, mSmoothScrollRequested, false, false);
}
Also used : ContactListAdapter(com.android.contacts.common.list.ContactListAdapter) Uri(android.net.Uri)

Example 2 with ContactListAdapter

use of com.android.contacts.common.list.ContactListAdapter in project packages_apps_Contacts by AOKP.

the class ContactBrowseListFragment method configureAdapter.

@Override
protected void configureAdapter() {
    super.configureAdapter();
    ContactListAdapter adapter = getAdapter();
    if (adapter == null) {
        return;
    }
    boolean searchMode = isSearchMode();
    if (!searchMode && mFilter != null) {
        adapter.setFilter(mFilter);
        if (mSelectionRequired || mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) {
            adapter.setSelectedContact(mSelectedContactDirectoryId, mSelectedContactLookupKey, mSelectedContactId);
        }
    }
    // Display the user's profile if not in search mode
    adapter.setIncludeProfile(!searchMode);
}
Also used : ContactListAdapter(com.android.contacts.common.list.ContactListAdapter)

Example 3 with ContactListAdapter

use of com.android.contacts.common.list.ContactListAdapter in project packages_apps_Contacts by AOKP.

the class ContactBrowseListFragment method setSelectedContactUri.

/**
 * Sets the new contact selection.
 *
 * @param uri the new selection
 * @param required if true, we need to check if the selection is present in
 *            the list and if not notify the listener so that it can load a
 *            different list
 * @param smoothScroll if true, the UI will roll smoothly to the new
 *            selection
 * @param persistent if true, the selection will be stored in shared
 *            preferences.
 * @param willReloadData if true, the selection will be remembered but not
 *            actually shown, because we are expecting that the data will be
 *            reloaded momentarily
 */
private void setSelectedContactUri(Uri uri, boolean required, boolean smoothScroll, boolean persistent, boolean willReloadData) {
    mSmoothScrollRequested = smoothScroll;
    mSelectionToScreenRequested = true;
    if ((mSelectedContactUri == null && uri != null) || (mSelectedContactUri != null && !mSelectedContactUri.equals(uri))) {
        mSelectionVerified = false;
        mSelectionRequired = required;
        mSelectionPersistenceRequested = persistent;
        mSelectedContactUri = uri;
        parseSelectedContactUri();
        if (!willReloadData) {
            // Configure the adapter to show the selection based on the
            // lookup key extracted from the URI
            ContactListAdapter adapter = getAdapter();
            if (adapter != null) {
                adapter.setSelectedContact(mSelectedContactDirectoryId, mSelectedContactLookupKey, mSelectedContactId);
                getListView().invalidateViews();
            }
        }
        // Also, launch a loader to pick up a new lookup URI in case it has changed
        refreshSelectedContactUri();
    }
}
Also used : ContactListAdapter(com.android.contacts.common.list.ContactListAdapter)

Example 4 with ContactListAdapter

use of com.android.contacts.common.list.ContactListAdapter in project packages_apps_Contacts by AOKP.

the class ContactBrowseListFragment method checkSelection.

private void checkSelection() {
    if (mSelectionVerified) {
        return;
    }
    if (mRefreshingContactUri) {
        return;
    }
    if (isLoadingDirectoryList()) {
        return;
    }
    ContactListAdapter adapter = getAdapter();
    if (adapter == null) {
        return;
    }
    boolean directoryLoading = true;
    int count = adapter.getPartitionCount();
    for (int i = 0; i < count; i++) {
        Partition partition = adapter.getPartition(i);
        if (partition instanceof DirectoryPartition) {
            DirectoryPartition directory = (DirectoryPartition) partition;
            if (directory.getDirectoryId() == mSelectedContactDirectoryId) {
                directoryLoading = directory.isLoading();
                break;
            }
        }
    }
    if (directoryLoading) {
        return;
    }
    adapter.setSelectedContact(mSelectedContactDirectoryId, mSelectedContactLookupKey, mSelectedContactId);
    final int selectedPosition = adapter.getSelectedContactPosition();
    if (selectedPosition != -1) {
        mLastSelectedPosition = selectedPosition;
    } else {
        if (isSearchMode()) {
            if (mDelaySelection) {
                selectFirstFoundContactAfterDelay();
                if (mListener != null) {
                    mListener.onSelectionChange();
                }
                return;
            }
        } else if (mSelectionRequired) {
            // A specific contact was requested, but it's not in the loaded list.
            // Try reconfiguring and reloading the list that will hopefully contain
            // the requested contact. Only take one attempt to avoid an infinite loop
            // in case the contact cannot be found at all.
            mSelectionRequired = false;
            // FILTER_TYPE cases.
            if (mFilter != null && (mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT || mFilter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS)) {
                reloadData();
            } else {
                // Otherwise, call the listener, which will adjust the filter.
                notifyInvalidSelection();
            }
            return;
        } else if (mFilter != null && mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) {
            // If we were trying to load a specific contact, but that contact no longer
            // exists, call the listener, which will adjust the filter.
            notifyInvalidSelection();
            return;
        }
        saveSelectedUri(null);
        selectDefaultContact();
    }
    mSelectionRequired = false;
    mSelectionVerified = true;
    if (mSelectionPersistenceRequested) {
        saveSelectedUri(mSelectedContactUri);
        mSelectionPersistenceRequested = false;
    }
    if (mSelectionToScreenRequested) {
        requestSelectionToScreen(selectedPosition);
    }
    getListView().invalidateViews();
    if (mListener != null) {
        mListener.onSelectionChange();
    }
}
Also used : Partition(com.android.common.widget.CompositeCursorAdapter.Partition) DirectoryPartition(com.android.contacts.common.list.DirectoryPartition) ContactListAdapter(com.android.contacts.common.list.ContactListAdapter) DirectoryPartition(com.android.contacts.common.list.DirectoryPartition)

Example 5 with ContactListAdapter

use of com.android.contacts.common.list.ContactListAdapter in project packages_apps_Contacts by AOKP.

the class DefaultContactBrowseListFragment method setProfileHeader.

@Override
protected void setProfileHeader() {
    mUserProfileExists = getAdapter().hasProfile();
    showEmptyUserProfile(!mUserProfileExists && !isSearchMode());
    if (isSearchMode()) {
        ContactListAdapter adapter = getAdapter();
        if (adapter == null) {
            return;
        }
        // In search mode we only display the header if there is nothing found
        if (TextUtils.isEmpty(getQueryString()) || !adapter.areAllPartitionsEmpty()) {
            mSearchHeaderView.setVisibility(View.GONE);
            showSearchProgress(false);
        } else {
            mSearchHeaderView.setVisibility(View.VISIBLE);
            if (adapter.isLoading()) {
                mSearchProgressText.setText(R.string.search_results_searching);
                showSearchProgress(true);
            } else {
                mSearchProgressText.setText(R.string.listFoundAllContactsZero);
                mSearchProgressText.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
                showSearchProgress(false);
            }
        }
        showEmptyUserProfile(false);
    }
}
Also used : DefaultContactListAdapter(com.android.contacts.common.list.DefaultContactListAdapter) ContactListAdapter(com.android.contacts.common.list.ContactListAdapter)

Aggregations

ContactListAdapter (com.android.contacts.common.list.ContactListAdapter)5 Uri (android.net.Uri)1 Partition (com.android.common.widget.CompositeCursorAdapter.Partition)1 DefaultContactListAdapter (com.android.contacts.common.list.DefaultContactListAdapter)1 DirectoryPartition (com.android.contacts.common.list.DirectoryPartition)1