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

Commit 1725f941 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE in NinePatchDrawable, propagate theme in StateListDrawable" into lmp-dev

parents cd542b8a ad55abdc
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics.drawable;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
@@ -609,16 +610,17 @@ public class NinePatchDrawable extends Drawable {
            // Empty constructor.
        }

        NinePatchState(NinePatch ninePatch, Rect padding) {
        NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding) {
            this(ninePatch, padding, null, DEFAULT_DITHER, false);
        }

        NinePatchState(NinePatch ninePatch, Rect padding, Rect opticalInsets) {
        NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding,
                @Nullable Rect opticalInsets) {
            this(ninePatch, padding, opticalInsets, DEFAULT_DITHER, false);
        }

        NinePatchState(NinePatch ninePatch, Rect padding, Rect opticalInsets, boolean dither,
                boolean autoMirror) {
        NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding,
                @Nullable Rect opticalInsets, boolean dither, boolean autoMirror) {
            mNinePatch = ninePatch;
            mPadding = padding;
            mOpticalInsets = Insets.of(opticalInsets);
@@ -626,7 +628,7 @@ public class NinePatchDrawable extends Drawable {
            mAutoMirrored = autoMirror;

            // Sanity check for valid padding when we have optical insets.
            if (!opticalInsets.isEmpty()) {
            if (opticalInsets != null && !opticalInsets.isEmpty()) {
                if (mPadding == null) {
                    mPadding = new Rect();
                }
@@ -643,7 +645,7 @@ public class NinePatchDrawable extends Drawable {

        // Copy constructor

        NinePatchState(NinePatchState state) {
        NinePatchState(@NonNull NinePatchState state) {
            // We don't deep-copy any fields because they are all immutable.
            mNinePatch = state.mNinePatch;
            mTint = state.mTint;
+14 −17
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.graphics.drawable;

import com.android.internal.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -116,32 +118,27 @@ public class StateListDrawable extends DrawableContainer {
    public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
            throws XmlPullParserException, IOException {

        TypedArray a = r.obtainAttributes(attrs,
                com.android.internal.R.styleable.StateListDrawable);
        final TypedArray a = r.obtainAttributes(attrs, R.styleable.StateListDrawable);

        super.inflateWithAttributes(r, parser, a,
                com.android.internal.R.styleable.StateListDrawable_visible);
                R.styleable.StateListDrawable_visible);

        mStateListState.setVariablePadding(a.getBoolean(
                com.android.internal.R.styleable.StateListDrawable_variablePadding, false));
                R.styleable.StateListDrawable_variablePadding, false));
        mStateListState.setConstantSize(a.getBoolean(
                com.android.internal.R.styleable.StateListDrawable_constantSize, false));
                R.styleable.StateListDrawable_constantSize, false));
        mStateListState.setEnterFadeDuration(a.getInt(
                com.android.internal.R.styleable.StateListDrawable_enterFadeDuration, 0));
                R.styleable.StateListDrawable_enterFadeDuration, 0));
        mStateListState.setExitFadeDuration(a.getInt(
                com.android.internal.R.styleable.StateListDrawable_exitFadeDuration, 0));

        setDither(a.getBoolean(com.android.internal.R.styleable.StateListDrawable_dither,
                               DEFAULT_DITHER));
                R.styleable.StateListDrawable_exitFadeDuration, 0));

        setAutoMirrored(a.getBoolean(
                com.android.internal.R.styleable.StateListDrawable_autoMirrored, false));
        setDither(a.getBoolean(R.styleable.StateListDrawable_dither, DEFAULT_DITHER));
        setAutoMirrored(a.getBoolean(R.styleable.StateListDrawable_autoMirrored, false));

        a.recycle();

        int type;

        final int innerDepth = parser.getDepth() + 1;
        int type;
        int depth;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && ((depth = parser.getDepth()) >= innerDepth
@@ -163,7 +160,7 @@ public class StateListDrawable extends DrawableContainer {
            for (i = 0; i < numAttrs; i++) {
                final int stateResId = attrs.getAttributeNameResource(i);
                if (stateResId == 0) break;
                if (stateResId == com.android.internal.R.attr.drawable) {
                if (stateResId == R.attr.drawable) {
                    drawableRes = attrs.getAttributeResourceValue(i, 0);
                } else {
                    states[j++] = attrs.getAttributeBooleanValue(i, false)
@@ -173,9 +170,9 @@ public class StateListDrawable extends DrawableContainer {
            }
            states = StateSet.trimStateSet(states, j);

            Drawable dr;
            final Drawable dr;
            if (drawableRes != 0) {
                dr = r.getDrawable(drawableRes);
                dr = r.getDrawable(drawableRes, theme);
            } else {
                while ((type = parser.next()) == XmlPullParser.TEXT) {
                }