Search in sources :

Example 1 with ContactEntry

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

the class PhoneFavoritesTileAdapter method getReflowedPinningOperations.

/**
 * Given an existing list of contact entries and a single entry that is to be pinned at a
 * particular position, return a list of {@link ContentProviderOperation}s that contains new
 * pinned positions for all contacts that are forced to be pinned at new positions, trying as
 * much as possible to keep pinned contacts at their original location.
 *
 * At this point in time the pinned position of each contact in the list has already been
 * updated by {@link #arrangeContactsByPinnedPosition}, so we can assume that all pinned
 * positions(within {@link #PIN_LIMIT} are unique positive integers.
 */
@VisibleForTesting
/* package */
ArrayList<ContentProviderOperation> getReflowedPinningOperations(ArrayList<ContactEntry> list, int oldPos, int newPinPos) {
    final ArrayList<ContentProviderOperation> positions = Lists.newArrayList();
    final int lowerBound = Math.min(oldPos, newPinPos);
    final int upperBound = Math.max(oldPos, newPinPos);
    for (int i = lowerBound; i <= upperBound; i++) {
        final ContactEntry entry = list.get(i);
        // Pinned positions in the database start from 1 instead of being zero-indexed like
        // arrays, so offset by 1.
        final int databasePinnedPosition = i + 1;
        if (entry.pinned == databasePinnedPosition)
            continue;
        final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(entry.id));
        final ContentValues values = new ContentValues();
        values.put(Contacts.PINNED, databasePinnedPosition);
        positions.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
    }
    return positions;
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ContactEntry(com.android.contacts.common.list.ContactEntry) Uri(android.net.Uri) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ContactEntry

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

the class PhoneFavoritesTileAdapterTest method getTestContactEntry.

private ContactEntry getTestContactEntry(int id, int pinned, String namePrimaryAppend, String nameAlternativeAppend) {
    ContactEntry contactEntry = new ContactEntry();
    contactEntry.id = id;
    contactEntry.pinned = pinned;
    contactEntry.namePrimary = namePrimaryAppend;
    contactEntry.nameAlternative = nameAlternativeAppend;
    return contactEntry;
}
Also used : ContactEntry(com.android.contacts.common.list.ContactEntry)

Example 3 with ContactEntry

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

the class PhoneFavoritesTileAdapter method saveCursorToCache.

/**
 * Saves the cursor data to the cache, to speed up UI changes.
 *
 * @param cursor Returned cursor from {@link ContactTileLoaderFactory} with data to populate the
 *     view.
 */
