From d872a97bd08e4c6c0946b5f9412ecff7babd4301 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 24 Nov 2021 18:07:04 -0800 Subject: [PATCH] Updating icon badging logic Bug: 201682172 Test: Manual Change-Id: I57421b0c77e12f1cd464e532d2a1383c2cf93981 --- .../uioverrides/PredictedAppIcon.java | 3 +- .../com/android/quickstep/TaskIconCache.java | 18 +++--- .../android/launcher3/AutoInstallsLayout.java | 4 +- src/com/android/launcher3/BubbleTextView.java | 14 ++++- src/com/android/launcher3/Utilities.java | 43 +++----------- .../android/launcher3/dragndrop/DragView.java | 15 +++-- .../launcher3/folder/PreviewItemManager.java | 3 +- .../graphics/LauncherPreviewRenderer.java | 9 ++- .../icons/ComponentWithLabelAndIcon.java | 3 +- .../android/launcher3/icons/IconCache.java | 22 +------ .../icons/LauncherActivityCachingLogic.java | 3 +- .../launcher3/icons/ShortcutCachingLogic.java | 4 +- .../model/data/ItemInfoWithIcon.java | 8 +-- .../model/data/SearchActionItemInfo.java | 5 +- .../launcher3/popup/PopupPopulator.java | 2 +- .../launcher3/shortcuts/DeepShortcutView.java | 1 + .../launcher3/views/FloatingIconView.java | 10 ++-- .../widget/DatabaseWidgetPreviewLoader.java | 59 +------------------ .../widget/PendingAppWidgetHostView.java | 4 +- .../widget/PendingItemDragHelper.java | 3 +- .../android/launcher3/widget/WidgetCell.java | 9 +-- 21 files changed, 71 insertions(+), 171 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java b/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java index ee6e8cee9b..351ec4a1b1 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java +++ b/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java @@ -16,6 +16,7 @@ package com.android.launcher3.uioverrides; import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL; +import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED; import android.animation.Animator; import android.animation.AnimatorSet; @@ -236,7 +237,7 @@ public class PredictedAppIcon extends DoubleShadowBubbleTextView { mSlotMachineIcons = new ArrayList<>(iconsToAnimate.size() + 2); mSlotMachineIcons.add(getIcon()); iconsToAnimate.stream() - .map(iconInfo -> iconInfo.newThemedIcon(mContext)) + .map(iconInfo -> iconInfo.newIcon(mContext, FLAG_THEMED)) .forEach(mSlotMachineIcons::add); if (endWithOriginalIcon) { mSlotMachineIcons.add(getIcon()); diff --git a/quickstep/src/com/android/quickstep/TaskIconCache.java b/quickstep/src/com/android/quickstep/TaskIconCache.java index fa61fffbc6..b5d6fae73a 100644 --- a/quickstep/src/com/android/quickstep/TaskIconCache.java +++ b/quickstep/src/com/android/quickstep/TaskIconCache.java @@ -26,10 +26,8 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.UserHandle; import android.text.TextUtils; -import android.util.SparseArray; import android.view.accessibility.AccessibilityManager; import androidx.annotation.WorkerThread; @@ -37,6 +35,7 @@ import androidx.annotation.WorkerThread; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.icons.BaseIconFactory; +import com.android.launcher3.icons.BaseIconFactory.IconOptions; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.IconProvider; import com.android.launcher3.util.DisplayController; @@ -63,7 +62,7 @@ public class TaskIconCache implements DisplayInfoChangeListener { private final Context mContext; private final TaskKeyLruCache mIconCache; - private final SparseArray mDefaultIcons = new SparseArray<>(); + private final BitmapInfo[] mDefaultIcons = new BitmapInfo[1]; private final IconProvider mIconProvider; private BaseIconFactory mIconFactory; @@ -154,7 +153,6 @@ public class TaskIconCache implements DisplayInfoChangeListener { // TODO: Load icon resource (b/143363444) Bitmap icon = TaskDescriptionCompat.getIcon(desc, key.userId); if (icon != null) { - /* isInstantApp */ entry.icon = getBitmapInfo( new BitmapDrawable(mContext.getResources(), icon), key.userId, @@ -210,14 +208,12 @@ public class TaskIconCache implements DisplayInfoChangeListener { @WorkerThread private Drawable getDefaultIcon(int userId) { synchronized (mDefaultIcons) { - BitmapInfo info = mDefaultIcons.get(userId); - if (info == null) { + if (mDefaultIcons[0] == null) { try (BaseIconFactory bif = getIconFactory()) { - info = bif.makeDefaultIcon(UserHandle.of(userId)); + mDefaultIcons[0] = bif.makeDefaultIcon(); } - mDefaultIcons.put(userId, info); } - return info.newIcon(mContext); + return mDefaultIcons[0].clone().withUser(UserHandle.of(userId)).newIcon(mContext); } } @@ -229,8 +225,8 @@ public class TaskIconCache implements DisplayInfoChangeListener { bif.setWrapperBackgroundColor(primaryColor); // User version code O, so that the icon is always wrapped in an adaptive icon container - return bif.createBadgedIconBitmap(drawable, UserHandle.of(userId), - Build.VERSION_CODES.O, isInstantApp); + return bif.createBadgedIconBitmap(drawable, + new IconOptions().setUser(UserHandle.of(userId)).setInstantApp(isInstantApp)); } } diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java index 5b655a4740..64666b0041 100644 --- a/src/com/android/launcher3/AutoInstallsLayout.java +++ b/src/com/android/launcher3/AutoInstallsLayout.java @@ -27,9 +27,7 @@ import android.content.res.Resources; import android.database.sqlite.SQLiteDatabase; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.os.Build.VERSION; import android.os.Bundle; -import android.os.Process; import android.text.TextUtils; import android.util.ArrayMap; import android.util.AttributeSet; @@ -449,7 +447,7 @@ public class AutoInstallsLayout { // Auto installs should always support the current platform version. LauncherIcons li = LauncherIcons.obtain(mContext); mValues.put(LauncherSettings.Favorites.ICON, GraphicsUtils.flattenBitmap( - li.createBadgedIconBitmap(icon, Process.myUserHandle(), VERSION.SDK_INT).icon)); + li.createBadgedIconBitmap(icon).icon)); li.recycle(); mValues.put(Favorites.ICON_PACKAGE, mIconRes.getResourcePackageName(iconId)); diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 5a6365adf9..4ee192aacb 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -18,6 +18,8 @@ package com.android.launcher3; import static com.android.launcher3.config.FeatureFlags.ENABLE_ICON_LABEL_AUTO_SCALING; import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon; +import static com.android.launcher3.icons.BitmapInfo.FLAG_NO_BADGE; +import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED; import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound; import android.animation.Animator; @@ -144,6 +146,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, private final boolean mIsRtl; private final int mIconSize; + @ViewDebug.ExportedProperty(category = "launcher") + private boolean mHideBadge = false; @ViewDebug.ExportedProperty(category = "launcher") private boolean mIsIconVisible = true; @ViewDebug.ExportedProperty(category = "launcher") @@ -241,6 +245,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, super.onFocusChanged(focused, direction, previouslyFocusedRect); } + public void setHideBadge(boolean hideBadge) { + mHideBadge = hideBadge; + } + /** * Resets the view so it can be recycled. */ @@ -364,7 +372,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, protected void applyIconAndLabel(ItemInfoWithIcon info) { boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER || mDisplay == DISPLAY_TASKBAR; - FastBitmapDrawable iconDrawable = info.newIcon(getContext(), useTheme); + int flags = useTheme ? FLAG_THEMED : 0; + if (mHideBadge) { + flags |= FLAG_NO_BADGE; + } + FastBitmapDrawable iconDrawable = info.newIcon(getContext(), flags); mDotParams.color = IconPalette.getMutedColor(iconDrawable.getIconColor(), 0.54f); setIcon(iconDrawable); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index d2fe483c96..ac194d2077 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -16,6 +16,7 @@ package com.android.launcher3; +import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ICON_BADGED; import android.annotation.TargetApi; @@ -36,7 +37,6 @@ import android.content.pm.ShortcutInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; -import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.LightingColorFilter; @@ -48,12 +48,12 @@ import android.graphics.RectF; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.graphics.drawable.InsetDrawable; import android.net.Uri; import android.os.Build; import android.os.DeadObjectException; import android.os.Handler; import android.os.Message; +import android.os.Process; import android.os.TransactionTooLargeException; import android.provider.Settings; import android.text.Spannable; @@ -78,7 +78,6 @@ import com.android.launcher3.graphics.GridCustomizationsProvider; import com.android.launcher3.graphics.TintedDrawableSpan; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.FastBitmapDrawable; -import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.icons.ShortcutCachingLogic; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; @@ -110,8 +109,6 @@ public final class Utilities { private static final Pattern sTrimPattern = Pattern.compile("^[\\s|\\p{javaSpaceChar}]*(.*)[\\s|\\p{javaSpaceChar}]*$"); - private static final float[] sTmpFloatArray = new float[4]; - private static final int[] sLoc0 = new int[2]; private static final int[] sLoc1 = new int[2]; private static final Matrix sMatrix = new Matrix(); @@ -738,27 +735,23 @@ public final class Utilities { @TargetApi(Build.VERSION_CODES.O) public static Drawable getBadge(Context context, ItemInfo info, Object obj) { LauncherAppState appState = LauncherAppState.getInstance(context); - int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize; if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0; if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) { // The item is not yet added on home screen. - return new FixedSizeEmptyDrawable(iconSize); + return new ColorDrawable(Color.TRANSPARENT); } ShortcutInfo si = (ShortcutInfo) obj; - Bitmap badge = LauncherAppState.getInstance(appState.getContext()) - .getIconCache().getShortcutInfoBadge(si).icon; - float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize); - float insetFraction = (iconSize - badgeSize) / iconSize; - return new InsetDrawable(new FastBitmapDrawable(badge), - insetFraction, insetFraction, 0, 0); + return LauncherAppState.getInstance(appState.getContext()) + .getIconCache().getShortcutInfoBadge(si).newIcon(context, FLAG_THEMED); } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) { return ((FolderAdaptiveIcon) obj).getBadge(); } else { - return context.getPackageManager() - .getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user); + return Process.myUserHandle().equals(info.user) + ? new ColorDrawable(Color.TRANSPARENT) + : context.getDrawable(R.drawable.ic_work_app_badge); } } @@ -864,24 +857,4 @@ public final class Utilities { v.getLocationOnScreen(pos); return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); } - - private static class FixedSizeEmptyDrawable extends ColorDrawable { - - private final int mSize; - - public FixedSizeEmptyDrawable(int size) { - super(Color.TRANSPARENT); - mSize = size; - } - - @Override - public int getIntrinsicHeight() { - return mSize; - } - - @Override - public int getIntrinsicWidth() { - return mSize; - } - } } diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index fa65945da3..8313571d2d 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -21,6 +21,7 @@ import static android.view.View.MeasureSpec.makeMeasureSpec; import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA; import static com.android.launcher3.Utilities.getBadge; +import static com.android.launcher3.icons.FastBitmapDrawable.getDisabledColorFilter; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import android.animation.Animator; @@ -31,9 +32,9 @@ import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.TargetApi; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.ColorFilter; import android.graphics.Path; import android.graphics.Picture; import android.graphics.Point; @@ -225,9 +226,8 @@ 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. - Rect badgeBounds = new Rect(bounds); mBadge = getBadge(mActivity, info, outObj[0]); - mBadge.setBounds(badgeBounds); + FastBitmapDrawable.setBadgeBounds(mBadge, bounds); // Do not draw the background in case of folder as its translucent final boolean shouldDrawBackground = !(dr instanceof FolderAdaptiveIcon); @@ -280,11 +280,10 @@ public abstract class DragView extends Fram removeAllViewsInLayout(); if (info.isDisabled()) { - FastBitmapDrawable d = new FastBitmapDrawable((Bitmap) null); - d.setIsDisabled(true); - mBgSpringDrawable.setColorFilter(d.getColorFilter()); - mFgSpringDrawable.setColorFilter(d.getColorFilter()); - mBadge.setColorFilter(d.getColorFilter()); + ColorFilter filter = getDisabledColorFilter(); + mBgSpringDrawable.setColorFilter(filter); + mFgSpringDrawable.setColorFilter(filter); + mBadge.setColorFilter(filter); } invalidate(); })); diff --git a/src/com/android/launcher3/folder/PreviewItemManager.java b/src/com/android/launcher3/folder/PreviewItemManager.java index 8bef6ad7ff..6355b62e27 100644 --- a/src/com/android/launcher3/folder/PreviewItemManager.java +++ b/src/com/android/launcher3/folder/PreviewItemManager.java @@ -21,6 +21,7 @@ import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.EXIT_INDE import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW; import static com.android.launcher3.folder.FolderIcon.DROP_IN_ANIMATION_DURATION; import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon; +import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -429,7 +430,7 @@ public class PreviewItemManager { drawable.setLevel(item.getProgressLevel()); p.drawable = drawable; } else { - p.drawable = item.newIcon(mContext, true); + p.drawable = item.newIcon(mContext, FLAG_THEMED); } p.drawable.setBounds(0, 0, mIconSize, mIconSize); p.item = item; diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 73e18f42f9..abf002f792 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -43,7 +43,6 @@ import android.graphics.drawable.ColorDrawable; import android.os.Build; import android.os.Handler; import android.os.Looper; -import android.os.Process; import android.util.AttributeSet; import android.util.SparseIntArray; import android.view.ContextThemeWrapper; @@ -202,10 +201,10 @@ public class LauncherPreviewRenderer extends ContextWrapper BaseIconFactory iconFactory = new BaseIconFactory(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize) { }; - BitmapInfo iconInfo = iconFactory.createBadgedIconBitmap(new AdaptiveIconDrawable( - new ColorDrawable(Color.WHITE), new ColorDrawable(Color.WHITE)), - Process.myUserHandle(), - Build.VERSION.SDK_INT); + BitmapInfo iconInfo = iconFactory.createBadgedIconBitmap( + new AdaptiveIconDrawable( + new ColorDrawable(Color.WHITE), + new ColorDrawable(Color.WHITE))); mWorkspaceItemInfo = new WorkspaceItemInfo(); mWorkspaceItemInfo.bitmap = iconInfo; diff --git a/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java b/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java index 248a57d2fd..c8606b1002 100644 --- a/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java +++ b/src/com/android/launcher3/icons/ComponentWithLabelAndIcon.java @@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.icons.BaseIconFactory.IconOptions; /** * Extension of ComponentWithLabel to also support loading icons @@ -47,7 +48,7 @@ public interface ComponentWithLabelAndIcon extends ComponentWithLabel { return super.loadIcon(context, object); } try (LauncherIcons li = LauncherIcons.obtain(context)) { - return li.createBadgedIconBitmap(d, object.getUser(), 0); + return li.createBadgedIconBitmap(d, new IconOptions().setUser(object.getUser())); } } } diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java index 936eeb9220..f512ced2eb 100644 --- a/src/com/android/launcher3/icons/IconCache.java +++ b/src/com/android/launcher3/icons/IconCache.java @@ -216,14 +216,7 @@ public class IconCache extends BaseIconCache { * Fill in {@param info} with the icon for {@param si} */ public void getShortcutIcon(ItemInfoWithIcon info, ShortcutInfo si) { - getShortcutIcon(info, si, true, mIsUsingFallbackOrNonDefaultIconCheck); - } - - /** - * Fill in {@param info} with an unbadged icon for {@param si} - */ - public void getUnbadgedShortcutIcon(ItemInfoWithIcon info, ShortcutInfo si) { - getShortcutIcon(info, si, false, mIsUsingFallbackOrNonDefaultIconCheck); + getShortcutIcon(info, si, mIsUsingFallbackOrNonDefaultIconCheck); } /** @@ -232,11 +225,6 @@ public class IconCache extends BaseIconCache { */ public void getShortcutIcon(T info, ShortcutInfo si, @NonNull Predicate fallbackIconCheck) { - getShortcutIcon(info, si, true /* use badged */, fallbackIconCheck); - } - - private synchronized void getShortcutIcon(T info, ShortcutInfo si, - boolean useBadged, @NonNull Predicate fallbackIconCheck) { BitmapInfo bitmapInfo; if (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) { bitmapInfo = cacheLocked(ShortcutKey.fromInfo(si).componentName, si.getUserHandle(), @@ -252,13 +240,7 @@ public class IconCache extends BaseIconCache { if (isDefaultIcon(bitmapInfo, si.getUserHandle()) && fallbackIconCheck.test(info)) { return; } - info.bitmap = bitmapInfo; - if (useBadged) { - BitmapInfo badgeInfo = getShortcutInfoBadge(si); - try (LauncherIcons li = LauncherIcons.obtain(mContext)) { - info.bitmap = li.badgeBitmap(info.bitmap.icon, badgeInfo); - } - } + info.bitmap = bitmapInfo.withBadgeInfo(getShortcutInfoBadge(si)); } /** diff --git a/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java b/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java index e820ac474a..4b8c1ad590 100644 --- a/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java +++ b/src/com/android/launcher3/icons/LauncherActivityCachingLogic.java @@ -22,6 +22,7 @@ import android.os.UserHandle; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; +import com.android.launcher3.icons.BaseIconFactory.IconOptions; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.util.ResourceBasedOverride; @@ -59,7 +60,7 @@ public class LauncherActivityCachingLogic try (LauncherIcons li = LauncherIcons.obtain(context)) { return li.createBadgedIconBitmap(LauncherAppState.getInstance(context) .getIconProvider().getIcon(object, li.mFillResIconDpi), - object.getUser(), object.getApplicationInfo().targetSdkVersion); + new IconOptions().setUser(object.getUser())); } } } diff --git a/src/com/android/launcher3/icons/ShortcutCachingLogic.java b/src/com/android/launcher3/icons/ShortcutCachingLogic.java index d7eed06901..6a8f34a93d 100644 --- a/src/com/android/launcher3/icons/ShortcutCachingLogic.java +++ b/src/com/android/launcher3/icons/ShortcutCachingLogic.java @@ -71,8 +71,8 @@ public class ShortcutCachingLogic implements CachingLogic { Drawable unbadgedDrawable = ShortcutCachingLogic.getIcon( context, info, LauncherAppState.getIDP(context).fillResIconDpi); if (unbadgedDrawable == null) return BitmapInfo.LOW_RES_INFO; - return new BitmapInfo(li.createScaledBitmapWithoutShadow( - unbadgedDrawable, 0), Themes.getColorAccent(context)); + return new BitmapInfo(li.createScaledBitmapWithoutShadow(unbadgedDrawable), + Themes.getColorAccent(context)); } } diff --git a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java index a74c02fb01..19345d7693 100644 --- a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java +++ b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java @@ -23,6 +23,7 @@ import android.content.Intent; import androidx.annotation.Nullable; import com.android.launcher3.icons.BitmapInfo; +import com.android.launcher3.icons.BitmapInfo.DrawableCreationFlags; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.logging.FileLog; import com.android.launcher3.pm.PackageInstallInfo; @@ -230,15 +231,14 @@ public abstract class ItemInfoWithIcon extends ItemInfo { * Returns a FastBitmapDrawable with the icon. */ public FastBitmapDrawable newIcon(Context context) { - return newIcon(context, false); + return newIcon(context, 0); } /** * Returns a FastBitmapDrawable with the icon and context theme applied */ - public FastBitmapDrawable newIcon(Context context, boolean applyTheme) { - FastBitmapDrawable drawable = applyTheme - ? bitmap.newThemedIcon(context) : bitmap.newIcon(context); + public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags) { + FastBitmapDrawable drawable = bitmap.newIcon(context, creationFlags); drawable.setIsDisabled(isDisabled()); return drawable; } diff --git a/src/com/android/launcher3/model/data/SearchActionItemInfo.java b/src/com/android/launcher3/model/data/SearchActionItemInfo.java index c6e5e8a98f..cc22601a6a 100644 --- a/src/com/android/launcher3/model/data/SearchActionItemInfo.java +++ b/src/com/android/launcher3/model/data/SearchActionItemInfo.java @@ -28,7 +28,6 @@ import androidx.annotation.Nullable; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherSettings; -import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.logger.LauncherAtom.ItemInfo; import com.android.launcher3.logger.LauncherAtom.SearchActionItem; import com.android.launcher3.model.AllAppsList; @@ -176,9 +175,7 @@ public class SearchActionItemInfo extends ItemInfoWithIcon { model.updateAndBindWorkspaceItem(() -> { PackageItemInfo pkgInfo = new PackageItemInfo(getIntentPackageName(), user); app.getIconCache().getTitleAndIconForApp(pkgInfo, false); - try (LauncherIcons li = LauncherIcons.obtain(app.getContext())) { - info.bitmap = li.badgeBitmap(info.bitmap.icon, pkgInfo.bitmap); - } + info.bitmap = info.bitmap.withBadgeInfo(pkgInfo.bitmap); return info; }); } diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 1dce1f25e8..8be4e6c8d9 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -162,7 +162,7 @@ public class PopupPopulator { for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) { final ShortcutInfo shortcut = shortcuts.get(i); final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, context); - cache.getUnbadgedShortcutIcon(si, shortcut); + cache.getShortcutIcon(si, shortcut); si.rank = i; si.container = CONTAINER_SHORTCUTS; diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index 71d288c0ab..2f17ce0260 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -72,6 +72,7 @@ public class DeepShortcutView extends FrameLayout implements BubbleTextHolder { protected void onFinishInflate() { super.onFinishInflate(); mBubbleText = findViewById(R.id.bubble_text); + mBubbleText.setHideBadge(true); mIconView = findViewById(R.id.icon); tryUpdateTextBackground(); } diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java index 8b7ad46dfb..e731706997 100644 --- a/src/com/android/launcher3/views/FloatingIconView.java +++ b/src/com/android/launcher3/views/FloatingIconView.java @@ -338,15 +338,13 @@ public class FloatingIconView extends FrameLayout implements setLayoutParams(lp); final LayoutParams clipViewLp = (LayoutParams) mClipIconView.getLayoutParams(); - final int clipViewOgHeight = clipViewLp.height; - final int clipViewOgWidth = clipViewLp.width; + if (mBadge != null) { + Rect badgeBounds = new Rect(0, 0, clipViewLp.width, clipViewLp.height); + FastBitmapDrawable.setBadgeBounds(mBadge, badgeBounds); + } clipViewLp.width = lp.width; clipViewLp.height = lp.height; mClipIconView.setLayoutParams(clipViewLp); - - if (mBadge != null) { - mBadge.setBounds(0, 0, clipViewOgWidth, clipViewOgHeight); - } } if (!mIsOpening && btvIcon != null) { diff --git a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java index 784f4f050e..7030f6dede 100644 --- a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java +++ b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java @@ -25,15 +25,10 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; -import android.graphics.Rect; import android.graphics.RectF; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Handler; -import android.os.Process; -import android.os.UserHandle; -import android.util.ArrayMap; import android.util.Log; import android.util.Size; @@ -44,7 +39,6 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.icons.BitmapRenderer; -import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.icons.ShadowGenerator; import com.android.launcher3.icons.cache.HandlerRunnable; @@ -65,9 +59,6 @@ public class DatabaseWidgetPreviewLoader { private final Context mContext; private final float mPreviewBoxCornerRadius; - private final UserHandle mMyUser = Process.myUserHandle(); - private final ArrayMap mUserBadges = new ArrayMap<>(); - public DatabaseWidgetPreviewLoader(Context context) { mContext = context; float previewCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(context); @@ -108,52 +99,6 @@ public class DatabaseWidgetPreviewLoader { } } - /** - * Returns a drawable that can be used as a badge for the user or null. - */ - // @UiThread - public Drawable getBadgeForUser(UserHandle user, int badgeSize) { - if (mMyUser.equals(user)) { - return null; - } - - Bitmap badgeBitmap = getUserBadge(user, badgeSize); - FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap); - d.setFilterBitmap(true); - d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight()); - return d; - } - - private Bitmap getUserBadge(UserHandle user, int badgeSize) { - synchronized (mUserBadges) { - Bitmap badgeBitmap = mUserBadges.get(user); - if (badgeBitmap != null) { - return badgeBitmap; - } - - final Resources res = mContext.getResources(); - badgeBitmap = Bitmap.createBitmap(badgeSize, badgeSize, Bitmap.Config.ARGB_8888); - - Drawable drawable = mContext.getPackageManager().getUserBadgedDrawableForDensity( - new BitmapDrawable(res, badgeBitmap), user, - new Rect(0, 0, badgeSize, badgeSize), - 0); - if (drawable instanceof BitmapDrawable) { - badgeBitmap = ((BitmapDrawable) drawable).getBitmap(); - } else { - badgeBitmap.eraseColor(Color.TRANSPARENT); - Canvas c = new Canvas(badgeBitmap); - drawable.setBounds(0, 0, badgeSize, badgeSize); - drawable.draw(c); - c.setBitmap(null); - } - - mUserBadges.put(user, badgeBitmap); - return badgeBitmap; - } - } - - /** * Generates the widget preview from either the {@link WidgetManagerHelper} or cache * and add badge at the bottom right corner. @@ -318,8 +263,8 @@ public class DatabaseWidgetPreviewLoader { LauncherIcons li = LauncherIcons.obtain(mContext); Drawable icon = li.createBadgedIconBitmap( mutateOnMainThread(info.getFullResIcon( - LauncherAppState.getInstance(mContext).getIconCache())), - Process.myUserHandle(), 0).newIcon(mContext); + LauncherAppState.getInstance(mContext).getIconCache()))) + .newIcon(mContext); li.recycle(); icon.setBounds(padding, padding, padding + iconSize, padding + iconSize); diff --git a/src/com/android/launcher3/widget/PendingAppWidgetHostView.java b/src/com/android/launcher3/widget/PendingAppWidgetHostView.java index 553ba13fe7..1f6551e160 100644 --- a/src/com/android/launcher3/widget/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/PendingAppWidgetHostView.java @@ -17,6 +17,7 @@ package com.android.launcher3.widget; import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon; +import static com.android.launcher3.icons.FastBitmapDrawable.getDisabledColorFilter; import static com.android.launcher3.widget.WidgetSections.getWidgetSections; import android.content.Context; @@ -159,8 +160,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView disabledIcon.setIsDisabled(true); mCenterDrawable = disabledIcon; } else { - widgetCategoryIcon.setColorFilter( - FastBitmapDrawable.getDisabledFColorFilter(/* disabledAlpha= */ 1f)); + widgetCategoryIcon.setColorFilter(getDisabledColorFilter()); mCenterDrawable = widgetCategoryIcon; } mSettingIconDrawable = null; diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java index 463f4ac1b1..46c0b99938 100644 --- a/src/com/android/launcher3/widget/PendingItemDragHelper.java +++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java @@ -181,8 +181,7 @@ public class PendingItemDragHelper extends DragPreviewProvider { PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo; Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache()); LauncherIcons li = LauncherIcons.obtain(launcher); - preview = new FastBitmapDrawable( - li.createScaledBitmapWithoutShadow(icon, 0)); + preview = new FastBitmapDrawable(li.createScaledBitmapWithoutShadow(icon)); previewWidth = preview.getIntrinsicWidth(); previewHeight = preview.getIntrinsicHeight(); li.recycle(); diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index c92fe5a516..2796721c63 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -26,6 +26,7 @@ import static com.android.launcher3.Utilities.ATLEAST_S; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.os.Process; import android.util.AttributeSet; import android.util.Log; import android.util.Size; @@ -48,7 +49,6 @@ import com.android.launcher3.CheckLongPressHelper; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.R; -import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.icons.RoundDrawableWrapper; import com.android.launcher3.icons.cache.HandlerRunnable; @@ -372,14 +372,11 @@ public class WidgetCell extends LinearLayout { /** Used to show the badge when the widget is in the recommended section */ public void showBadge() { - Drawable badge = mWidgetPreviewLoader.getBadgeForUser(mItem.user, - BaseIconFactory.getBadgeSizeForIconSize( - mActivity.getDeviceProfile().allAppsIconSizePx)); - if (badge == null) { + if (Process.myUserHandle().equals(mItem.user)) { mWidgetBadge.setVisibility(View.GONE); } else { mWidgetBadge.setVisibility(View.VISIBLE); - mWidgetBadge.setImageDrawable(badge); + mWidgetBadge.setImageResource(R.drawable.ic_work_app_badge); } }