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

Commit d74377f3 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing drawable cloning does not preserve badge

Bug: 209503720
Test: Manual
Change-Id: Iacfc5f2fdbdeb4d76a639b3e187b1ef7854f0d5b
parent 3798f613
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -419,24 +419,22 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap
        }

        @Override
        public ConstantState getConstantState() {
            return new ClockConstantState(mInfo, isDisabled());
        public FastBitmapConstantState newConstantState() {
            return new ClockConstantState(mInfo);
        }

        private static class ClockConstantState extends FastBitmapConstantState {

            private final ClockBitmapInfo mInfo;

            ClockConstantState(ClockBitmapInfo info, boolean isDisabled) {
                super(info.icon, info.color, isDisabled);
            ClockConstantState(ClockBitmapInfo info) {
                super(info.icon, info.color);
                mInfo = info;
            }

            @Override
            public FastBitmapDrawable newDrawable() {
                ClockIconDrawable drawable = new ClockIconDrawable(mInfo);
                drawable.setIsDisabled(mIsDisabled);
                return drawable;
            public FastBitmapDrawable createDrawable() {
                return new ClockIconDrawable(mInfo);
            }
        }
    }
+28 −12
Original line number Diff line number Diff line
@@ -87,14 +87,9 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    }

    protected FastBitmapDrawable(Bitmap b, int iconColor) {
        this(b, iconColor, false);
    }

    protected FastBitmapDrawable(Bitmap b, int iconColor, boolean isDisabled) {
        mBitmap = b;
        mIconColor = iconColor;
        setFilterBitmap(true);
        setIsDisabled(isDisabled);
    }

    @Override
@@ -290,9 +285,18 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
        invalidateSelf();
    }

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

    @Override
    public ConstantState getConstantState() {
        return new FastBitmapConstantState(mBitmap, mIconColor, mIsDisabled);
    public final ConstantState getConstantState() {
        FastBitmapConstantState cs = newConstantState();
        cs.mIsDisabled = mIsDisabled;
        if (mBadge != null) {
            cs.mBadgeConstantState = mBadge.getConstantState();
        }
        return cs;
    }

    public static ColorFilter getDisabledColorFilter() {
@@ -349,17 +353,29 @@ public class FastBitmapDrawable extends Drawable implements Drawable.Callback {
    protected static class FastBitmapConstantState extends ConstantState {
        protected final Bitmap mBitmap;
        protected final int mIconColor;
        protected final boolean mIsDisabled;

        public FastBitmapConstantState(Bitmap bitmap, int color, boolean isDisabled) {
        // These are initialized later so that subclasses don't need to
        // pass everything in constructor
        protected boolean mIsDisabled;
        private ConstantState mBadgeConstantState;

        public FastBitmapConstantState(Bitmap bitmap, int color) {
            mBitmap = bitmap;
            mIconColor = color;
            mIsDisabled = isDisabled;
        }

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

        @Override
        public FastBitmapDrawable newDrawable() {
            return new FastBitmapDrawable(mBitmap, mIconColor, mIsDisabled);
        public final FastBitmapDrawable newDrawable() {
            FastBitmapDrawable drawable = createDrawable();
            drawable.setIsDisabled(mIsDisabled);
            if (mBadgeConstantState != null) {
                drawable.setBadge(mBadgeConstantState.newDrawable());
            }
            return drawable;
        }

        @Override
+7 −7
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class ThemedIconDrawable extends FastBitmapDrawable {
    private final AdaptiveIconDrawable mBgWrapper;

    protected ThemedIconDrawable(ThemedConstantState constantState) {
        super(constantState.mBitmap, constantState.colorFg, constantState.mIsDisabled);
        super(constantState.mBitmap, constantState.colorFg);
        bitmapInfo = constantState.bitmapInfo;
        colorBg = constantState.colorBg;
        colorFg = constantState.colorFg;
@@ -95,8 +95,8 @@ public class ThemedIconDrawable extends FastBitmapDrawable {
    }

    @Override
    public ConstantState getConstantState() {
        return new ThemedConstantState(bitmapInfo, colorBg, colorFg, mIsDisabled);
    public FastBitmapConstantState newConstantState() {
        return new ThemedConstantState(bitmapInfo, colorBg, colorFg);
    }

    static class ThemedConstantState extends FastBitmapConstantState {
@@ -105,15 +105,15 @@ public class ThemedIconDrawable extends FastBitmapDrawable {
        final int colorFg, colorBg;

        public ThemedConstantState(ThemedBitmapInfo bitmapInfo,
                int colorBg, int colorFg, boolean isDisabled) {
            super(bitmapInfo.icon, bitmapInfo.color, isDisabled);
                int colorBg, int colorFg) {
            super(bitmapInfo.icon, bitmapInfo.color);
            this.bitmapInfo = bitmapInfo;
            this.colorBg = colorBg;
            this.colorFg = colorFg;
        }

        @Override
        public FastBitmapDrawable newDrawable() {
        public FastBitmapDrawable createDrawable() {
            return new ThemedIconDrawable(this);
        }
    }
@@ -136,7 +136,7 @@ public class ThemedIconDrawable extends FastBitmapDrawable {
            if ((creationFlags & FLAG_THEMED) != 0) {
                int[] colors = getColors(context);
                FastBitmapDrawable drawable =
                        new ThemedConstantState(this, colors[0], colors[1], false).newDrawable();
                        new ThemedConstantState(this, colors[0], colors[1]).newDrawable();
                applyFlags(context, drawable, creationFlags);
                return drawable;
            }