am 11c4009c: Merge "Fix NPE in NinePatchDrawable, propagate theme in StateListDrawable" into lmp-dev

* commit '11c4009c0463446e19fb7591206619617544aee0':
  Fix NPE in NinePatchDrawable, propagate theme in StateListDrawable
This commit is contained in:
Alan Viverette
2014-08-12 21:16:42 +00:00
committed by Android Git Automerger
2 changed files with 22 additions and 23 deletions

View File

@@ -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;

View File

@@ -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));
R.styleable.StateListDrawable_exitFadeDuration, 0));
setDither(a.getBoolean(com.android.internal.R.styleable.StateListDrawable_dither,
DEFAULT_DITHER));
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) {
}