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

Commit 931435cf authored by Ember Rose's avatar Ember Rose
Browse files

Implement #mutate for ColorStateListDrawable

ColorStateListDrawable did not implement #mutate correctly. This adds an
implementation for it.

Change-Id: I823b2096194ebc4e3424283ad5bad9d0f8df10df
Fixes: 113099852
Test: atest ColorStateListDrawable
parent 8f7a8000
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.MathUtils;
public class ColorStateListDrawable extends Drawable implements Drawable.Callback {
    private ColorDrawable mColorDrawable;
    private ColorStateListDrawableState mState;
    private boolean mMutated = false;

    public ColorStateListDrawable() {
        mState = new ColorStateListDrawableState();
@@ -139,7 +140,7 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac
            int color = mState.mColor.getColorForState(state, mState.mColor.getDefaultColor());

            if (mState.mAlpha != -1) {
                color = color & 0xFFFFFF | MathUtils.constrain(mState.mAlpha, 0, 255) << 24;
                color = (color & 0xFFFFFF) | MathUtils.constrain(mState.mAlpha, 0, 255) << 24;
            }

            if (color != mColorDrawable.getColor()) {
@@ -183,6 +184,8 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac

    @Override
    public ConstantState getConstantState() {
        mState.mChangingConfigurations = mState.mChangingConfigurations
                | (getChangingConfigurations() & ~mState.getChangingConfigurations());
        return mState;
    }

@@ -200,6 +203,29 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac
        }
    }

    @Override
    public int getChangingConfigurations() {
        return super.getChangingConfigurations() | mState.getChangingConfigurations();
    }

    @Override
    public Drawable mutate() {
        if (!mMutated && super.mutate() == this) {
            mState = new ColorStateListDrawableState(mState);
            mMutated = true;
        }
        return this;
    }

    /**
     * @hide
     */
    @Override
    public void clearMutated() {
        super.clearMutated();
        mMutated = false;
    }

    /**
     * Replace this Drawable's ColorStateList. It is not copied, so changes will propagate on the
     * next call to {@link #setState(int[])}.
@@ -221,6 +247,13 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac
        ColorStateListDrawableState() {
        }

        ColorStateListDrawableState(ColorStateListDrawableState state) {
            mColor = state.mColor;
            mTint = state.mTint;
            mAlpha = state.mAlpha;
            mTintMode = state.mTintMode;
            mChangingConfigurations = state.mChangingConfigurations;
        }

        @Override
        public Drawable newDrawable() {