diff options
| author | 2020-07-14 19:18:02 +0000 | |
|---|---|---|
| committer | 2020-07-14 19:18:02 +0000 | |
| commit | 38ddedd779358d8b39d8decd6209356be612da44 (patch) | |
| tree | 20cbbe3b38ad05bad94763b9b5811b6425cb91a7 | |
| parent | ba229b5a9e2768c646b8af3280b5ef0f7a59a948 (diff) | |
| parent | ad34b1110e190fdf35296c4972f84336878f4b1c (diff) | |
Merge "Ensure that bubble badge is always circle" into rvc-qpr-dev am: 441d5a3cd5 am: ad34b1110e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12132201
Change-Id: I72288d0e7735903d5dd31f4966aa61e17bc5d04d
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/bubbles/BubbleIconFactory.java | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleIconFactory.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleIconFactory.java index 57e2362bd511..d017bc0e31c2 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleIconFactory.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleIconFactory.java @@ -24,6 +24,8 @@ import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; @@ -40,15 +42,15 @@ import com.android.systemui.R; */ public class BubbleIconFactory extends BaseIconFactory { + private int mBadgeSize; + protected BubbleIconFactory(Context context) { super(context, context.getResources().getConfiguration().densityDpi, context.getResources().getDimensionPixelSize(R.dimen.individual_bubble_size)); - } - - int getBadgeSize() { - return mContext.getResources().getDimensionPixelSize( + mBadgeSize = mContext.getResources().getDimensionPixelSize( com.android.launcher3.icons.R.dimen.profile_badge_size); } + /** * Returns the drawable that the developer has provided to display in the bubble. */ @@ -78,18 +80,20 @@ public class BubbleIconFactory extends BaseIconFactory { * will include the workprofile indicator on the badge if appropriate. */ BitmapInfo getBadgeBitmap(Drawable userBadgedAppIcon, boolean isImportantConversation) { - Bitmap userBadgedBitmap = createIconBitmap( - userBadgedAppIcon, 1f, getBadgeSize()); - ShadowGenerator shadowGenerator = new ShadowGenerator(getBadgeSize()); - if (!isImportantConversation) { - Canvas c = new Canvas(); - c.setBitmap(userBadgedBitmap); - shadowGenerator.recreateIcon(Bitmap.createBitmap(userBadgedBitmap), c); - return createIconBitmap(userBadgedBitmap); - } else { - float ringStrokeWidth = mContext.getResources().getDimensionPixelSize( + ShadowGenerator shadowGenerator = new ShadowGenerator(mBadgeSize); + Bitmap userBadgedBitmap = createIconBitmap(userBadgedAppIcon, 1f, mBadgeSize); + + if (userBadgedAppIcon instanceof AdaptiveIconDrawable) { + userBadgedBitmap = Bitmap.createScaledBitmap( + getCircleBitmap((AdaptiveIconDrawable) userBadgedAppIcon, /* size */ + userBadgedAppIcon.getIntrinsicWidth()), + mBadgeSize, mBadgeSize, /* filter */ true); + } + + if (isImportantConversation) { + final float ringStrokeWidth = mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.importance_ring_stroke_width); - int importantConversationColor = mContext.getResources().getColor( + final int importantConversationColor = mContext.getResources().getColor( com.android.settingslib.R.color.important_conversation, null); Bitmap badgeAndRing = Bitmap.createBitmap(userBadgedBitmap.getWidth(), userBadgedBitmap.getHeight(), userBadgedBitmap.getConfig()); @@ -114,9 +118,45 @@ public class BubbleIconFactory extends BaseIconFactory { shadowGenerator.recreateIcon(Bitmap.createBitmap(badgeAndRing), c); return createIconBitmap(badgeAndRing); + } else { + Canvas c = new Canvas(); + c.setBitmap(userBadgedBitmap); + shadowGenerator.recreateIcon(Bitmap.createBitmap(userBadgedBitmap), c); + return createIconBitmap(userBadgedBitmap); } } + public Bitmap getCircleBitmap(AdaptiveIconDrawable icon, int size) { + Drawable foreground = icon.getForeground(); + Drawable background = icon.getBackground(); + Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(); + canvas.setBitmap(bitmap); + + // Clip canvas to circle. + Path circlePath = new Path(); + circlePath.addCircle(/* x */ size / 2f, + /* y */ size / 2f, + /* radius */ size / 2f, + Path.Direction.CW); + canvas.clipPath(circlePath); + + // Draw background. + background.setBounds(0, 0, size, size); + background.draw(canvas); + + // Draw foreground. The foreground and background drawables are derived from adaptive icons + // Some icon shapes fill more space than others, so adaptive icons are normalized to about + // the same size. This size is smaller than the original bounds, so we estimate + // the difference in this offset. + int offset = size / 5; + foreground.setBounds(-offset, -offset, size + offset, size + offset); + foreground.draw(canvas); + + canvas.setBitmap(null); + return bitmap; + } + /** * Returns a {@link BitmapInfo} for the entire bubble icon including the badge. */ |