Search in sources :

Example 6 with ContactEntry

use of com.android.contacts.common.list.ContactEntry in project android_packages_apps_Dialer by LineageOS.

the class ShortcutRefresher method speedDialUiItemsToContactEntries.

public static List<ContactEntry> speedDialUiItemsToContactEntries(List<SpeedDialUiItem> items) {
    List<ContactEntry> contactEntries = new ArrayList<>();
    for (SpeedDialUiItem item : items) {
        ContactEntry entry = new ContactEntry();
        entry.id = item.contactId();
        entry.lookupKey = item.lookupKey();
        // SpeedDialUiItem name's are already configured for alternative display orders, so we don't
        // need to account for them in these entries.
        entry.namePrimary = item.name();
        contactEntries.add(entry);
    }
    return contactEntries;
}
Also used : ContactEntry(com.android.contacts.common.list.ContactEntry) ArrayList(java.util.ArrayList) SpeedDialUiItem(com.android.dialer.speeddial.loader.SpeedDialUiItem)

Example 7 with ContactEntry

use of com.android.contacts.common.list.ContactEntry in project android_packages_apps_Dialer by MoKee.

the class PhoneFavoritesTileAdapter method saveCursorToCache.

/**
 * Saves the cursor data to the cache, to speed up UI changes.
 *
 * @param cursor Returned cursor with data to populate the view.
 */
private void saveCursorToCache(Cursor cursor) {
    mContactEntries.clear();
    cursor.moveToPosition(-1);
    final LongSparseArray<Object> duplicates = new LongSparseArray<Object>(cursor.getCount());
    // Track the length of {@link #mContactEntries} and compare to {@link #TILES_SOFT_LIMIT}.
    int counter = 0;
    while (cursor.moveToNext()) {
        final int starred = cursor.getInt(mStarredIndex);
        final long id;
        // whichever is greater.
        if (starred < 1 && counter >= TILES_SOFT_LIMIT) {
            break;
        } else {
            id = cursor.getLong(mContactIdIndex);
        }
        final ContactEntry existing = (ContactEntry) duplicates.get(id);
        if (existing != null) {
            // and label fields so that the disambiguation dialog will show up.
            if (!existing.isDefaultNumber) {
                existing.phoneLabel = null;
                existing.phoneNumber = null;
            }
            continue;
        }
        final String photoUri = cursor.getString(mPhotoUriIndex);
        final String lookupKey = cursor.getString(mLookupIndex);
        final int pinned = cursor.getInt(mPinnedIndex);
        final String name = cursor.getString(mNamePrimaryIndex);
        final String nameAlternative = cursor.getString(mNameAlternativeIndex);
        final boolean isStarred = cursor.getInt(mStarredIndex) > 0;
        final boolean isDefaultNumber = cursor.getInt(mIsDefaultNumberIndex) > 0;
        final ContactEntry contact = new ContactEntry();
        contact.id = id;
        contact.namePrimary = (!TextUtils.isEmpty(name)) ? name : mResources.getString(R.string.missing_name);
        contact.nameAlternative = (!TextUtils.isEmpty(nameAlternative)) ? nameAlternative : mResources.getString(R.string.missing_name);
        contact.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
        contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null);
        contact.lookupKey = lookupKey;
        contact.lookupUri = ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), id);
        contact.isFavorite = isStarred;
        contact.isDefaultNumber = isDefaultNumber;
        // Set phone number and label
        final int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex);
        final String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex);
        contact.phoneLabel = (String) Phone.getTypeLabel(mResources, phoneNumberType, phoneNumberCustomLabel);
        contact.phoneNumber = cursor.getString(mPhoneNumberIndex);
        contact.pinned = pinned;
        mContactEntries.add(contact);
        duplicates.put(id, contact);
        counter++;
    }
    mAwaitingRemove = false;
    arrangeContactsByPinnedPosition(mContactEntries);
    notifyDataSetChanged();
}
Also used : LongSparseArray(android.util.LongSparseArray) ContactEntry(com.android.contacts.common.list.ContactEntry)

