From 4ac0379f8b486a0375ae422db6f671571daff7e6 Mon Sep 17 00:00:00 2001 From: fbaron Date: Thu, 22 Jun 2023 16:50:41 -0700 Subject: [PATCH] Add themed work badge for themed icons in dragview or floatingiconview Bug: 288491653 Test: Verify that dragging icons with work badge have the right badge theming and that when the icons are animatng (e.g swipe to go back home from app) have the right themed/non-themed work badge Change-Id: I3d75e83ebab0d99866f1fe3688dc06bb7e933a6e --- src/com/android/launcher3/Utilities.java | 9 ++++++--- src/com/android/launcher3/dragndrop/DragView.java | 6 +++--- src/com/android/launcher3/views/FloatingIconView.java | 8 +++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 709c57c82e..e41d8f9cf9 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -569,12 +569,13 @@ public final class Utilities { */ @TargetApi(Build.VERSION_CODES.TIRAMISU) public static Drawable getFullDrawable(Context context, ItemInfo info, int width, int height, - boolean shouldThemeIcon, Object[] outObj) { + boolean shouldThemeIcon, Object[] outObj, boolean[] outIsIconThemed) { Drawable icon = loadFullDrawableWithoutTheme(context, info, width, height, outObj); if (ATLEAST_T && icon instanceof AdaptiveIconDrawable && shouldThemeIcon) { AdaptiveIconDrawable aid = (AdaptiveIconDrawable) icon.mutate(); Drawable mono = aid.getMonochrome(); if (mono != null && Themes.isThemedIconEnabled(context)) { + outIsIconThemed[0] = true; int[] colors = ThemedIconDrawable.getColors(context); mono = mono.mutate(); mono.setTint(colors[1]); @@ -635,7 +636,8 @@ public final class Utilities { * badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge **/ @TargetApi(Build.VERSION_CODES.O) - public static Drawable getBadge(Context context, ItemInfo info, Object obj) { + public static Drawable getBadge(Context context, ItemInfo info, Object obj, + boolean isIconThemed) { LauncherAppState appState = LauncherAppState.getInstance(context); if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { boolean iconBadged = (info instanceof ItemInfoWithIcon) @@ -653,7 +655,8 @@ public final class Utilities { } else { return Process.myUserHandle().equals(info.user) ? new ColorDrawable(Color.TRANSPARENT) - : context.getDrawable(R.drawable.ic_work_app_badge); + : context.getDrawable(isIconThemed + ? R.drawable.ic_work_app_badge_themed : R.drawable.ic_work_app_badge); } } diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index c26d673f8c..b9bb52c548 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -224,11 +224,11 @@ public abstract class DragView extends Fram // Load the adaptive icon on a background thread and add the view in ui thread. MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> { Object[] outObj = new Object[1]; + boolean[] outIsIconThemed = new boolean[1]; int w = mWidth; int h = mHeight; Drawable dr = Utilities.getFullDrawable(mActivity, info, w, h, - true /* shouldThemeIcon */, outObj); - + true /* shouldThemeIcon */, outObj, outIsIconThemed); if (dr instanceof AdaptiveIconDrawable) { int blurMargin = (int) mActivity.getResources() .getDimension(R.dimen.blur_size_medium_outline) / 2; @@ -237,7 +237,7 @@ public abstract class DragView extends Fram bounds.inset(blurMargin, blurMargin); // Badge is applied after icon normalization so the bounds for badge should not // be scaled down due to icon normalization. - mBadge = getBadge(mActivity, info, outObj[0]); + mBadge = getBadge(mActivity, info, outObj[0], outIsIconThemed[0]); FastBitmapDrawable.setBadgeBounds(mBadge, bounds); // Do not draw the background in case of folder as its translucent diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java index 3b052210a4..8aeb16c7cb 100644 --- a/src/com/android/launcher3/views/FloatingIconView.java +++ b/src/com/android/launcher3/views/FloatingIconView.java @@ -289,12 +289,14 @@ public class FloatingIconView extends FrameLayout implements int width = (int) pos.width(); int height = (int) pos.height(); Object[] tmpObjArray = new Object[1]; + boolean[] outIsIconThemed = new boolean[1]; if (supportsAdaptiveIcons) { boolean shouldThemeIcon = btvIcon instanceof FastBitmapDrawable && ((FastBitmapDrawable) btvIcon).isThemed(); - drawable = getFullDrawable(l, info, width, height, shouldThemeIcon, tmpObjArray); + drawable = getFullDrawable( + l, info, width, height, shouldThemeIcon, tmpObjArray, outIsIconThemed); if (drawable instanceof AdaptiveIconDrawable) { - badge = getBadge(l, info, tmpObjArray[0]); + badge = getBadge(l, info, tmpObjArray[0], outIsIconThemed[0]); } else { // The drawable we get back is not an adaptive icon, so we need to use the // BubbleTextView icon that is already legacy treated. @@ -306,7 +308,7 @@ public class FloatingIconView extends FrameLayout implements drawable = btvIcon; } else { drawable = getFullDrawable(l, info, width, height, true /* shouldThemeIcon */, - tmpObjArray); + tmpObjArray, outIsIconThemed); } } }