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

Commit 038e454d authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using the task primary color as the background for the wrapped icon

Bug: 74445840
Change-Id: I6c6248c8c71cc9b27cbf301e36400a983127da18
parent 7eee62b3
Loading
Loading
Loading
Loading
+121 B (115 KiB)

File changed.

No diff preview for this file type.

+10 −6
Original line number Diff line number Diff line
@@ -16,13 +16,13 @@
package com.android.quickstep;

import android.annotation.TargetApi;
import android.app.ActivityManager.TaskDescription;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.UserHandle;
import android.util.LruCache;
import android.util.SparseArray;
@@ -56,7 +56,7 @@ public class NormalizedIconLoader extends IconLoader {
            BitmapInfo info = mDefaultIcons.get(userId);
            if (info == null) {
                info = getBitmapInfo(Resources.getSystem()
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId, false);
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId, 0, false);
                mDefaultIcons.put(userId, info);
            }

@@ -65,26 +65,30 @@ public class NormalizedIconLoader extends IconLoader {
    }

    @Override
    protected Drawable createBadgedDrawable(Drawable drawable, int userId) {
        return new FastBitmapDrawable(getBitmapInfo(drawable, userId, false));
    protected Drawable createBadgedDrawable(Drawable drawable, int userId, TaskDescription desc) {
        return new FastBitmapDrawable(getBitmapInfo(drawable, userId, desc.getPrimaryColor(),
                false));
    }

    private synchronized BitmapInfo getBitmapInfo(Drawable drawable, int userId,
            boolean isInstantApp) {
            int primaryColor, boolean isInstantApp) {
        if (mLauncherIcons == null) {
            mLauncherIcons = LauncherIcons.obtain(mContext);
        }

        mLauncherIcons.setWrapperBackgroundColor(primaryColor);
        // User version code O, so that the icon is always wrapped in an adaptive icon container.
        return mLauncherIcons.createBadgedIconBitmap(drawable, UserHandle.of(userId),
                Build.VERSION_CODES.O, isInstantApp);
    }

    @Override
    protected synchronized Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId) {
    protected Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId,
            TaskDescription desc) {
        BitmapInfo bitmapInfo = getBitmapInfo(
                activityInfo.loadUnbadgedIcon(mContext.getPackageManager()),
                userId,
                desc.getPrimaryColor(),
                activityInfo.applicationInfo.isInstantApp());
        return mDrawableFactory.newIcon(bitmapInfo, activityInfo);
    }
+18 −0
Original line number Diff line number Diff line
@@ -29,11 +29,13 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Build;
@@ -60,6 +62,8 @@ import com.android.launcher3.util.Themes;
 */
public class LauncherIcons implements AutoCloseable {

    private static final int DEFAULT_WRAPPER_BACKGROUND = Color.WHITE;

    public static final Object sPoolSync = new Object();
    private static LauncherIcons sPool;

@@ -84,6 +88,9 @@ public class LauncherIcons implements AutoCloseable {
     */
    public void recycle() {
        synchronized (sPoolSync) {
            // Clear any temporary state variables
            mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND;

            next = sPool;
            sPool = this;
        }
@@ -104,7 +111,9 @@ public class LauncherIcons implements AutoCloseable {

    private IconNormalizer mNormalizer;
    private ShadowGenerator mShadowGenerator;

    private Drawable mWrapperIcon;
    private int mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND;

    // sometimes we store linked lists of these things
    private LauncherIcons next;
@@ -222,6 +231,13 @@ public class LauncherIcons implements AutoCloseable {
                Math.min(scale[0], ShadowGenerator.getScaleForBounds(iconBounds)));
    }

    /**
     * Sets the background color used for wrapped adaptive icon
     */
    public void setWrapperBackgroundColor(int color) {
        mWrapperBackgroundColor = (Color.alpha(color) < 255) ? DEFAULT_WRAPPER_BACKGROUND : color;
    }

    private Drawable normalizeAndWrapToAdaptiveIcon(Drawable icon, int iconAppTargetSdk,
            RectF outIconBounds, float[] outScale) {
        float scale = 1f;
@@ -240,6 +256,8 @@ public class LauncherIcons implements AutoCloseable {
                fsd.setScale(scale);
                icon = dr;
                scale = getNormalizer().getScale(icon, outIconBounds, null, null);

                ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor);
            }
        } else {
            scale = getNormalizer().getScale(icon, outIconBounds, null, null);