Example 8 with ContactEntry

use of com.android.contacts.common.list.ContactEntry in project android_packages_apps_Dialer by MoKee.

the class PhoneFavoritesTileAdapter method arrangeContactsByPinnedPosition.

/**
 * Given a list of contacts that each have pinned positions, rearrange the list (destructive)
 * such that all pinned contacts are in their defined pinned positions, and unpinned contacts
 * take the spaces between those pinned contacts. Demoted contacts should not appear in the
 * resulting list.
 *
 * This method also updates the pinned positions of pinned contacts so that they are all
 * unique positive integers within range from 0 to toArrange.size() - 1. This is because
 * when the contact entries are read from the database, it is possible for them to have
 * overlapping pin positions due to sync or modifications by third party apps.
 */
@VisibleForTesting
/* package */
void arrangeContactsByPinnedPosition(ArrayList<ContactEntry> toArrange) {
    final PriorityQueue<ContactEntry> pinnedQueue = new PriorityQueue<ContactEntry>(PIN_LIMIT, mContactEntryComparator);
    final List<ContactEntry> unpinnedContacts = new LinkedList<ContactEntry>();
    final int length = toArrange.size();
    for (int i = 0; i < length; i++) {
        final ContactEntry contact = toArrange.get(i);
        // Decide whether the contact is hidden(demoted), pinned, or unpinned
        if (contact.pinned > PIN_LIMIT || contact.pinned == PinnedPositions.UNPINNED) {
            unpinnedContacts.add(contact);
        } else if (contact.pinned > PinnedPositions.DEMOTED) {
            // Demoted or contacts with negative pinned positions are ignored.
            // Pinned contacts go into a priority queue where they are ranked by pinned
            // position. This is required because the contacts provider does not return
            // contacts ordered by pinned position.
            pinnedQueue.add(contact);
        }
    }
    final int maxToPin = Math.min(PIN_LIMIT, pinnedQueue.size() + unpinnedContacts.size());
    toArrange.clear();
    for (int i = 1; i < maxToPin + 1; i++) {
        if (!pinnedQueue.isEmpty() && pinnedQueue.peek().pinned <= i) {
            final ContactEntry toPin = pinnedQueue.poll();
            toPin.pinned = i;
            toArrange.add(toPin);
        } else if (!unpinnedContacts.isEmpty()) {
            toArrange.add(unpinnedContacts.remove(0));
        }
    }
    // and then cleared frequents. Contacts in this situation should become unpinned.
    while (!pinnedQueue.isEmpty()) {
        final ContactEntry entry = pinnedQueue.poll();
        entry.pinned = PinnedPositions.UNPINNED;
        toArrange.add(entry);
    }
    // Any remaining unpinned contacts that weren't in the gaps between the pinned contacts
    // now just get appended to the end of the list.
    toArrange.addAll(unpinnedContacts);
}
Also used : ContactEntry(com.android.contacts.common.list.ContactEntry) PriorityQueue(java.util.PriorityQueue) LinkedList(java.util.LinkedList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with ContactEntry

use of com.android.contacts.common.list.ContactEntry in project android_packages_apps_Dialer by MoKee.

the class PhoneFavoritesTileAdapterTest method testArrangeContactsByPinnedPosition_All_Pinned_AllConflicts_SortNameAlternative.

public void testArrangeContactsByPinnedPosition_All_Pinned_AllConflicts_SortNameAlternative() {
    Context context = getContext();
    context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE).edit().putInt(ContactsPreferences.SORT_ORDER_KEY, ContactsPreferences.SORT_ORDER_ALTERNATIVE).commit();
    ArrayList<ContactEntry> actual = Lists.newArrayList(getTestContactEntry(1, 3, "2", "1"), getTestContactEntry(2, 3, "0", "2"), getTestContactEntry(0, 3, "1", "0"));
    mAdapter.arrangeContactsByPinnedPosition(actual);
    assertContactEntryListPositionsMatchId(actual, 3);
}
Also used : Context(android.content.Context) ContactEntry(com.android.contacts.common.list.ContactEntry)

