From 0c1dd96b1f08c9c27d3edca10865820b3e6968fb Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 7 Dec 2022 12:56:50 -0800 Subject: [PATCH] Fix drawing the ring around adaptive app icons It seems like when you set the bounds on an adaptive icon, it does not draw the icon in the center of those bounds. Fix by translating the drawable before setting the bounds. Also removes drawing black first as this seems to leave a slight artifact around the edges of the circle otherwise. Bug: 260636233 Test: manual - mark a bubbleable notification as an important person - bubble it => observe the app icon badge is centered in the highlight ring Change-Id: I04279a3c51badd26a5141a8edf77f05472cb9718 --- .../wm/shell/bubbles/BubbleBadgeIconFactory.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java index d3a9a672ec766..56b13b8dcd462 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java @@ -19,7 +19,6 @@ package com.android.wm.shell.bubbles; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.AdaptiveIconDrawable; @@ -59,7 +58,8 @@ public class BubbleBadgeIconFactory extends BaseIconFactory { private class CircularRingDrawable extends CircularAdaptiveIcon { final int mImportantConversationColor; - final Rect mTempBounds = new Rect(); + final int mRingWidth; + final Rect mInnerBounds = new Rect(); final Drawable mDr; @@ -68,6 +68,8 @@ public class BubbleBadgeIconFactory extends BaseIconFactory { mDr = dr; mImportantConversationColor = mContext.getResources().getColor( R.color.important_conversation, null); + mRingWidth = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.importance_ring_stroke_width); } @Override @@ -75,11 +77,10 @@ public class BubbleBadgeIconFactory extends BaseIconFactory { int save = canvas.save(); canvas.clipPath(getIconMask()); canvas.drawColor(mImportantConversationColor); - int ringStrokeWidth = mContext.getResources().getDimensionPixelSize( - com.android.internal.R.dimen.importance_ring_stroke_width); - mTempBounds.set(getBounds()); - mTempBounds.inset(ringStrokeWidth, ringStrokeWidth); - mDr.setBounds(mTempBounds); + mInnerBounds.set(getBounds()); + mInnerBounds.inset(mRingWidth, mRingWidth); + canvas.translate(mInnerBounds.left, mInnerBounds.top); + mDr.setBounds(0, 0, mInnerBounds.width(), mInnerBounds.height()); mDr.draw(canvas); canvas.restoreToCount(save); } @@ -106,7 +107,6 @@ public class BubbleBadgeIconFactory extends BaseIconFactory { int save = canvas.save(); canvas.clipPath(getIconMask()); - canvas.drawColor(Color.BLACK); Drawable d; if ((d = getBackground()) != null) { d.draw(canvas);