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

Commit 275681c5 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Updating FastBitmapDrawable to store BitmapInfo instead of bitmap and icon separately

Bug: 390572144
Flag: EXEMPT refactor
Test: atest LauncherBindableItemsContainerTest
Change-Id: I391be39de59cb31b6d4233e08a392aface822ab4
parent 2571238a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class BitmapInfo {

    public static final String TAG = "BitmapInfo";

    @NonNull
    public final Bitmap icon;
    public final int color;

@@ -72,7 +73,7 @@ public class BitmapInfo {

    private BitmapInfo badgeInfo;

    public BitmapInfo(Bitmap icon, int color) {
    public BitmapInfo(@NonNull Bitmap icon, int color) {
        this.icon = icon;
        this.color = color;
    }
+5 −5
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap
                return super.newIcon(context, creationFlags);
            }
            ClockIconDrawable.ClockConstantState cs = new ClockIconDrawable.ClockConstantState(
                    icon, color, themedFgColor, boundsOffset, info, bg, bgFilter);
                    this, themedFgColor, boundsOffset, info, bg, bgFilter);
            FastBitmapDrawable d = cs.newDrawable();
            applyFlags(context, d, creationFlags);
            return d;
@@ -341,7 +341,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap
        private final float mCanvasScale;

        ClockIconDrawable(ClockConstantState cs) {
            super(cs.mBitmap, cs.mIconColor);
            super(cs.mBitmapInfo);
            mBoundsOffset = cs.mBoundsOffset;
            mAnimInfo = cs.mAnimInfo;

@@ -447,7 +447,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap

        @Override
        public FastBitmapConstantState newConstantState() {
            return new ClockConstantState(mBitmap, mIconColor, mThemedFgColor, mBoundsOffset,
            return new ClockConstantState(mBitmapInfo, mThemedFgColor, mBoundsOffset,
                    mAnimInfo, mBG, mBgPaint.getColorFilter());
        }

@@ -459,9 +459,9 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap
            private final ColorFilter mBgFilter;
            private final int mThemedFgColor;

            ClockConstantState(Bitmap bitmap, int color, int themedFgColor,
            ClockConstantState(BitmapInfo info, int themedFgColor,
                    float boundsOffset, AnimationInfo animInfo, Bitmap bg, ColorFilter bgFilter) {
                super(bitmap, color);
                super(info);
                mBoundsOffset = boundsOffset;
                mAnimInfo = animInfo;
                mBG = bg;
+25 −18
Original line number Diff line number Diff line
@@ -65,8 +65,7 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    private static boolean sFlagHoverEnabled = false;

    protected final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    protected final Bitmap mBitmap;
    protected final int mIconColor;
    public final BitmapInfo mBitmapInfo;

    @Nullable private ColorFilter mColorFilter;

@@ -99,18 +98,24 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {

    private boolean mHoverScaleEnabledForDisplay = true;

    protected FastBitmapDrawable(Bitmap b, int iconColor) {
        this(BitmapInfo.of(b, iconColor));
    }

    public FastBitmapDrawable(Bitmap b) {
        this(b, Color.TRANSPARENT);
        this(BitmapInfo.fromBitmap(b));
    }

    public FastBitmapDrawable(BitmapInfo info) {
        this(info.icon, info.color);
        mBitmapInfo = info;
        setFilterBitmap(true);
    }

    protected FastBitmapDrawable(Bitmap b, int iconColor) {
        mBitmap = b;
        mIconColor = iconColor;
        setFilterBitmap(true);
    /**
     * Returns true if the drawable points to the same bitmap icon object
     */
    public boolean isSameInfo(BitmapInfo info) {
        return mBitmapInfo == info;
    }

    @Override
@@ -145,7 +150,7 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    }

    protected void drawInternal(Canvas canvas, Rect bounds) {
        canvas.drawBitmap(mBitmap, null, bounds, mPaint);
        canvas.drawBitmap(mBitmapInfo.icon, null, bounds, mPaint);
    }

    /**
@@ -153,7 +158,7 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
     */
    public int getIconColor() {
        int whiteScrim = setColorAlphaBound(Color.WHITE, WHITE_SCRIM_ALPHA);
        return ColorUtils.compositeColors(whiteScrim, mIconColor);
        return ColorUtils.compositeColors(whiteScrim, mBitmapInfo.color);
    }

    /**
@@ -220,12 +225,12 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {

    @Override
    public int getIntrinsicWidth() {
        return mBitmap.getWidth();
        return mBitmapInfo.icon.getWidth();
    }

    @Override
    public int getIntrinsicHeight() {
        return mBitmap.getHeight();
        return mBitmapInfo.icon.getHeight();
    }

    @Override
@@ -333,7 +338,7 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    }

    protected FastBitmapConstantState newConstantState() {
        return new FastBitmapConstantState(mBitmap, mIconColor);
        return new FastBitmapConstantState(mBitmapInfo);
    }

    @Override
@@ -423,8 +428,7 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    }

    public static class FastBitmapConstantState extends ConstantState {
        protected final Bitmap mBitmap;
        protected final int mIconColor;
        protected final BitmapInfo mBitmapInfo;

        // These are initialized later so that subclasses don't need to
        // pass everything in constructor
@@ -434,12 +438,15 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
        @DrawableCreationFlags int mCreationFlags = 0;

        public FastBitmapConstantState(Bitmap bitmap, int color) {
            mBitmap = bitmap;
            mIconColor = color;
            this(BitmapInfo.of(bitmap, color));
        }

        public FastBitmapConstantState(BitmapInfo info) {
            mBitmapInfo = info;
        }

        protected FastBitmapDrawable createDrawable() {
            return new FastBitmapDrawable(mBitmap, mIconColor);
            return new FastBitmapDrawable(mBitmapInfo);
        }

        @Override
+5 −6
Original line number Diff line number Diff line
@@ -28,8 +28,7 @@ import com.android.launcher3.icons.R

/** Class to handle monochrome themed app icons */
class ThemedIconDrawable(constantState: ThemedConstantState) :
    FastBitmapDrawable(constantState.getBitmap(), constantState.colorFg) {
    val bitmapInfo = constantState.bitmapInfo
    FastBitmapDrawable(constantState.getBitmapInfo()) {
    private val colorFg = constantState.colorFg
    private val colorBg = constantState.colorBg

@@ -66,21 +65,21 @@ class ThemedIconDrawable(constantState: ThemedConstantState) :
    override fun isThemed() = true

    override fun newConstantState() =
        ThemedConstantState(bitmapInfo, monoIcon, bgBitmap, colorBg, colorFg)
        ThemedConstantState(mBitmapInfo, monoIcon, bgBitmap, colorBg, colorFg)

    override fun getIconColor() = colorFg

    class ThemedConstantState(
        val bitmapInfo: BitmapInfo,
        bitmapInfo: BitmapInfo,
        val mono: Bitmap,
        val whiteShadowLayer: Bitmap,
        val colorBg: Int,
        val colorFg: Int,
    ) : FastBitmapConstantState(bitmapInfo.icon, bitmapInfo.color) {
    ) : FastBitmapConstantState(bitmapInfo) {

        public override fun createDrawable() = ThemedIconDrawable(this)

        fun getBitmap(): Bitmap = mBitmap
        fun getBitmapInfo(): BitmapInfo = mBitmapInfo
    }

    companion object {