diff options
author | Alan Viverette <alanv@google.com> | 2014-06-20 14:45:11 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-06-20 14:45:11 -0700 |
commit | 9cd14fc710cf81cc6d1c47d599abe349d3aa87dc (patch) | |
tree | f2943d2af65b3fed26c0ee32ac445d96782eb863 /graphics/java | |
parent | a427fcf2cb6cc49e4f137e2853e3b6f51af940c5 (diff) | |
download | frameworks_base-9cd14fc710cf81cc6d1c47d599abe349d3aa87dc.zip frameworks_base-9cd14fc710cf81cc6d1c47d599abe349d3aa87dc.tar.gz frameworks_base-9cd14fc710cf81cc6d1c47d599abe349d3aa87dc.tar.bz2 |
Add support for tint attribute in VectorDrawable
Fixes NPE from previous change. Also fixes docs reference in TypedArray.
BUG: 15375203
Change-Id: Icf3b5759780276b0875a4fb70b29522ab7c8cb90
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/drawable/VectorDrawable.java | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index b4d1fdc..60177af8f 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -286,13 +286,6 @@ public class VectorDrawable extends Drawable { } @Override - public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) - throws XmlPullParserException, IOException { - final VPathRenderer p = inflateInternal(res, parser, attrs, theme); - setPathRenderer(p); - } - - @Override public boolean canApplyTheme() { return super.canApplyTheme() || mVectorState != null && mVectorState.canApplyTheme(); } @@ -335,13 +328,44 @@ public class VectorDrawable extends Drawable { return color; } - private VPathRenderer inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, - Theme theme) throws XmlPullParserException, IOException { + + @Override + public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) + throws XmlPullParserException, IOException { + final TypedArray a = obtainAttributes(res, theme, attrs,R.styleable.VectorDrawable); + updateStateFromTypedArray(a); + a.recycle(); + + final VectorDrawableState state = mVectorState; + state.mVPathRenderer = inflateInternal(res, parser, attrs, theme); + + mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); + state.mVPathRenderer.setColorFilter(mTintFilter); + } + + private void updateStateFromTypedArray(TypedArray a) { + final VectorDrawableState state = mVectorState; + + // Extract the theme attributes, if any. + state.mThemeAttrs = a.extractThemeAttrs(); + + final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1); + if (tintMode != -1) { + state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN); + } + + final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint); + if (tint != null) { + state.mTint = tint; + } + } + + private VPathRenderer inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) + throws XmlPullParserException, IOException { final VPathRenderer pathRenderer = new VPathRenderer(); boolean noSizeTag = true; boolean noViewportTag = true; - boolean noGroupTag = true; boolean noPathTag = true; // Use a stack to help to build the group tree. @@ -377,7 +401,6 @@ public class VectorDrawable extends Drawable { if (newChildGroup.getGroupName() != null) { mVGTargetsMap.put(newChildGroup.getGroupName(), newChildGroup); } - noGroupTag = false; } } else if (eventType == XmlPullParser.END_TAG) { final String tagName = parser.getName(); @@ -435,11 +458,8 @@ public class VectorDrawable extends Drawable { } } - private void setPathRenderer(VPathRenderer pathRenderer) { - mVectorState.mVPathRenderer = pathRenderer; - } - private static class VectorDrawableState extends ConstantState { + int[] mThemeAttrs; int mChangingConfigurations; VPathRenderer mVPathRenderer; Rect mPadding; @@ -448,6 +468,7 @@ public class VectorDrawable extends Drawable { public VectorDrawableState(VectorDrawableState copy) { if (copy != null) { + mThemeAttrs = copy.mThemeAttrs; mChangingConfigurations = copy.mChangingConfigurations; // TODO: Make sure the constant state are handled correctly. mVPathRenderer = new VPathRenderer(copy.mVPathRenderer); |