Merge "Better handling of unresolved theme attributes" into lmp-dev

This commit is contained in:
Alan Viverette
2014-08-16 01:10:41 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 4 deletions

View File

@@ -715,7 +715,13 @@ public class Resources {
* @see #getDrawable(int, Theme)
*/
public Drawable getDrawable(int id) throws NotFoundException {
return getDrawable(id, null);
final Drawable d = getDrawable(id, null);
if (d.canApplyTheme()) {
Log.w(TAG, "Drawable " + getResourceName(id) + " has unresolved theme "
+ "attributes! Consider using Resources.getDrawable(int, Theme) or "
+ "Context.getDrawable(int).", new RuntimeException());
}
return d;
}
/**

View File

@@ -395,8 +395,12 @@ public class RippleDrawable extends LayerDrawable {
mState.mColor = color;
}
// If we're not waiting on a theme, verify required attributes.
if (state.mTouchThemeAttrs == null && mState.mColor == null) {
verifyRequiredAttributes(a);
}
private void verifyRequiredAttributes(TypedArray a) throws XmlPullParserException {
if (mState.mColor == null && (mState.mTouchThemeAttrs == null
|| mState.mTouchThemeAttrs[R.styleable.RippleDrawable_color] == 0)) {
throw new XmlPullParserException(a.getPositionDescription() +
": <ripple> requires a valid color attribute");
}
@@ -891,7 +895,7 @@ public class RippleDrawable extends LayerDrawable {
static class RippleState extends LayerState {
int[] mTouchThemeAttrs;
ColorStateList mColor = null;
ColorStateList mColor = ColorStateList.valueOf(Color.MAGENTA);
int mMaxRadius = RADIUS_AUTO;
public RippleState(RippleState orig, RippleDrawable owner, Resources res) {