diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-11-03 02:07:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-03 02:07:32 +0000 |
commit | 6eec20f5c5a56177f050b1490e2ba198748c0fd4 (patch) | |
tree | ab82401c5c33c58ecf534fc73962405f8af94122 /java/com/android/incallui | |
parent | 9ebcbef57c9c694f2ab1c357b6b6356d0aa0d143 (diff) | |
parent | a5a08d8890b08ac1fde8ccaf333fe33c69333ae5 (diff) |
Merge "Add avatar and small icon in bubble primary button."
Diffstat (limited to 'java/com/android/incallui')
-rw-r--r-- | java/com/android/incallui/InCallServiceImpl.java | 3 | ||||
-rw-r--r-- | java/com/android/incallui/NewReturnToCallController.java | 99 |
2 files changed, 100 insertions, 2 deletions
diff --git a/java/com/android/incallui/InCallServiceImpl.java b/java/com/android/incallui/InCallServiceImpl.java index 402e0021f..539dba8dd 100644 --- a/java/com/android/incallui/InCallServiceImpl.java +++ b/java/com/android/incallui/InCallServiceImpl.java @@ -99,7 +99,8 @@ public class InCallServiceImpl extends InCallService { returnToCallController = new ReturnToCallController(this); } if (NewReturnToCallController.isEnabled(this)) { - newReturnToCallController = new NewReturnToCallController(this); + newReturnToCallController = + new NewReturnToCallController(this, ContactInfoCache.getInstance(context)); } IBinder iBinder = super.onBind(intent); 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<NewReturnToCallController> 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)); + } + } + } } |