From 8d25921a2216552c8ab8356217b8e8ffab733f26 Mon Sep 17 00:00:00 2001 From: Sergey Serokurov Date: Mon, 9 May 2022 17:03:00 -0700 Subject: [PATCH] Use bitmap width for bubble icon and app badge to calculate translation Bubble icon view and app badge view have 0 width immediately after ImageView#setImageBitmap is called. Bug: 223911171 Test: manual, video: https://drive.google.com/file/d/1Mw0BaKmndLCML3VlpkCuXUO0P005CPQ1/view?usp=sharing Change-Id: Id88cf7436395440cbecf9adc8734bdcb49936367 --- .../src/com/android/wm/shell/bubbles/BadgedImageView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 3876533a922ed..b04a1fa93bbdc 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 @@ -19,6 +19,7 @@ import android.annotation.DrawableRes; import android.annotation.Nullable; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Path; @@ -350,16 +351,19 @@ public class BadgedImageView extends ConstraintLayout { } void showBadge() { - if (mBubble.getAppBadge() == null) { + Bitmap appBadgeBitmap = mBubble.getAppBadge(); + if (appBadgeBitmap == null) { mAppIcon.setVisibility(GONE); return; } + int translationX; if (mOnLeft) { - translationX = -(mBubbleIcon.getWidth() - mAppIcon.getWidth()); + translationX = -(mBubble.getBubbleIcon().getWidth() - appBadgeBitmap.getWidth()); } else { translationX = 0; } + mAppIcon.setTranslationX(translationX); mAppIcon.setVisibility(VISIBLE); }