Example 10 with ContactEntry

use of com.android.contacts.common.list.ContactEntry in project android_packages_apps_Dialer by LineageOS.

the class PhoneFavoritesTileAdapter method arrangeContactsByPinnedPosition.

/**
 * Given a list of contacts that each have pinned positions, rearrange the list (destructive) such
 * that all pinned contacts are in their defined pinned positions, and unpinned contacts take the
 * spaces between those pinned contacts. Demoted contacts should not appear in the resulting list.
 *
 * <p>This method also updates the pinned positions of pinned contacts so that they are all unique
 * positive integers within range from 0 to toArrange.size() - 1. This is because when the contact
 * entries are read from the database, it is possible for them to have overlapping pin positions
 * due to sync or modifications by third party apps.
 */
@VisibleForTesting
private void arrangeContactsByPinnedPosition(ArrayList<ContactEntry> toArrange) {
    final PriorityQueue<ContactEntry> pinnedQueue = new PriorityQueue<>(PIN_LIMIT, contactEntryComparator);
    final List<ContactEntry> unpinnedContacts = new LinkedList<>();
    final int length = toArrange.size();
    for (int i = 0; i < length; i++) {
        final ContactEntry contact = toArrange.get(i);
        // Decide whether the contact is hidden(demoted), pinned, or unpinned
        if (contact.pinned > PIN_LIMIT || contact.pinned == PinnedPositions.UNPINNED) {
            unpinnedContacts.add(contact);
        } else if (contact.pinned > PinnedPositions.DEMOTED) {
            // Demoted or contacts with negative pinned positions are ignored.
            // Pinned contacts go into a priority queue where they are ranked by pinned
            // position. This is required because the contacts provider does not return
            // contacts ordered by pinned position.
            pinnedQueue.add(contact);
        }
    }
    final int maxToPin = Math.min(PIN_LIMIT, pinnedQueue.size() + unpinnedContacts.size());
    toArrange.clear();
    for (int i = 1; i < maxToPin + 1; i++) {
        if (!pinnedQueue.isEmpty() && pinnedQueue.peek().pinned <= i) {
            final ContactEntry toPin = pinnedQueue.poll();
            toPin.pinned = i;
            toArrange.add(toPin);
        } else if (!unpinnedContacts.isEmpty()) {
            toArrange.add(unpinnedContacts.remove(0));
        }
    }
    // and then cleared frequents. Contacts in this situation should become unpinned.
    while (!pinnedQueue.isEmpty()) {
        final ContactEntry entry = pinnedQueue.poll();
        entry.pinned = PinnedPositions.UNPINNED;
        toArrange.add(entry);
    }
    // Any remaining unpinned contacts that weren't in the gaps between the pinned contacts
    // now just get appended to the end of the list.
    toArrange.addAll(unpinnedContacts);
}
Also used : ContactEntry(com.android.contacts.common.list.ContactEntry) PriorityQueue(java.util.PriorityQueue) LinkedList(java.util.LinkedList) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

ContactEntry (com.android.contacts.common.list.ContactEntry)10 ArrayList (java.util.ArrayList)3 ContentProviderOperation (android.content.ContentProviderOperation)2 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 LongSparseArray (android.util.LongSparseArray)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 Context (android.content.Context)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 ShortcutManager (android.content.pm.ShortcutManager)1 WorkerThread (android.support.annotation.WorkerThread)1 ArrayMap (android.util.ArrayMap)1 Duo (com.android.dialer.duo.Duo)1 SpeedDialUiItem (com.android.dialer.speeddial.loader.SpeedDialUiItem)1