am 58248d04: Merge "Update drawables to fix CTS test failures" into lmp-preview-dev

* commit '58248d049e8b17dd60e4e94e784c09b00e0a7e9d':
  Update drawables to fix CTS test failures
This commit is contained in:
Alan Viverette
2014-06-06 20:57:37 +00:00
committed by Android Git Automerger
3 changed files with 20 additions and 1 deletions

View File

@@ -706,9 +706,23 @@ 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.
*/
@@ -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 {

View File

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

View File

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