From a5a08d8890b08ac1fde8ccaf333fe33c69333ae5 Mon Sep 17 00:00:00 2001 From: yueg Date: Tue, 31 Oct 2017 14:11:53 -0700 Subject: Add avatar and small icon in bubble primary button. Bug: 67605985 Test: NewBubbleIntegrationTest, NewReturnToCallControllerTest PiperOrigin-RevId: 174089572 Change-Id: Icaeb41482cffe522e09ee1ec068b5d47f476b146 --- .../incallui/NewReturnToCallController.java | 99 +++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) (limited to 'java/com/android/incallui/NewReturnToCallController.java') diff --git a/java/com/android/incallui/NewReturnToCallController.java b/java/com/android/incallui/NewReturnToCallController.java index cd69ea1be..fa7a45de0 100644 --- a/java/com/android/incallui/NewReturnToCallController.java +++ b/java/com/android/incallui/NewReturnToCallController.java @@ -19,15 +19,21 @@ package com.android.incallui; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; import android.telecom.CallAudioState; +import android.text.TextUtils; +import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.common.LogUtil; import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.lettertile.LetterTileDrawable; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.telecom.TelecomUtil; +import com.android.incallui.ContactInfoCache.ContactCacheEntry; +import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; import com.android.incallui.InCallPresenter.InCallUiListener; import com.android.incallui.audiomode.AudioModeProvider; import com.android.incallui.audiomode.AudioModeProvider.AudioModeListener; @@ -41,6 +47,7 @@ import com.android.newbubble.NewBubble.BubbleExpansionStateListener; import com.android.newbubble.NewBubble.ExpansionState; import com.android.newbubble.NewBubbleInfo; import com.android.newbubble.NewBubbleInfo.Action; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -65,12 +72,15 @@ public class NewReturnToCallController implements InCallUiListener, Listener, Au private final PendingIntent endCall; private final PendingIntent fullScreen; + private final ContactInfoCache contactInfoCache; + public static boolean isEnabled(Context context) { return ConfigProviderBindings.get(context).getBoolean("enable_return_to_call_bubble_v2", false); } - public NewReturnToCallController(Context context) { + public NewReturnToCallController(Context context, ContactInfoCache contactInfoCache) { this.context = context; + this.contactInfoCache = contactInfoCache; toggleSpeaker = createActionIntent(ReturnToCallActionReceiver.ACTION_TOGGLE_SPEAKER); showSpeakerSelect = @@ -130,6 +140,7 @@ public class NewReturnToCallController implements InCallUiListener, Listener, Au } else { bubble.show(); } + startContactInfoSearch(); } @VisibleForTesting @@ -213,6 +224,8 @@ public class NewReturnToCallController implements InCallUiListener, Listener, Au // parent call is still there. if (!CallList.getInstance().hasNonParentActiveOrBackgroundCall()) { hideAndReset(); + } else { + startContactInfoSearch(); } } @@ -233,6 +246,22 @@ public class NewReturnToCallController implements InCallUiListener, Listener, Au } } + private void startContactInfoSearch() { + DialerCall dialerCall = CallList.getInstance().getActiveOrBackgroundCall(); + if (dialerCall != null) { + contactInfoCache.findInfo( + dialerCall, false /* isIncoming */, new ReturnToCallContactInfoCacheCallback(this)); + } + } + + private void onPhotoAvatarReceived(@NonNull Drawable photo) { + bubble.updatePhotoAvatar(photo); + } + + private void onLetterTileAvatarReceived(@NonNull Drawable photo) { + bubble.updateAvatar(photo); + } + private NewBubbleInfo generateBubbleInfo() { return NewBubbleInfo.builder() .setPrimaryColor(context.getResources().getColor(R.color.dialer_theme_color, null)) @@ -280,4 +309,72 @@ public class NewReturnToCallController implements InCallUiListener, Listener, Au toggleSpeaker.setAction(action); return PendingIntent.getBroadcast(context, 0, toggleSpeaker, 0); } + + @NonNull + private LetterTileDrawable createLettleTileDrawable( + DialerCall dialerCall, ContactCacheEntry entry) { + String preferredName = + ContactDisplayUtils.getPreferredDisplayName( + entry.namePrimary, + entry.nameAlternative, + ContactsPreferencesFactory.newContactsPreferences(context)); + if (TextUtils.isEmpty(preferredName)) { + preferredName = entry.number; + } + + LetterTileDrawable letterTile = new LetterTileDrawable(context.getResources()); + letterTile.setCanonicalDialerLetterTileDetails( + dialerCall.updateNameIfRestricted(preferredName), + entry.lookupKey, + LetterTileDrawable.SHAPE_CIRCLE, + LetterTileDrawable.getContactTypeFromPrimitives( + dialerCall.isVoiceMailNumber(), + dialerCall.isSpam(), + entry.isBusiness, + dialerCall.getNumberPresentation(), + dialerCall.isConferenceCall())); + return letterTile; + } + + private static class ReturnToCallContactInfoCacheCallback implements ContactInfoCacheCallback { + + private final WeakReference newReturnToCallControllerWeakReference; + + private ReturnToCallContactInfoCacheCallback( + NewReturnToCallController newReturnToCallController) { + newReturnToCallControllerWeakReference = new WeakReference<>(newReturnToCallController); + } + + @Override + public void onContactInfoComplete(String callId, ContactCacheEntry entry) { + NewReturnToCallController newReturnToCallController = + newReturnToCallControllerWeakReference.get(); + if (newReturnToCallController == null) { + return; + } + if (entry.photo != null) { + newReturnToCallController.onPhotoAvatarReceived(entry.photo); + } else { + DialerCall dialerCall = CallList.getInstance().getCallById(callId); + newReturnToCallController.onLetterTileAvatarReceived( + newReturnToCallController.createLettleTileDrawable(dialerCall, entry)); + } + } + + @Override + public void onImageLoadComplete(String callId, ContactCacheEntry entry) { + NewReturnToCallController newReturnToCallController = + newReturnToCallControllerWeakReference.get(); + if (newReturnToCallController == null) { + return; + } + if (entry.photo != null) { + newReturnToCallController.onPhotoAvatarReceived(entry.photo); + } else { + DialerCall dialerCall = CallList.getInstance().getCallById(callId); + newReturnToCallController.onLetterTileAvatarReceived( + newReturnToCallController.createLettleTileDrawable(dialerCall, entry)); + } + } + } } -- cgit v1.2.3