Skip to content

Commit 1725f94

Browse files
alanvAndroid (Google) Code Review
authored andcommitted
Merge "Fix NPE in NinePatchDrawable, propagate theme in StateListDrawable" into lmp-dev
2 parents cd542b8 + ad55abd commit 1725f94

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

graphics/java/android/graphics/drawable/NinePatchDrawable.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.graphics.drawable;
1818

1919
import android.annotation.NonNull;
20+
import android.annotation.Nullable;
2021
import android.content.res.ColorStateList;
2122
import android.content.res.Resources;
2223
import android.content.res.Resources.Theme;
@@ -609,24 +610,25 @@ final static class NinePatchState extends ConstantState {
609610
// Empty constructor.
610611
}
611612

612-
NinePatchState(NinePatch ninePatch, Rect padding) {
613+
NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding) {
613614
this(ninePatch, padding, null, DEFAULT_DITHER, false);
614615
}
615616

616-
NinePatchState(NinePatch ninePatch, Rect padding, Rect opticalInsets) {
617+
NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding,
618+
@Nullable Rect opticalInsets) {
617619
this(ninePatch, padding, opticalInsets, DEFAULT_DITHER, false);
618620
}
619621

620-
NinePatchState(NinePatch ninePatch, Rect padding, Rect opticalInsets, boolean dither,
621-
boolean autoMirror) {
622+
NinePatchState(@NonNull NinePatch ninePatch, @Nullable Rect padding,
623+
@Nullable Rect opticalInsets, boolean dither, boolean autoMirror) {
622624
mNinePatch = ninePatch;
623625
mPadding = padding;
624626
mOpticalInsets = Insets.of(opticalInsets);
625627
mDither = dither;
626628
mAutoMirrored = autoMirror;
627629

628630
// Sanity check for valid padding when we have optical insets.
629-
if (!opticalInsets.isEmpty()) {
631+
if (opticalInsets != null && !opticalInsets.isEmpty()) {
630632
if (mPadding == null) {
631633
mPadding = new Rect();
632634
}
@@ -643,7 +645,7 @@ final static class NinePatchState extends ConstantState {
643645

644646
// Copy constructor
645647

646-
NinePatchState(NinePatchState state) {
648+
NinePatchState(@NonNull NinePatchState state) {
647649
// We don't deep-copy any fields because they are all immutable.
648650
mNinePatch = state.mNinePatch;
649651
mTint = state.mTint;

graphics/java/android/graphics/drawable/StateListDrawable.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package android.graphics.drawable;
1818

19+
import com.android.internal.R;
20+
1921
import org.xmlpull.v1.XmlPullParser;
2022
import org.xmlpull.v1.XmlPullParserException;
2123

@@ -116,32 +118,27 @@ protected boolean onStateChange(int[] stateSet) {
116118
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
117119
throws XmlPullParserException, IOException {
118120

119-
TypedArray a = r.obtainAttributes(attrs,
120-
com.android.internal.R.styleable.StateListDrawable);
121+
final TypedArray a = r.obtainAttributes(attrs, R.styleable.StateListDrawable);
121122

122123
super.inflateWithAttributes(r, parser, a,
123-
com.android.internal.R.styleable.StateListDrawable_visible);
124+
R.styleable.StateListDrawable_visible);
124125

125126
mStateListState.setVariablePadding(a.getBoolean(
126-
com.android.internal.R.styleable.StateListDrawable_variablePadding, false));
127+
R.styleable.StateListDrawable_variablePadding, false));
127128
mStateListState.setConstantSize(a.getBoolean(
128-
com.android.internal.R.styleable.StateListDrawable_constantSize, false));
129+
R.styleable.StateListDrawable_constantSize, false));
129130
mStateListState.setEnterFadeDuration(a.getInt(
130-
com.android.internal.R.styleable.StateListDrawable_enterFadeDuration, 0));
131+
R.styleable.StateListDrawable_enterFadeDuration, 0));
131132
mStateListState.setExitFadeDuration(a.getInt(
132-
com.android.internal.R.styleable.StateListDrawable_exitFadeDuration, 0));
133-
134-
setDither(a.getBoolean(com.android.internal.R.styleable.StateListDrawable_dither,
135-
DEFAULT_DITHER));
133+
R.styleable.StateListDrawable_exitFadeDuration, 0));
136134

137-
setAutoMirrored(a.getBoolean(
138-
com.android.internal.R.styleable.StateListDrawable_autoMirrored, false));
135+
setDither(a.getBoolean(R.styleable.StateListDrawable_dither, DEFAULT_DITHER));
136+
setAutoMirrored(a.getBoolean(R.styleable.StateListDrawable_autoMirrored, false));
139137

140138
a.recycle();
141139

142-
int type;
143-
144140
final int innerDepth = parser.getDepth() + 1;
141+
int type;
145142
int depth;
146143
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
147144
&& ((depth = parser.getDepth()) >= innerDepth
@@ -163,7 +160,7 @@ public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme
163160
for (i = 0; i < numAttrs; i++) {
164161
final int stateResId = attrs.getAttributeNameResource(i);
165162
if (stateResId == 0) break;
166-
if (stateResId == com.android.internal.R.attr.drawable) {
163+
if (stateResId == R.attr.drawable) {
167164
drawableRes = attrs.getAttributeResourceValue(i, 0);
168165
} else {
169166
states[j++] = attrs.getAttributeBooleanValue(i, false)
@@ -173,9 +170,9 @@ public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme
173170
}
174171
states = StateSet.trimStateSet(states, j);
175172

176-
Drawable dr;
173+
final Drawable dr;
177174
if (drawableRes != 0) {
178-
dr = r.getDrawable(drawableRes);
175+
dr = r.getDrawable(drawableRes, theme);
179176
} else {
180177
while ((type = parser.next()) == XmlPullParser.TEXT) {
181178
}

0 commit comments

Comments
 (0)