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

Commit 8e5e11b9 authored by Alan Viverette's avatar Alan Viverette
Browse files

Handle configuration changes in drawable attributes

Adds themeable attribute support to InsetDrawable, adds support
for attribute configuration changes to all themable drawables.

BUG: 16045735
Change-Id: I3dc62d28801760ac69d303be81b6c78bb9bb5aca
parent 0e73e532
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8972,6 +8972,7 @@ package android.content.res {
  public class TypedArray {
    method public boolean getBoolean(int, boolean);
    method public int getChangingConfigurations();
    method public int getColor(int, int);
    method public android.content.res.ColorStateList getColorStateList(int);
    method public float getDimension(int, float);
+24 −0
Original line number Diff line number Diff line
@@ -927,6 +927,30 @@ public class TypedArray {
        return attrs;
    }

    /**
     * Return a mask of the configuration parameters for which the values in
     * this typed array may change.
     *
     * @return Returns a mask of the changing configuration parameters, as
     *         defined by {@link android.content.pm.ActivityInfo}.
     * @see android.content.pm.ActivityInfo
     */
    public int getChangingConfigurations() {
        int changingConfig = 0;

        final int[] data = mData;
        final int N = length();
        for (int i = 0; i < N; i++) {
            final int index = i * AssetManager.STYLE_NUM_ENTRIES;
            final int type = data[index + AssetManager.STYLE_TYPE];
            if (type == TypedValue.TYPE_NULL) {
                continue;
            }
            changingConfig |= data[index + AssetManager.STYLE_CHANGING_CONFIGURATIONS];
        }
        return changingConfig;
    }

    private boolean getValueAt(int index, TypedValue outValue) {
        final int[] data = mData;
        final int type = data[index+AssetManager.STYLE_TYPE];
+4 −3
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.ColorDrawable.ColorState;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Shader;
@@ -712,9 +711,11 @@ public class BitmapDrawable extends Drawable {
        final Resources r = a.getResources();
        final BitmapState state = mBitmapState;

        // Account for any configuration changes.
        state.mChangingConfigurations |= a.getChangingConfigurations();

        // Extract the theme attributes, if any.
        final int[] themeAttrs = a.extractThemeAttrs();
        state.mThemeAttrs = themeAttrs;
        state.mThemeAttrs = a.extractThemeAttrs();

        final int srcResId = a.getResourceId(R.styleable.BitmapDrawable_src, 0);
        if (srcResId != 0) {
+14 −33
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ public class ColorDrawable extends Drawable {

    @ViewDebug.ExportedProperty(deepExport = true, prefix = "state_")
    private ColorState mColorState;
    private ColorStateList mTint;
    private PorterDuffColorFilter mTintFilter;

    private boolean mMutated;
@@ -215,25 +214,24 @@ public class ColorDrawable extends Drawable {
        super.inflate(r, parser, attrs, theme);

        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ColorDrawable);
        inflateStateFromTypedArray(a);
        updateStateFromTypedArray(a);
        a.recycle();
    }

    /**
     * Initializes the constant state from the values in the typed array.
     * Updates the constant state from the values in the typed array.
     */
    private void inflateStateFromTypedArray(TypedArray a) {
    private void updateStateFromTypedArray(TypedArray a) {
        final ColorState state = mColorState;

        // Account for any configuration changes.
        state.mChangingConfigurations |= a.getChangingConfigurations();

        // Extract the theme attributes, if any.
        final int[] themeAttrs = a.extractThemeAttrs();
        state.mThemeAttrs = themeAttrs;
        state.mThemeAttrs = a.extractThemeAttrs();

        if (themeAttrs == null || themeAttrs[R.styleable.ColorDrawable_color] == 0) {
            final int color = a.getColor(R.styleable.ColorDrawable_color, 0);
            state.mBaseColor = color;
            state.mUseColor = color;
        }
        state.mBaseColor = a.getColor(R.styleable.ColorDrawable_color, state.mBaseColor);
        state.mUseColor = state.mBaseColor;
    }

    @Override
@@ -241,34 +239,17 @@ public class ColorDrawable extends Drawable {
        super.applyTheme(t);

        final ColorState state = mColorState;
        if (state == null) {
            throw new RuntimeException("Can't apply theme to <color> with no constant state");
        if (state == null || state.mThemeAttrs == null) {
            return;
        }

        final int[] themeAttrs = state.mThemeAttrs;
        if (themeAttrs != null) {
            final TypedArray a = t.resolveAttributes(themeAttrs, R.styleable.ColorDrawable);
        final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.ColorDrawable);
        updateStateFromTypedArray(a);
        a.recycle();
    }
    }

    /**
     * Updates the constant state from the values in the typed array.
     */
    private void updateStateFromTypedArray(TypedArray a) {
        final ColorState state = mColorState;

        if (a.hasValue(R.styleable.ColorDrawable_color)) {
            final int color = a.getColor(R.styleable.ColorDrawable_color, 0);
            state.mBaseColor = color;
            state.mUseColor = color;
        }
    }

    @Override
    public ConstantState getConstantState() {
        mColorState.mChangingConfigurations = getChangingConfigurations();
        return mColorState;
    }

+4 −4
Original line number Diff line number Diff line
@@ -238,9 +238,9 @@ public abstract class Drawable {
     * may change, requiring that it be re-created.
     *
     * @param configs A mask of the changing configuration parameters, as
     * defined by {@link android.content.res.Configuration}.
     * defined by {@link android.content.pm.ActivityInfo}.
     *
     * @see android.content.res.Configuration
     * @see android.content.pm.ActivityInfo
     */
    public void setChangingConfigurations(int configs) {
        mChangingConfigurations = configs;
@@ -255,9 +255,9 @@ public abstract class Drawable {
     * drawables they hold.
     *
     * @return Returns a mask of the changing configuration parameters, as
     * defined by {@link android.content.res.Configuration}.
     * defined by {@link android.content.pm.ActivityInfo}.
     *
     * @see android.content.res.Configuration
     * @see android.content.pm.ActivityInfo
     */
    public int getChangingConfigurations() {
        return mChangingConfigurations;
Loading