summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2014-09-10 14:51:05 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-10 14:51:05 +0000
commit13a081975414ab3559bec7ed2fb934d9fae63a2b (patch)
tree6517a5cf66adf446f97f86bac94124656e768e71 /graphics/java
parent5a88f7f343a37c406b92dc68ca0feb346d043d8e (diff)
parent5a3be5f99d853a0ee2a69edc0603550640011aca (diff)
downloadframeworks_base-13a081975414ab3559bec7ed2fb934d9fae63a2b.zip
frameworks_base-13a081975414ab3559bec7ed2fb934d9fae63a2b.tar.gz
frameworks_base-13a081975414ab3559bec7ed2fb934d9fae63a2b.tar.bz2
am 568b3fe9: am 1fac2ba1: Merge "Use intrinsic size for path animation in AnimatedVectorDrawable" into lmp-dev
* commit '568b3fe99baa8e5eba1acad6a522706f16803a40': Use intrinsic size for path animation in AnimatedVectorDrawable
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java10
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java23
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 {