Search in sources :

Example 1 with Duo

use of com.android.dialer.duo.Duo 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 2 with Duo

use of com.android.dialer.duo.Duo in project android_packages_apps_Dialer by MoKee.

the class CallLogListItemViewHolder method bindActionButtons.

/**
 * Binds text titles, click handlers and intents to the voicemail, details and callback action
 * buttons.
 */
private void bindActionButtons() {
    boolean canPlaceCallToNumber = PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation);
    // Hide the call buttons by default. We then set it to be visible when appropriate below.
    // This saves us having to remember to set it to GONE in multiple places.
    callButtonView.setVisibility(View.GONE);
    videoCallButtonView.setVisibility(View.GONE);
    setUpVideoButtonView.setVisibility(View.GONE);
    inviteVideoButtonView.setVisibility(View.GONE);
    if (isFullyUndialableVoicemail()) {
        // Sometimes the voicemail server will report the message is from some non phone number
        // source. If the number does not contains any dialable digit treat it as it is from a unknown
        // number, remove all action buttons but still show the voicemail playback layout.
        detailsButtonView.setVisibility(View.GONE);
        createNewContactButtonView.setVisibility(View.GONE);
        addToExistingContactButtonView.setVisibility(View.GONE);
        sendMessageView.setVisibility(View.GONE);
        callWithNoteButtonView.setVisibility(View.GONE);
        callComposeButtonView.setVisibility(View.GONE);
        blockReportView.setVisibility(View.GONE);
        blockView.setVisibility(View.GONE);
        unblockView.setVisibility(View.GONE);
        userMarkButtonView.setVisibility(View.GONE);
        reportNotSpamView.setVisibility(View.GONE);
        voicemailPlaybackView.setVisibility(View.VISIBLE);
        Uri uri = Uri.parse(voicemailUri);
        voicemailPlaybackPresenter.setPlaybackView(voicemailPlaybackView, rowId, uri, voicemailPrimaryActionButtonClicked, sendVoicemailButtonView);
        voicemailPrimaryActionButtonClicked = false;
        CallLogAsyncTaskUtil.markVoicemailAsRead(context, uri);
        return;
    }
    TextView callTypeOrLocationView = ((TextView) callButtonView.findViewById(R.id.call_type_or_location_text));
    if (canPlaceCallToNumber) {
        if (canSupportAssistedDialing()) {
            callButtonView.setTag(IntentProvider.getAssistedDialIntentProvider(number, context, context.getSystemService(TelephonyManager.class)));
        } else {
            callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number));
        }
        callTypeOrLocationView.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) {
        ((TextView) callButtonView.findViewById(R.id.call_action_text)).setText(TextUtils.expandTemplate(context.getString(R.string.call_log_action_call), nameOrNumber == null ? "" : nameOrNumber));
        if (callType == Calls.VOICEMAIL_TYPE && !TextUtils.isEmpty(callTypeOrLocation)) {
            callTypeOrLocationView.setText(callTypeOrLocation);
            callTypeOrLocationView.setVisibility(View.VISIBLE);
        }
        callButtonView.setVisibility(View.VISIBLE);
    }
    boolean isVoicemailNumber = callLogCache.isVoicemailNumber(accountHandle, number);
    switch(callbackAction) {
        case CallbackAction.IMS_VIDEO:
        case CallbackAction.DUO:
            // For an IMS video call or a Duo call, the secondary action should always be a
            // voice callback.
            callButtonView.setVisibility(View.VISIBLE);
            videoCallButtonView.setVisibility(View.GONE);
            break;
        case CallbackAction.VOICE:
            Duo duo = DuoComponent.get(context).getDuo();
            // available. Otherwise try to set it as a Duo call.
            if (CallUtil.isVideoEnabled(context) && (hasPlacedCarrierVideoCall() || canSupportCarrierVideoCall())) {
                videoCallButtonView.setTag(IntentProvider.getReturnVideoCallIntentProvider(number));
                videoCallButtonView.setVisibility(View.VISIBLE);
                break;
            }
            if (isVoicemailNumber) {
                break;
            }
            boolean identifiedSpamCall = isSpamFeatureEnabled && isSpam;
            if (duo.isReachable(context, number)) {
                videoCallButtonView.setTag(IntentProvider.getDuoVideoIntentProvider(number));
                videoCallButtonView.setVisibility(View.VISIBLE);
            } else if (duo.isActivated(context) && !identifiedSpamCall) {
                if (ConfigProviderBindings.get(context).getBoolean("enable_call_log_duo_invite_button", false)) {
                    inviteVideoButtonView.setTag(IntentProvider.getDuoInviteIntentProvider(number));
                    inviteVideoButtonView.setVisibility(View.VISIBLE);
                    Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_INVITE_SHOWN);
                }
            } else if (duo.isEnabled(context) && !identifiedSpamCall) {
                if (!duo.isInstalled(context)) {
                    if (ConfigProviderBindings.get(context).getBoolean("enable_call_log_install_duo_button", false)) {
                        setUpVideoButtonView.setTag(IntentProvider.getInstallDuoIntentProvider());
                        setUpVideoButtonView.setVisibility(View.VISIBLE);
                        Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_INSTALL_SHOWN);
                    }
                } else {
                    if (ConfigProviderBindings.get(context).getBoolean("enable_call_log_activate_duo_button", false)) {
                        setUpVideoButtonView.setTag(IntentProvider.getSetUpDuoIntentProvider());
                        setUpVideoButtonView.setVisibility(View.VISIBLE);
                        Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_ACTIVATE_SHOWN);
                    }
                }
            }
            break;
        default:
            callButtonView.setVisibility(View.GONE);
            videoCallButtonView.setVisibility(View.GONE);
    }
    // For voicemail calls, show the voicemail playback layout; hide otherwise.
    if (callType == Calls.VOICEMAIL_TYPE && voicemailPlaybackPresenter != null && !TextUtils.isEmpty(voicemailUri)) {
        voicemailPlaybackView.setVisibility(View.VISIBLE);
        Uri uri = Uri.parse(voicemailUri);
        voicemailPlaybackPresenter.setPlaybackView(voicemailPlaybackView, rowId, uri, voicemailPrimaryActionButtonClicked, sendVoicemailButtonView);
        voicemailPrimaryActionButtonClicked = false;
        CallLogAsyncTaskUtil.markVoicemailAsRead(context, uri);
    } else {
        voicemailPlaybackView.setVisibility(View.GONE);
        sendVoicemailButtonView.setVisibility(View.GONE);
    }
    if (callType == Calls.VOICEMAIL_TYPE) {
        detailsButtonView.setVisibility(View.GONE);
    } else {
        detailsButtonView.setVisibility(View.VISIBLE);
        boolean canReportCallerId = cachedNumberLookupService != null && cachedNumberLookupService.canReportAsInvalid(info.sourceType, info.objectId);
        detailsButtonView.setTag(IntentProvider.getCallDetailIntentProvider(callDetailsEntries, buildContact(), canReportCallerId, canSupportAssistedDialing()));
    }
    boolean isBlockedOrSpam = blockId != null || (isSpamFeatureEnabled && isSpam);
    if (!isBlockedOrSpam && info != null && UriUtils.isEncodedContactUri(info.lookupUri)) {
        createNewContactButtonView.setTag(IntentProvider.getAddContactIntentProvider(info.lookupUri, info.name, info.number, info.type, true));
        createNewContactButtonView.setVisibility(View.VISIBLE);
        addToExistingContactButtonView.setTag(IntentProvider.getAddContactIntentProvider(info.lookupUri, info.name, info.number, info.type, false));
        addToExistingContactButtonView.setVisibility(View.VISIBLE);
        userMarkButtonView.setVisibility(View.VISIBLE);
    } else {
        createNewContactButtonView.setVisibility(View.GONE);
        addToExistingContactButtonView.setVisibility(View.GONE);
        userMarkButtonView.setVisibility(View.GONE);
    }
    if (canPlaceCallToNumber && !isBlockedOrSpam && !isVoicemailNumber) {
        sendMessageView.setTag(IntentProvider.getSendSmsIntentProvider(number));
        sendMessageView.setVisibility(View.VISIBLE);
    } else {
        sendMessageView.setVisibility(View.GONE);
    }
    callLogListItemHelper.setActionContentDescriptions(this);
    boolean supportsCallSubject = callLogCache.doesAccountSupportCallSubject(accountHandle);
    callWithNoteButtonView.setVisibility(supportsCallSubject && !isVoicemailNumber && info != null ? View.VISIBLE : View.GONE);
    callComposeButtonView.setVisibility(isCallComposerCapable ? View.VISIBLE : View.GONE);
    updateBlockReportActions(isVoicemailNumber);
}
Also used : TextView(android.widget.TextView) Uri(android.net.Uri) Duo(com.android.dialer.duo.Duo)

