Merge "Do not theme icons when the original view is not themed."

This commit is contained in:
TreeHugger Robot
2022-02-16 17:13:10 +00:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 18 deletions
+4 -3
View File
@@ -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)) {
@@ -216,7 +216,8 @@ public abstract class DragView<T extends Context & ActivityContext> 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()
@@ -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++;