private void saveCursorToCache(Cursor cursor) {
    contactEntries.clear();
    if (cursor == null) {
        return;
    }
    final LongSparseArray<Object> duplicates = new LongSparseArray<>(cursor.getCount());
    // Track the length of {@link #mContactEntries} and compare to {@link #TILES_SOFT_LIMIT}.
    int counter = 0;
    // Data for logging
    int starredContactsCount = 0;
    int pinnedContactsCount = 0;
    int multipleNumbersContactsCount = 0;
    int contactsWithPhotoCount = 0;
    int contactsWithNameCount = 0;
    int lightbringerReachableContactsCount = 0;
    // The cursor should not be closed since this is invoked from a CursorLoader.
    if (cursor.moveToFirst()) {
        int starredColumn = cursor.getColumnIndexOrThrow(Contacts.STARRED);
        int contactIdColumn = cursor.getColumnIndexOrThrow(Phone.CONTACT_ID);
        int photoUriColumn = cursor.getColumnIndexOrThrow(Contacts.PHOTO_URI);
        int lookupKeyColumn = cursor.getColumnIndexOrThrow(Contacts.LOOKUP_KEY);
        int pinnedColumn = cursor.getColumnIndexOrThrow(Contacts.PINNED);
        int nameColumn = cursor.getColumnIndexOrThrow(Contacts.DISPLAY_NAME_PRIMARY);
        int nameAlternativeColumn = cursor.getColumnIndexOrThrow(Contacts.DISPLAY_NAME_ALTERNATIVE);
        int isDefaultNumberColumn = cursor.getColumnIndexOrThrow(Phone.IS_SUPER_PRIMARY);
        int phoneTypeColumn = cursor.getColumnIndexOrThrow(Phone.TYPE);
        int phoneLabelColumn = cursor.getColumnIndexOrThrow(Phone.LABEL);
        int phoneNumberColumn = cursor.getColumnIndexOrThrow(Phone.NUMBER);
        do {
            final int starred = cursor.getInt(starredColumn);
            final long id;
            // whichever is greater.
            if (starred < 1 && counter >= TILES_SOFT_LIMIT) {
                break;
            } else {
                id = cursor.getLong(contactIdColumn);
            }
            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(photoUriColumn);
            final String lookupKey = cursor.getString(lookupKeyColumn);
            final int pinned = cursor.getInt(pinnedColumn);
            final String name = cursor.getString(nameColumn);
            final String nameAlternative = cursor.getString(nameAlternativeColumn);
            final boolean isStarred = cursor.getInt(starredColumn) > 0;
            final boolean isDefaultNumber = cursor.getInt(isDefaultNumberColumn) > 0;
            final ContactEntry contact = new ContactEntry();
            contact.id = id;
            contact.namePrimary = (!TextUtils.isEmpty(name)) ? name : resources.getString(R.string.missing_name);
            contact.nameAlternative = (!TextUtils.isEmpty(nameAlternative)) ? nameAlternative : resources.getString(R.string.missing_name);
            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(phoneTypeColumn);
            final String phoneNumberCustomLabel = cursor.getString(phoneLabelColumn);
            contact.phoneLabel = (String) Phone.getTypeLabel(resources, phoneNumberType, phoneNumberCustomLabel);
            contact.phoneNumber = cursor.getString(phoneNumberColumn);
            contact.pinned = pinned;
            contactEntries.add(contact);
            // Set counts for logging
            if (isStarred) {
                // mNumStarred might be larger than the number of visible starred contact,
                // since it includes invisible ones (starred contact with no phone number).
                starredContactsCount++;
            }
            if (pinned != PinnedPositions.UNPINNED) {
                pinnedContactsCount++;
            }
            if (!TextUtils.isEmpty(name)) {
                contactsWithNameCount++;
            }
            if (photoUri != null) {
                contactsWithPhotoCount++;
            }
            duplicates.put(id, contact);
            counter++;
        } while (cursor.moveToNext());
    }
    awaitingRemove = false;
    arrangeContactsByPinnedPosition(contactEntries);
    ShortcutRefresher.refresh(context, contactEntries);
    notifyDataSetChanged();
    Duo duo = DuoComponent.get(context).getDuo();
    for (ContactEntry contact : contactEntries) {
        if (contact.phoneNumber == null) {
            multipleNumbersContactsCount++;
        } else if (duo.isReachable(context, contact.phoneNumber)) {
            lightbringerReachableContactsCount++;
        }
    }
    Logger.get(context).logSpeedDialContactComposition(counter, starredContactsCount, pinnedContactsCount, multipleNumbersContactsCount, contactsWithPhotoCount, contactsWithNameCount, lightbringerReachableContactsCount);
    // Logs for manual testing
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "counter: %d", counter);
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "starredContactsCount: %d", starredContactsCount);
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "pinnedContactsCount: %d", pinnedContactsCount);
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "multipleNumbersContactsCount: %d", multipleNumbersContactsCount);
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "contactsWithPhotoCount: %d", contactsWithPhotoCount);
    LogUtil.v("PhoneFavoritesTileAdapter.saveCursorToCache", "contactsWithNameCount: %d", contactsWithNameCount);
}
Also used : LongSparseArray(android.util.LongSparseArray) ContactEntry(com.android.contacts.common.list.ContactEntry) Duo(com.android.dialer.duo.Duo)

