summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2014-06-06 19:37:16 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2014-06-06 19:37:16 +0000
commitf2dc2d145948d7dcec5a7c5c9cb7a839d5aa50b9 (patch)
tree4619bce0e1ac084facdbd255bab180e33573fa81
parent2987eefe094443252cf8a593d881d2025fcf8ae8 (diff)
parent06318a0869b9f214bc97cabf1d2b6854acb6431b (diff)
Merge "Update drawables to fix CTS test failures" into lmp-preview-dev
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java15
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java5
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java1
3 files changed, 20 insertions, 1 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index c95ac8238d72..ef6c0859f666 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -706,10 +706,24 @@ public class BitmapDrawable extends Drawable {
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.BitmapDrawable);
updateStateFromTypedArray(a);
+ verifyState(a);
a.recycle();
}
/**
+ * Ensures all required attributes are set.
+ *
+ * @throws XmlPullParserException if any required attributes are missing
+ */
+ private void verifyState(TypedArray a) throws XmlPullParserException {
+ final BitmapState state = mBitmapState;
+ if (state.mBitmap == null) {
+ throw new XmlPullParserException(a.getPositionDescription() +
+ ": <bitmap> requires a valid src attribute");
+ }
+ }
+
+ /**
* Updates the constant state from the values in the typed array.
*/
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
@@ -912,6 +926,7 @@ public class BitmapDrawable extends Drawable {
*/
private BitmapDrawable(BitmapState state, Resources res, Theme theme) {
if (theme != null && state.canApplyTheme()) {
+ // If we need to apply a theme, implicitly mutate.
mBitmapState = new BitmapState(state);
applyTheme(theme);
} else {
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 241b89e2d6b8..005b8efeba32 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -1662,9 +1662,12 @@ public class GradientDrawable extends Drawable {
* @param theme Theme to apply to the drawable
*/
private GradientDrawable(GradientState state, Theme theme) {
- mGradientState = new GradientState(state);
if (theme != null && state.canApplyTheme()) {
+ // If we need to apply a theme, implicitly mutate.
+ mGradientState = new GradientState(state);
applyTheme(theme);
+ } else {
+ mGradientState = state;
}
initializeWithState(state);
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 77ed29a825d3..fea68ee1a4db 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -659,6 +659,7 @@ public class NinePatchDrawable extends Drawable {
*/
private NinePatchDrawable(NinePatchState state, Resources res, Theme theme) {
if (theme != null && state.canApplyTheme()) {
+ // If we need to apply a theme, implicitly mutate.
mNinePatchState = new NinePatchState(state);
applyTheme(theme);
} else {