diff options
author | Alan Viverette <alanv@google.com> | 2014-09-12 20:52:03 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-09-12 20:52:03 +0000 |
commit | 0cfc7717aa473262044c9edaddcfe7bc0caaa2ee (patch) | |
tree | 6b25203514bcbaa8f7c05320244a3710aae271f5 /graphics/java | |
parent | 7d6fc23fe712a6e03d0f35cc1967f7473f7dbc5a (diff) | |
parent | f97afd5334f644848897e5ab26c374b3dd524deb (diff) | |
download | frameworks_base-0cfc7717aa473262044c9edaddcfe7bc0caaa2ee.zip frameworks_base-0cfc7717aa473262044c9edaddcfe7bc0caaa2ee.tar.gz frameworks_base-0cfc7717aa473262044c9edaddcfe7bc0caaa2ee.tar.bz2 |
am 5dee9c9b: am 855fc8c7: Update icons to vectors, fix preload theming & vector tinting
* commit '5dee9c9b3e68e7567e765b7abb5ba3d3f05ce989':
Update icons to vectors, fix preload theming & vector tinting
Diffstat (limited to 'graphics/java')
7 files changed, 89 insertions, 31 deletions
diff --git a/graphics/java/android/graphics/PorterDuffColorFilter.java b/graphics/java/android/graphics/PorterDuffColorFilter.java index 705f5e6..ff768b7 100644 --- a/graphics/java/android/graphics/PorterDuffColorFilter.java +++ b/graphics/java/android/graphics/PorterDuffColorFilter.java @@ -99,5 +99,25 @@ public class PorterDuffColorFilter extends ColorFilter { native_instance = native_CreatePorterDuffFilter(mColor, mMode.nativeInt); } + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + final PorterDuffColorFilter other = (PorterDuffColorFilter) object; + if (mColor != other.mColor || mMode != other.mMode) { + return false; + } + return true; + } + + @Override + public int hashCode() { + return 31 * mMode.hashCode() + mColor; + } + private static native long native_CreatePorterDuffFilter(int srcColor, int porterDuffMode); } diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 715da7e..cf6be48 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -867,7 +867,7 @@ public class BitmapDrawable extends Drawable { int[] mThemeAttrs = null; Bitmap mBitmap = null; ColorStateList mTint = null; - Mode mTintMode = Mode.SRC_IN; + Mode mTintMode = DEFAULT_TINT_MODE; int mGravity = Gravity.FILL; float mBaseAlpha = 1.0f; Shader.TileMode mTileModeX = null; diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java index 9e42a89..33225ce 100644 --- a/graphics/java/android/graphics/drawable/ColorDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorDrawable.java @@ -261,8 +261,8 @@ public class ColorDrawable extends Drawable { @ViewDebug.ExportedProperty int mUseColor; // basecolor modulated by setAlpha() int mChangingConfigurations; - ColorStateList mTint; - Mode mTintMode; + ColorStateList mTint = null; + Mode mTintMode = DEFAULT_TINT_MODE; ColorState() { // Empty constructor. diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 3cb5210..43a9eaa 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -125,6 +125,8 @@ import java.util.Arrays; public abstract class Drawable { private static final Rect ZERO_BOUNDS_RECT = new Rect(); + static final PorterDuff.Mode DEFAULT_TINT_MODE = PorterDuff.Mode.SRC_IN; + private int[] mStateSet = StateSet.WILD_CARD; private int mLevel = 0; private int mChangingConfigurations = 0; diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index c185a9e..6c62ccf 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -585,7 +585,7 @@ public class NinePatchDrawable extends Drawable { int[] mThemeAttrs = null; NinePatch mNinePatch = null; ColorStateList mTint = null; - Mode mTintMode = Mode.SRC_IN; + Mode mTintMode = DEFAULT_TINT_MODE; Rect mPadding = null; Insets mOpticalInsets = Insets.NONE; float mBaseAlpha = 1.0f; diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 6f18635..bd69d76 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -515,8 +515,8 @@ public class ShapeDrawable extends Drawable { int mChangingConfigurations; Paint mPaint; Shape mShape; - ColorStateList mTint; - Mode mTintMode = Mode.SRC_IN; + ColorStateList mTint = null; + Mode mTintMode = DEFAULT_TINT_MODE; Rect mPadding; int mIntrinsicWidth; int mIntrinsicHeight; diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 4407a3c..62eb4c8 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -216,7 +216,7 @@ public class VectorDrawable extends Drawable { } mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); - mVectorState.mVPathRenderer.setColorFilter(mTintFilter); + state.setColorFilter(mTintFilter); } @Override @@ -302,7 +302,7 @@ public class VectorDrawable extends Drawable { colorFilter = mTintFilter; } - state.mVPathRenderer.setColorFilter(colorFilter); + state.setColorFilter(colorFilter); invalidateSelf(); } @@ -312,7 +312,7 @@ public class VectorDrawable extends Drawable { if (state.mTint != tint) { state.mTint = tint; mTintFilter = updateTintFilter(mTintFilter, tint, state.mTintMode); - state.mVPathRenderer.setColorFilter(mTintFilter); + state.setColorFilter(mTintFilter); invalidateSelf(); } } @@ -323,17 +323,24 @@ public class VectorDrawable extends Drawable { if (state.mTintMode != tintMode) { state.mTintMode = tintMode; mTintFilter = updateTintFilter(mTintFilter, state.mTint, tintMode); - state.mVPathRenderer.setColorFilter(mTintFilter); + state.setColorFilter(mTintFilter); invalidateSelf(); } } @Override + public boolean isStateful() { + return super.isStateful() || (mVectorState != null && mVectorState.mTint != null + && mVectorState.mTint.isStateful()); + } + + @Override protected boolean onStateChange(int[] stateSet) { final VectorDrawableState state = mVectorState; if (state.mTint != null && state.mTintMode != null) { mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); - mVectorState.mVPathRenderer.setColorFilter(mTintFilter); + state.setColorFilter(mTintFilter); + invalidateSelf(); return true; } return false; @@ -364,6 +371,21 @@ public class VectorDrawable extends Drawable { super.applyTheme(t); final VectorDrawableState state = mVectorState; + if (state != null && state.mThemeAttrs != null) { + final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.VectorDrawable); + try { + state.mCacheDirty = true; + updateStateFromTypedArray(a); + } catch (XmlPullParserException e) { + throw new RuntimeException(e); + } finally { + a.recycle(); + } + + mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); + state.setColorFilter(mTintFilter); + } + final VPathRenderer path = state.mVPathRenderer; if (path != null && path.canApplyTheme()) { path.applyTheme(t); @@ -433,7 +455,7 @@ public class VectorDrawable extends Drawable { final VPathRenderer pathRenderer = new VPathRenderer(); state.mVPathRenderer = pathRenderer; - TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.VectorDrawable); + final TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.VectorDrawable); updateStateFromTypedArray(a); a.recycle(); @@ -441,7 +463,7 @@ public class VectorDrawable extends Drawable { inflateInternal(res, parser, attrs, theme); mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); - state.mVPathRenderer.setColorFilter(mTintFilter); + state.setColorFilter(mTintFilter); } private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { @@ -613,8 +635,8 @@ public class VectorDrawable extends Drawable { int[] mThemeAttrs; int mChangingConfigurations; VPathRenderer mVPathRenderer; - ColorStateList mTint; - Mode mTintMode; + ColorStateList mTint = null; + Mode mTintMode = DEFAULT_TINT_MODE; boolean mAutoMirrored; Bitmap mCachedBitmap; @@ -671,6 +693,18 @@ public class VectorDrawable extends Drawable { mCacheDirty = false; } + @Override + public boolean canApplyTheme() { + return super.canApplyTheme() || mThemeAttrs != null + || (mVPathRenderer != null && mVPathRenderer.canApplyTheme()); + } + + public void setColorFilter(ColorFilter colorFilter) { + if (mVPathRenderer != null && mVPathRenderer.setColorFilter(colorFilter)) { + mCacheDirty = true; + } + } + public VectorDrawableState() { mVPathRenderer = new VPathRenderer(); } @@ -813,17 +847,21 @@ public class VectorDrawable extends Drawable { } } - public void setColorFilter(ColorFilter colorFilter) { - mColorFilter = colorFilter; + public boolean setColorFilter(ColorFilter colorFilter) { + if (colorFilter != mColorFilter + || (colorFilter != null && !colorFilter.equals(mColorFilter))) { + mColorFilter = colorFilter; - if (mFillPaint != null) { - mFillPaint.setColorFilter(colorFilter); - } + if (mFillPaint != null) { + mFillPaint.setColorFilter(colorFilter); + } - if (mStrokePaint != null) { - mStrokePaint.setColorFilter(colorFilter); + if (mStrokePaint != null) { + mStrokePaint.setColorFilter(colorFilter); + } + return true; } - + return false; } private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix, @@ -1011,10 +1049,6 @@ public class VectorDrawable extends Drawable { return mLocalMatrix; } - public boolean canApplyTheme() { - return mThemeAttrs != null; - } - public void inflate(Resources res, AttributeSet attrs, Theme theme) { final TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.VectorDrawableGroup); @@ -1045,13 +1079,16 @@ public class VectorDrawable extends Drawable { updateLocalMatrix(); } + public boolean canApplyTheme() { + return mThemeAttrs != null; + } + public void applyTheme(Theme t) { if (mThemeAttrs == null) { return; } - final TypedArray a = t.resolveAttributes(mThemeAttrs, - R.styleable.VectorDrawableGroup); + final TypedArray a = t.resolveAttributes(mThemeAttrs, R.styleable.VectorDrawableGroup); updateStateFromTypedArray(a); a.recycle(); } @@ -1375,8 +1412,7 @@ public class VectorDrawable extends Drawable { return; } - final TypedArray a = t.resolveAttributes(mThemeAttrs, - R.styleable.VectorDrawablePath); + final TypedArray a = t.resolveAttributes(mThemeAttrs, R.styleable.VectorDrawablePath); updateStateFromTypedArray(a); a.recycle(); } |