Example 4 with ContactEntry

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

the class PhoneFavoritesTileAdapter method getReflowedPinningOperations.

/**
 * Given an existing list of contact entries and a single entry that is to be pinned at a
 * particular position, return a list of {@link ContentProviderOperation}s that contains new
 * pinned positions for all contacts that are forced to be pinned at new positions, trying as much
 * as possible to keep pinned contacts at their original location.
 *
 * <p>At this point in time the pinned position of each contact in the list has already been
 * updated by {@link #arrangeContactsByPinnedPosition}, so we can assume that all pinned
 * positions(within {@link #PIN_LIMIT} are unique positive integers.
 */
@VisibleForTesting
private ArrayList<ContentProviderOperation> getReflowedPinningOperations(ArrayList<ContactEntry> list, int oldPos, int newPinPos) {
    final ArrayList<ContentProviderOperation> positions = new ArrayList<>();
    final int lowerBound = Math.min(oldPos, newPinPos);
    final int upperBound = Math.max(oldPos, newPinPos);
    for (int i = lowerBound; i <= upperBound; i++) {
        final ContactEntry entry = list.get(i);
        // Pinned positions in the database start from 1 instead of being zero-indexed like
        // arrays, so offset by 1.
        final int databasePinnedPosition = i + 1;
        if (entry.pinned == databasePinnedPosition) {
            continue;
        }
        final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(entry.id));
        final ContentValues values = new ContentValues();
        values.put(Contacts.PINNED, databasePinnedPosition);
        positions.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
    }
    return positions;
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ContactEntry(com.android.contacts.common.list.ContactEntry) ArrayList(java.util.ArrayList) Uri(android.net.Uri) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 5 with ContactEntry

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

the class DynamicShortcuts method refresh.

/**
 * Performs a "complete refresh" of dynamic shortcuts. This is done by comparing the provided
 * contact information with the existing dynamic shortcuts in order to compute a delta which
 * contains shortcuts which should be added, updated, or removed.
 *
 * <p>If the delta is non-empty, it is applied by making appropriate calls to the {@link
 * ShortcutManager} system service.
 *
 * <p>This is a slow blocking call which performs file I/O and should not be performed on the main
 * thread.
 */
@WorkerThread
public void refresh(List<ContactEntry> contacts) {
    Assert.isWorkerThread();
    LogUtil.enterBlock("DynamicShortcuts.refresh");
    ShortcutManager shortcutManager = getShortcutManager(context);
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        LogUtil.i("DynamicShortcuts.refresh", "no contact permissions");
        shortcutManager.removeAllDynamicShortcuts();
        return;
    }
    // Fill the available shortcuts with dynamic shortcuts up to a maximum of 3 dynamic shortcuts.
    int numDynamicShortcutsToCreate = Math.min(MAX_DYNAMIC_SHORTCUTS, shortcutManager.getMaxShortcutCountPerActivity() - shortcutManager.getManifestShortcuts().size());
    Map<String, DialerShortcut> newDynamicShortcutsById = new ArrayMap<>(numDynamicShortcutsToCreate);
    int rank = 0;
    for (ContactEntry entry : contacts) {
        if (newDynamicShortcutsById.size() >= numDynamicShortcutsToCreate) {
            break;
        }
        DialerShortcut shortcut = DialerShortcut.builder().setContactId(entry.id).setLookupKey(entry.lookupKey).setDisplayName(entry.getPreferredDisplayName(context)).setRank(rank++).build();
        newDynamicShortcutsById.put(shortcut.getShortcutId(), shortcut);
    }
    List<ShortcutInfo> oldDynamicShortcuts = new ArrayList<>(shortcutManager.getDynamicShortcuts());
    Delta delta = computeDelta(oldDynamicShortcuts, newDynamicShortcutsById);
    applyDelta(delta);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ContactEntry(com.android.contacts.common.list.ContactEntry) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) WorkerThread(android.support.annotation.WorkerThread)

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