From 0aa263c5a02efc4d7e989461bcecb4e5a37f318e Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 15 Feb 2022 13:16:22 -0800 Subject: [PATCH] Do not theme icons when the original view is not themed. Fixes bug where animations uses themed icons in All Apps, where the icons are not themed. We want the DragView themed since all valid drop locations will have it appear themed. Bug: 215650713 Test: open/close an app from All Apps Change-Id: I9969ce4921831dd12858ed9b0fe64379e9e3b188 --- src/com/android/launcher3/Utilities.java | 7 ++-- .../android/launcher3/dragndrop/DragView.java | 3 +- .../launcher3/views/FloatingIconView.java | 32 +++++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index cbc21eb352..9bc3d15da2 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -671,14 +671,15 @@ public final class Utilities { /** * Returns the full drawable for info without any flattening or pre-processing. * - * @param outObj this is set to the internal data associated with {@param info}, + * @param shouldThemeIcon If true, will theme icons when applicable + * @param outObj this is set to the internal data associated with {@code info}, * eg {@link LauncherActivityInfo} or {@link ShortcutInfo}. */ @TargetApi(Build.VERSION_CODES.TIRAMISU) public static Drawable getFullDrawable(Context context, ItemInfo info, int width, int height, - Object[] outObj) { + boolean shouldThemeIcon, Object[] outObj) { Drawable icon = loadFullDrawableWithoutTheme(context, info, width, height, outObj); - if (ATLEAST_T && icon instanceof AdaptiveIconDrawable) { + if (ATLEAST_T && icon instanceof AdaptiveIconDrawable && shouldThemeIcon) { AdaptiveIconDrawable aid = (AdaptiveIconDrawable) icon.mutate(); Drawable mono = aid.getMonochrome(); if (mono != null && Themes.isThemedIconEnabled(context)) { diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index 4588a04444..8bfd774918 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -216,7 +216,8 @@ public abstract class DragView extends Fram Object[] outObj = new Object[1]; int w = mWidth; int h = mHeight; - Drawable dr = Utilities.getFullDrawable(mActivity, info, w, h, outObj); + Drawable dr = Utilities.getFullDrawable(mActivity, info, w, h, + true /* shouldThemeIcon */, outObj); if (dr instanceof AdaptiveIconDrawable) { int blurMargin = (int) mActivity.getResources() diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java index 55524dd9ed..cc180d0d7d 100644 --- a/src/com/android/launcher3/views/FloatingIconView.java +++ b/src/com/android/launcher3/views/FloatingIconView.java @@ -247,11 +247,13 @@ public class FloatingIconView extends FrameLayout implements * @param originalView The View that the FloatingIconView will replace. * @param info ItemInfo of the originalView * @param pos The position of the view. + * @param btvIcon The drawable of the BubbleTextView. May be null if original view is not a BTV + * @param outIconLoadResult We store the icon results into this object. */ @WorkerThread @SuppressWarnings("WrongThread") private static void getIconResult(Launcher l, View originalView, ItemInfo info, RectF pos, - Drawable btvIcon, IconLoadResult iconLoadResult) { + @Nullable Drawable btvIcon, IconLoadResult outIconLoadResult) { Drawable drawable; boolean supportsAdaptiveIcons = !info.isDisabled(); // Use original icon for disabled icons. @@ -271,7 +273,9 @@ public class FloatingIconView extends FrameLayout implements int width = (int) pos.width(); int height = (int) pos.height(); if (supportsAdaptiveIcons) { - drawable = getFullDrawable(l, info, width, height, sTmpObjArray); + boolean shouldThemeIcon = btvIcon instanceof FastBitmapDrawable + && ((FastBitmapDrawable) btvIcon).isThemed(); + drawable = getFullDrawable(l, info, width, height, shouldThemeIcon, sTmpObjArray); if (drawable instanceof AdaptiveIconDrawable) { badge = getBadge(l, info, sTmpObjArray[0]); } else { @@ -284,24 +288,25 @@ public class FloatingIconView extends FrameLayout implements // Similar to DragView, we simply use the BubbleTextView icon here. drawable = btvIcon; } else { - drawable = getFullDrawable(l, info, width, height, sTmpObjArray); + drawable = getFullDrawable(l, info, width, height, true /* shouldThemeIcon */, + sTmpObjArray); } } } drawable = drawable == null ? null : drawable.getConstantState().newDrawable(); int iconOffset = getOffsetForIconBounds(l, drawable, pos); - synchronized (iconLoadResult) { - iconLoadResult.btvDrawable = btvIcon == null || drawable == btvIcon + synchronized (outIconLoadResult) { + outIconLoadResult.btvDrawable = btvIcon == null || drawable == btvIcon ? null : btvIcon.getConstantState().newDrawable(); - iconLoadResult.drawable = drawable; - iconLoadResult.badge = badge; - iconLoadResult.iconOffset = iconOffset; - if (iconLoadResult.onIconLoaded != null) { - l.getMainExecutor().execute(iconLoadResult.onIconLoaded); - iconLoadResult.onIconLoaded = null; + outIconLoadResult.drawable = drawable; + outIconLoadResult.badge = badge; + outIconLoadResult.iconOffset = iconOffset; + if (outIconLoadResult.onIconLoaded != null) { + l.getMainExecutor().execute(outIconLoadResult.onIconLoaded); + outIconLoadResult.onIconLoaded = null; } - iconLoadResult.isIconLoaded = true; + outIconLoadResult.isIconLoaded = true; } } @@ -528,8 +533,7 @@ public class FloatingIconView extends FrameLayout implements btvIcon = null; } - IconLoadResult result = new IconLoadResult(info, - btvIcon == null ? false : btvIcon.isThemed()); + IconLoadResult result = new IconLoadResult(info, btvIcon != null && btvIcon.isThemed()); result.btvDrawable = btvIcon; final long fetchIconId = sFetchIconId++;