diff options
author | George Mount <mount@google.com> | 2014-09-10 14:30:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-10 14:30:17 +0000 |
commit | b7d63aedf57e946c1a555e773d1e3591122544a7 (patch) | |
tree | c4629cc4a656f71381d083c7f18bba5a8eb5c374 /graphics | |
parent | cb0567f98cc6d13365a32c3adaa41078a8afc8d4 (diff) | |
parent | fd3c4744f265c5277e6e2641a18d5ec3dff19f6b (diff) | |
download | frameworks_base-b7d63aedf57e946c1a555e773d1e3591122544a7.zip frameworks_base-b7d63aedf57e946c1a555e773d1e3591122544a7.tar.gz frameworks_base-b7d63aedf57e946c1a555e773d1e3591122544a7.tar.bz2 |
Merge "Use intrinsic size for path animation in AnimatedVectorDrawable" into lmp-dev
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java | 10 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/VectorDrawable.java | 23 |
2 files changed, 30 insertions, 3 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index ba22550..e5e2f18 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -252,6 +252,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { throws XmlPullParserException, IOException { int eventType = parser.getEventType(); + float pathErrorScale = 1; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); @@ -261,9 +262,11 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { int drawableRes = a.getResourceId( R.styleable.AnimatedVectorDrawable_drawable, 0); if (drawableRes != 0) { - mAnimatedVectorState.mVectorDrawable = (VectorDrawable) res.getDrawable( + VectorDrawable vectorDrawable = (VectorDrawable) res.getDrawable( drawableRes, theme).mutate(); - mAnimatedVectorState.mVectorDrawable.setAllowCaching(false); + vectorDrawable.setAllowCaching(false); + pathErrorScale = vectorDrawable.getPixelSize(); + mAnimatedVectorState.mVectorDrawable = vectorDrawable; } a.recycle(); } else if (TARGET.equals(tagName)) { @@ -275,7 +278,8 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { int id = a.getResourceId( R.styleable.AnimatedVectorDrawableTarget_animation, 0); if (id != 0) { - Animator objectAnimator = AnimatorInflater.loadAnimator(res, theme, id); + Animator objectAnimator = AnimatorInflater.loadAnimator(res, theme, id, + pathErrorScale); setupAnimatorsForTarget(target, objectAnimator); } a.recycle(); diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 042da5b..a07ccc4 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -368,6 +368,29 @@ public class VectorDrawable extends Drawable { } } + /** + * The size of a pixel when scaled from the intrinsic dimension to the viewport dimension. + * This is used to calculate the path animation accuracy. + * + * @hide + */ + public float getPixelSize() { + if (mVectorState == null && mVectorState.mVPathRenderer == null || + mVectorState.mVPathRenderer.mBaseWidth == 0 || + mVectorState.mVPathRenderer.mBaseHeight == 0 || + mVectorState.mVPathRenderer.mViewportHeight == 0 || + mVectorState.mVPathRenderer.mViewportWidth == 0) { + return 1; // fall back to 1:1 pixel mapping. + } + float intrinsicWidth = mVectorState.mVPathRenderer.mBaseWidth; + float intrinsicHeight = mVectorState.mVPathRenderer.mBaseHeight; + float viewportWidth = mVectorState.mVPathRenderer.mViewportWidth; + float viewportHeight = mVectorState.mVPathRenderer.mViewportHeight; + float scaleX = viewportWidth / intrinsicWidth; + float scaleY = viewportHeight / intrinsicHeight; + return Math.min(scaleX, scaleY); + } + /** @hide */ public static VectorDrawable create(Resources resources, int rid) { try { |