From 1f6d6d5d337d32e9471817a9f791a2062499f02c Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Mon, 3 May 2021 12:45:21 -0700 Subject: [PATCH] Add the priority person highlight back to bubbles badge In BubbleViewInfo task where the icons are fetched, we were creating the ringed badge for priority people but we weren't using it. Instead the original badge drawable was being used. This switched the app badge to be a bitmap & uses the bitmap with the priority person ring. Also fixes an issue where the ring would draw through a badge that also had the work profile indicator. This is done by drawing the highlight first and then drawing the badge on top. Test: manual 1) have a conversation notif that can bubble 2) mark it as priority => Observe that the bubble is created and it has the ringed bitmap 3) dismiss the bubble => check that the ring is present on the bubble in the bubble overflow 4) repeat above steps with a bubble from workprofile, ensure it has the ring and the workprofile badge Bug: 185202938 Change-Id: Ief297f073f9684930b3a08fd93e90bbaae3180ca --- .../wm/shell/bubbles/BadgedImageView.java | 17 +++++++++-------- .../com/android/wm/shell/bubbles/Bubble.java | 11 ++++++----- .../wm/shell/bubbles/BubbleIconFactory.java | 14 ++++++-------- .../android/wm/shell/bubbles/BubbleOverflow.kt | 3 +-- .../wm/shell/bubbles/BubbleStackView.java | 2 +- .../wm/shell/bubbles/BubbleViewInfoTask.java | 4 ++-- .../wm/shell/bubbles/BubbleViewProvider.java | 3 +-- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BadgedImageView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BadgedImageView.java index 1971ca97d4262..55dfc12966a98 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BadgedImageView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BadgedImageView.java @@ -15,6 +15,7 @@ */ package com.android.wm.shell.bubbles; +import static android.graphics.Paint.ANTI_ALIAS_FLAG; import static android.graphics.Paint.DITHER_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; @@ -22,10 +23,10 @@ import android.annotation.Nullable; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Path; import android.graphics.Rect; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.PathParser; import android.widget.ImageView; @@ -75,13 +76,13 @@ public class BadgedImageView extends ImageView { private BubbleViewProvider mBubble; private BubblePositioner mPositioner; + private boolean mOnLeft; private DotRenderer mDotRenderer; private DotRenderer.DrawParams mDrawParams; - private boolean mOnLeft; - private int mDotColor; + private Paint mPaint = new Paint(ANTI_ALIAS_FLAG); private Rect mTempBounds = new Rect(); public BadgedImageView(Context context) { @@ -305,7 +306,7 @@ public class BadgedImageView extends ImageView { } void showBadge() { - Drawable badge = mBubble.getAppBadge(); + Bitmap badge = mBubble.getAppBadge(); if (badge == null) { setImageBitmap(mBubble.getBubbleIcon()); return; @@ -318,13 +319,13 @@ public class BadgedImageView extends ImageView { bubbleCanvas.setBitmap(bubble); final int bubbleSize = bubble.getWidth(); final int badgeSize = (int) (ICON_BADGE_SCALE * bubbleSize); + Rect dest = new Rect(); if (mOnLeft) { - badge.setBounds(0, bubbleSize - badgeSize, badgeSize, bubbleSize); + dest.set(0, bubbleSize - badgeSize, badgeSize, bubbleSize); } else { - badge.setBounds(bubbleSize - badgeSize, bubbleSize - badgeSize, - bubbleSize, bubbleSize); + dest.set(bubbleSize - badgeSize, bubbleSize - badgeSize, bubbleSize, bubbleSize); } - badge.draw(bubbleCanvas); + bubbleCanvas.drawBitmap(badge, null /* src */, dest, mPaint); bubbleCanvas.setBitmap(null); setImageBitmap(bubble); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java index f6e92ef0e8eae..afb40d1ff95cb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java @@ -104,9 +104,10 @@ public class Bubble implements BubbleViewProvider { } private FlyoutMessage mFlyoutMessage; - private Drawable mBadgeDrawable; - // Bitmap with no badge, no dot + // The developer provided image for the bubble private Bitmap mBubbleBitmap; + // The app badge for the bubble + private Bitmap mBadgeBitmap; private int mDotColor; private Path mDotPath; private int mFlags; @@ -242,8 +243,8 @@ public class Bubble implements BubbleViewProvider { } @Override - public Drawable getAppBadge() { - return mBadgeDrawable; + public Bitmap getAppBadge() { + return mBadgeBitmap; } @Override @@ -398,7 +399,7 @@ public class Bubble implements BubbleViewProvider { mAppName = info.appName; mFlyoutMessage = info.flyoutMessage; - mBadgeDrawable = info.badgeDrawable; + mBadgeBitmap = info.badgeBitmap; mBubbleBitmap = info.bubbleBitmap; mDotColor = info.dotColor; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleIconFactory.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleIconFactory.java index e64ed6a0836c1..b83feeedbf211 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleIconFactory.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleIconFactory.java @@ -101,6 +101,12 @@ public class BubbleIconFactory extends BaseIconFactory { userBadgedBitmap.getHeight(), userBadgedBitmap.getConfig()); Canvas c = new Canvas(badgeAndRing); + Paint ringPaint = new Paint(); + ringPaint.setStyle(Paint.Style.FILL); + ringPaint.setColor(importantConversationColor); + ringPaint.setAntiAlias(true); + c.drawCircle(c.getWidth() / 2, c.getHeight() / 2, c.getWidth() / 2, ringPaint); + final int bitmapTop = (int) ringStrokeWidth; final int bitmapLeft = (int) ringStrokeWidth; final int bitmapWidth = c.getWidth() - 2 * (int) ringStrokeWidth; @@ -110,14 +116,6 @@ public class BubbleIconFactory extends BaseIconFactory { bitmapHeight, /* filter */ true); c.drawBitmap(scaledBitmap, bitmapTop, bitmapLeft, /* paint */null); - Paint ringPaint = new Paint(); - ringPaint.setStyle(Paint.Style.STROKE); - ringPaint.setColor(importantConversationColor); - ringPaint.setAntiAlias(true); - ringPaint.setStrokeWidth(ringStrokeWidth); - c.drawCircle(c.getWidth() / 2, c.getHeight() / 2, c.getWidth() / 2 - ringStrokeWidth, - ringPaint); - shadowGenerator.recreateIcon(Bitmap.createBitmap(badgeAndRing), c); return createIconBitmap(badgeAndRing); } else { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt index 51d63cff385a6..36908b854842d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflow.kt @@ -24,7 +24,6 @@ import android.graphics.Matrix import android.graphics.Path import android.graphics.drawable.AdaptiveIconDrawable import android.graphics.drawable.ColorDrawable -import android.graphics.drawable.Drawable import android.graphics.drawable.InsetDrawable import android.util.PathParser import android.util.TypedValue @@ -151,7 +150,7 @@ class BubbleOverflow( return dotColor } - override fun getAppBadge(): Drawable? { + override fun getAppBadge(): Bitmap? { return null } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index c4d33877f17d4..2dd01810b5ec0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -2487,7 +2487,7 @@ public class BubbleStackView extends FrameLayout // name and icon. if (show && mBubbleData.hasBubbleInStackWithKey(mExpandedBubble.getKey())) { final Bubble bubble = mBubbleData.getBubbleInStackWithKey(mExpandedBubble.getKey()); - mManageSettingsIcon.setImageDrawable(bubble.getAppBadge()); + mManageSettingsIcon.setImageBitmap(bubble.getAppBadge()); mManageSettingsText.setText(getResources().getString( R.string.bubbles_app_settings, bubble.getAppName())); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java index fc53ef26dbd95..932f879caef81 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java @@ -126,7 +126,7 @@ public class BubbleViewInfoTask extends AsyncTask