diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/shortcuts/IconFactory.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/shortcuts/IconFactory.java')
-rw-r--r-- | java/com/android/dialer/shortcuts/IconFactory.java | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/java/com/android/dialer/shortcuts/IconFactory.java b/java/com/android/dialer/shortcuts/IconFactory.java index a8c4ada4e..7aad1129a 100644 --- a/java/com/android/dialer/shortcuts/IconFactory.java +++ b/java/com/android/dialer/shortcuts/IconFactory.java @@ -20,16 +20,21 @@ import android.content.Context; import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.provider.ContactsContract; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; import android.support.annotation.WorkerThread; import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; -import com.android.contacts.common.lettertiles.LetterTileDrawable; import com.android.dialer.common.Assert; +import com.android.dialer.lettertile.LetterTileDrawable; import com.android.dialer.util.DrawableConverter; import java.io.InputStream; @@ -83,6 +88,38 @@ class IconFactory { ContactsContract.Contacts.openContactPhotoInputStream( context.getContentResolver(), lookupUri, false /* preferHighres */); + return VERSION.SDK_INT >= VERSION_CODES.O + ? createAdaptiveIcon(displayName, lookupKey, inputStream) + : createFlatIcon(displayName, lookupKey, inputStream); + } + + @RequiresApi(VERSION_CODES.O) + private Icon createAdaptiveIcon( + @NonNull String displayName, @NonNull String lookupKey, @Nullable InputStream inputStream) { + if (inputStream == null) { + LetterTileDrawable letterTileDrawable = new LetterTileDrawable(context.getResources()); + // The adaptive icons clip the drawable to a safe area inside the drawable. Scale the letter + // so it fits inside the safe area. + letterTileDrawable.setScale(1f / (1f + AdaptiveIconDrawable.getExtraInsetFraction())); + letterTileDrawable.setCanonicalDialerLetterTileDetails( + displayName, + lookupKey, + LetterTileDrawable.SHAPE_RECTANGLE, + LetterTileDrawable.TYPE_DEFAULT); + + int iconSize = + context + .getResources() + .getDimensionPixelSize(R.dimen.launcher_shortcut_adaptive_icon_size); + return Icon.createWithAdaptiveBitmap( + DrawableConverter.drawableToBitmap(letterTileDrawable, iconSize, iconSize)); + } + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); + return Icon.createWithAdaptiveBitmap(bitmap); + } + + private Icon createFlatIcon( + @NonNull String displayName, @NonNull String lookupKey, @Nullable InputStream inputStream) { Drawable drawable; if (inputStream == null) { // No photo for contact; use a letter tile. |