Example 3 with Duo

use of com.android.dialer.duo.Duo in project android_packages_apps_Dialer by LineageOS.

the class CallLogListItemViewHolder method bindActionButtons.

/**
 * Binds text titles, click handlers and intents to the voicemail, details and callback action
 * buttons.
 */
private void bindActionButtons() {
    boolean canPlaceCallToNumber = PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation);
    // Hide the call buttons by default. We then set it to be visible when appropriate below.
    // This saves us having to remember to set it to GONE in multiple places.
    callButtonView.setVisibility(View.GONE);
    videoCallButtonView.setVisibility(View.GONE);
    setUpVideoButtonView.setVisibility(View.GONE);
    inviteVideoButtonView.setVisibility(View.GONE);
    // For an emergency number, show "Call details" only.
    if (PhoneNumberHelper.isLocalEmergencyNumber(context, number)) {
        createNewContactButtonView.setVisibility(View.GONE);
        addToExistingContactButtonView.setVisibility(View.GONE);
        sendMessageView.setVisibility(View.GONE);
        callWithNoteButtonView.setVisibility(View.GONE);
        callComposeButtonView.setVisibility(View.GONE);
        blockReportView.setVisibility(View.GONE);
        blockView.setVisibility(View.GONE);
        unblockView.setVisibility(View.GONE);
        reportNotSpamView.setVisibility(View.GONE);
        voicemailPlaybackView.setVisibility(View.GONE);
        detailsButtonView.setVisibility(View.VISIBLE);
        detailsButtonView.setTag(IntentProvider.getCallDetailIntentProvider(callDetailsEntries, buildContact(), /* canReportCallerId = */
        false, /* canSupportAssistedDialing = */
        false));
        return;
    }
    if (isFullyUndialableVoicemail()) {
        // Sometimes the voicemail server will report the message is from some non phone number
        // source. If the number does not contains any dialable digit treat it as it is from a unknown
        // number, remove all action buttons but still show the voicemail playback layout.
        detailsButtonView.setVisibility(View.GONE);
        createNewContactButtonView.setVisibility(View.GONE);
        addToExistingContactButtonView.setVisibility(View.GONE);
        sendMessageView.setVisibility(View.GONE);
        callWithNoteButtonView.setVisibility(View.GONE);
        callComposeButtonView.setVisibility(View.GONE);
        blockReportView.setVisibility(View.GONE);
        blockView.setVisibility(View.GONE);
        unblockView.setVisibility(View.GONE);
        reportNotSpamView.setVisibility(View.GONE);
        voicemailPlaybackView.setVisibility(View.VISIBLE);
        Uri uri = Uri.parse(voicemailUri);
        voicemailPlaybackPresenter.setPlaybackView(voicemailPlaybackView, rowId, uri, voicemailPrimaryActionButtonClicked, sendVoicemailButtonView);
        voicemailPrimaryActionButtonClicked = false;
        CallLogAsyncTaskUtil.markVoicemailAsRead(context, uri);
        return;
    }
    TextView callTypeOrLocationView = ((TextView) callButtonView.findViewById(R.id.call_type_or_location_text));
    if (canPlaceCallToNumber) {
        if (canSupportAssistedDialing()) {
            callButtonView.setTag(IntentProvider.getAssistedDialIntentProvider(number, context, context.getSystemService(TelephonyManager.class)));
        } else {
            callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number));
        }
        callTypeOrLocationView.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) {
        ((TextView) callButtonView.findViewById(R.id.call_action_text)).setText(TextUtils.expandTemplate(context.getString(R.string.call_log_action_call), nameOrNumber == null ? "" : nameOrNumber));
        if (callType == Calls.VOICEMAIL_TYPE && !TextUtils.isEmpty(callTypeOrLocation)) {
            callTypeOrLocationView.setText(callTypeOrLocation);
            callTypeOrLocationView.setVisibility(View.VISIBLE);
        }
        callButtonView.setVisibility(View.VISIBLE);
    }
    boolean isVoicemailNumber = callLogCache.isVoicemailNumber(accountHandle, number);
    switch(callbackAction) {
        case CallbackAction.IMS_VIDEO:
        case CallbackAction.DUO:
            // For an IMS video call or a Duo call, the secondary action should always be a
            // voice callback.
            callButtonView.setVisibility(View.VISIBLE);
            videoCallButtonView.setVisibility(View.GONE);
            break;
        case CallbackAction.VOICE:
            Duo duo = DuoComponent.get(context).getDuo();
            // available. Otherwise try to set it as a Duo call.
            if (CallUtil.isVideoEnabled(context) && (hasPlacedCarrierVideoCall() || canSupportCarrierVideoCall())) {
                videoCallButtonView.setTag(IntentProvider.getReturnVideoCallIntentProvider(number));
                videoCallButtonView.setVisibility(View.VISIBLE);
                break;
            }
            if (isVoicemailNumber) {
                break;
            }
            boolean identifiedSpamCall = isSpamFeatureEnabled && isSpam;
            if (duo.isReachable(context, number)) {
                videoCallButtonView.setTag(IntentProvider.getDuoVideoIntentProvider(number, isNonContactEntry(info)));
                videoCallButtonView.setVisibility(View.VISIBLE);
                CallIntentBuilder.increaseLightbringerCallButtonAppearInExpandedCallLogItemCount();
            } else if (duo.isActivated(context) && !identifiedSpamCall) {
                if (ConfigProviderComponent.get(context).getConfigProvider().getBoolean("enable_call_log_duo_invite_button", false)) {
                    inviteVideoButtonView.setTag(IntentProvider.getDuoInviteIntentProvider(number));
                    inviteVideoButtonView.setVisibility(View.VISIBLE);
                    Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_INVITE_SHOWN);
                    CallIntentBuilder.increaseLightbringerCallButtonAppearInExpandedCallLogItemCount();
                }
            } else if (duo.isEnabled(context) && !identifiedSpamCall) {
                if (!duo.isInstalled(context)) {
                    if (ConfigProviderComponent.get(context).getConfigProvider().getBoolean("enable_call_log_install_duo_button", false)) {
                        setUpVideoButtonView.setTag(IntentProvider.getInstallDuoIntentProvider());
                        setUpVideoButtonView.setVisibility(View.VISIBLE);
                        Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_INSTALL_SHOWN);
                        CallIntentBuilder.increaseLightbringerCallButtonAppearInExpandedCallLogItemCount();
                    }
                } else {
                    if (ConfigProviderComponent.get(context).getConfigProvider().getBoolean("enable_call_log_activate_duo_button", false)) {
                        setUpVideoButtonView.setTag(IntentProvider.getSetUpDuoIntentProvider());
                        setUpVideoButtonView.setVisibility(View.VISIBLE);
                        Logger.get(context).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_ACTIVATE_SHOWN);
                        CallIntentBuilder.increaseLightbringerCallButtonAppearInExpandedCallLogItemCount();
                    }
                }
            }
            break;
        default:
            callButtonView.setVisibility(View.GONE);
            videoCallButtonView.setVisibility(View.GONE);
    }
    // For voicemail calls, show the voicemail playback layout; hide otherwise.
    if (callType == Calls.VOICEMAIL_TYPE && voicemailPlaybackPresenter != null && !TextUtils.isEmpty(voicemailUri)) {
        voicemailPlaybackView.setVisibility(View.VISIBLE);
        Uri uri = Uri.parse(voicemailUri);
        voicemailPlaybackPresenter.setPlaybackView(voicemailPlaybackView, rowId, uri, voicemailPrimaryActionButtonClicked, sendVoicemailButtonView);
        voicemailPrimaryActionButtonClicked = false;
        CallLogAsyncTaskUtil.markVoicemailAsRead(context, uri);
    } else {
        voicemailPlaybackView.setVisibility(View.GONE);
        sendVoicemailButtonView.setVisibility(View.GONE);
    }
    if (callType == Calls.VOICEMAIL_TYPE) {
        detailsButtonView.setVisibility(View.GONE);
    } else {
        detailsButtonView.setVisibility(View.VISIBLE);
        boolean canReportCallerId = cachedNumberLookupService != null && cachedNumberLookupService.canReportAsInvalid(info.sourceType, info.objectId);
        detailsButtonView.setTag(IntentProvider.getCallDetailIntentProvider(callDetailsEntries, buildContact(), canReportCallerId, canSupportAssistedDialing()));
    }
    boolean isBlockedOrSpam = blockId != null || (isSpamFeatureEnabled && isSpam);
    if (!isBlockedOrSpam && info != null && UriUtils.isEncodedContactUri(info.lookupUri)) {
        createNewContactButtonView.setTag(IntentProvider.getAddContactIntentProvider(info.lookupUri, info.name, info.number, info.type, true));
        createNewContactButtonView.setVisibility(View.VISIBLE);
        addToExistingContactButtonView.setTag(IntentProvider.getAddContactIntentProvider(info.lookupUri, info.name, info.number, info.type, false));
        addToExistingContactButtonView.setVisibility(View.VISIBLE);
    } else {
        createNewContactButtonView.setVisibility(View.GONE);
        addToExistingContactButtonView.setVisibility(View.GONE);
    }
    if (canPlaceCallToNumber && !isBlockedOrSpam && !isVoicemailNumber) {
        sendMessageView.setTag(IntentProvider.getSendSmsIntentProvider(number));
        sendMessageView.setVisibility(View.VISIBLE);
    } else {
        sendMessageView.setVisibility(View.GONE);
    }
    callLogListItemHelper.setActionContentDescriptions(this);
    boolean supportsCallSubject = callLogCache.doesAccountSupportCallSubject(accountHandle);
    callWithNoteButtonView.setVisibility(supportsCallSubject && !isVoicemailNumber && info != null ? View.VISIBLE : View.GONE);
    callComposeButtonView.setVisibility(isCallComposerCapable ? View.VISIBLE : View.GONE);
    updateBlockReportActions(canPlaceCallToNumber, isVoicemailNumber);
}
Also used : TextView(android.widget.TextView) Uri(android.net.Uri) Duo(com.android.dialer.duo.Duo)

Example 4 with Duo

use of com.android.dialer.duo.Duo 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 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.nameDisplayOrder = contactsPreferences.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(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)

Aggregations

Duo (com.android.dialer.duo.Duo)4 Uri (android.net.Uri)2 LongSparseArray (android.util.LongSparseArray)2 TextView (android.widget.TextView)2 ContactEntry (com.android.contacts.common.list.ContactEntry)2