Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ac0379f authored by fbaron's avatar fbaron
Browse files

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
parent 961e6831
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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);
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -224,11 +224,11 @@ public abstract class DragView<T extends Context & ActivityContext> 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<T extends Context & ActivityContext> 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
+5 −3
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }