diff options
author | Alan Viverette <alanv@google.com> | 2014-08-15 19:12:28 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-08-15 19:12:28 -0700 |
commit | 0bece71ee24f75967b86de47cae07e6fc04b4b36 (patch) | |
tree | 06d8b72e3c7416b447c98c4e969a3a6dd9c9fe68 /graphics/java/android | |
parent | 4473ec5a5b39248377ce1596cdae83715b513413 (diff) | |
download | frameworks_base-0bece71ee24f75967b86de47cae07e6fc04b4b36.zip frameworks_base-0bece71ee24f75967b86de47cae07e6fc04b4b36.tar.gz frameworks_base-0bece71ee24f75967b86de47cae07e6fc04b4b36.tar.bz2 |
Throw exception when inset drawable is missing drawable attribute
BUG: 17068252
Change-Id: I3f5757966c1bb723311a2e2c41d419ed41369061
Diffstat (limited to 'graphics/java/android')
-rw-r--r-- | graphics/java/android/graphics/drawable/InsetDrawable.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index 588e776..dd0f06f 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -26,10 +26,13 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.Resources.Theme; -import android.graphics.*; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Insets; +import android.graphics.Outline; import android.graphics.PorterDuff.Mode; +import android.graphics.Rect; import android.util.AttributeSet; -import android.util.Log; import java.io.IOException; @@ -50,8 +53,6 @@ import java.io.IOException; * @attr ref android.R.styleable#InsetDrawable_insetBottom */ public class InsetDrawable extends Drawable implements Drawable.Callback { - private static final String LOG_TAG = "InsetDrawable"; - private final Rect mTmpRect = new Rect(); private InsetState mInsetState; @@ -86,7 +87,6 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { final TypedArray a = r.obtainAttributes(attrs, R.styleable.InsetDrawable); super.inflateWithAttributes(r, parser, a, R.styleable.InsetDrawable_visible); updateStateFromTypedArray(a); - a.recycle(); // Load inner XML elements. if (mInsetState.mDrawable == null) { @@ -104,9 +104,17 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { dr.setCallback(this); } - // Verify state. - if (mInsetState.mDrawable == null) { - Log.w(LOG_TAG, "No drawable specified for <inset>"); + verifyRequiredAttributes(a); + a.recycle(); + } + + private void verifyRequiredAttributes(TypedArray a) throws XmlPullParserException { + // If we're not waiting on a theme, verify required attributes. + if (mInsetState.mDrawable == null && (mInsetState.mThemeAttrs == null + || mInsetState.mThemeAttrs[R.styleable.InsetDrawable_drawable] == 0)) { + throw new XmlPullParserException(a.getPositionDescription() + + ": <inset> tag requires a 'drawable' attribute or " + + "child tag defining a drawable"); } } @@ -167,6 +175,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.InsetDrawable); try { updateStateFromTypedArray(a); + verifyRequiredAttributes(a); } catch (XmlPullParserException e) { throw new RuntimeException(e); } finally { @@ -224,12 +233,8 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { padding.top += mInsetState.mInsetTop; padding.bottom += mInsetState.mInsetBottom; - if (pad || (mInsetState.mInsetLeft | mInsetState.mInsetRight | - mInsetState.mInsetTop | mInsetState.mInsetBottom) != 0) { - return true; - } else { - return false; - } + return pad || (mInsetState.mInsetLeft | mInsetState.mInsetRight | + mInsetState.mInsetTop | mInsetState.mInsetBottom) != 0; } /** @hide */ |