diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index 0f305f3cff3d2..dcca431ea7544 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -65,19 +65,36 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; /** - * This class uses {@link android.animation.ObjectAnimator} and - * {@link android.animation.AnimatorSet} to animate the properties of a - * {@link android.graphics.drawable.VectorDrawable} to create an animated drawable. + * This class animates properties of a {@link android.graphics.drawable.VectorDrawable} with + * animations defined using {@link android.animation.ObjectAnimator} or + * {@link android.animation.AnimatorSet}. *
- * AnimatedVectorDrawable are normally defined as 3 separate XML files. + * Starting from API 25, AnimatedVectorDrawable runs on RenderThread (as opposed to on UI thread for + * earlier APIs). This means animations in AnimatedVectorDrawable can remain smooth even when there + * is heavy workload on the UI thread. Note: If the UI thread is unresponsive, RenderThread may + * continue animating until the UI thread is capable of pushing another frame. Therefore, it is not + * possible to precisely coordinate a RenderThread-enabled AnimatedVectorDrawable with UI thread + * animations. Additionally, + * {@link android.graphics.drawable.Animatable2.AnimationCallback#onAnimationEnd(Drawable)} will be + * called the frame after the AnimatedVectorDrawable finishes on the RenderThread. *
*- * First is the XML file for {@link android.graphics.drawable.VectorDrawable}. - * Note that we allow the animation to happen on the group's attributes and path's - * attributes, which requires they are uniquely named in this XML file. Groups - * and paths without animations do not need names. + * AnimatedVectorDrawable can be defined in either three separate XML files, + * or one XML. *
- *+ * Animations can be performed on both group and path attributes, which requires groups and paths to + * have unique names in the same VectorDrawable. Groups and paths without animations do not need to + * be named. + *
+ * Below is an example of a VectorDrawable defined in vectordrawable.xml. This VectorDrawable is + * referred to by its file name (not including file suffix) in the + * AnimatedVectorDrawable XML example. ** <vector xmlns:android="http://schemas.android.com/apk/res/android" * android:height="64dp" @@ -96,17 +113,20 @@ import java.util.ArrayList; * </group> * </vector> *
- * Second is the AnimatedVectorDrawable's XML file, which defines the target - * VectorDrawable, the target paths and groups to animate, the properties of the - * path and group to animate and the animations defined as the ObjectAnimators - * or AnimatorSets. + * An AnimatedVectorDrawable element has a VectorDrawable attribute, and one or more target + * element(s). The target elements can be the path or group to be animated. Each target element + * contains a name attribute that references a property (of a path or a group) to animate, and an + * animation attribute that points to an ObjectAnimator or an AnimatorSet. *
- ** <animated-vector xmlns:android="http://schemas.android.com/apk/res/android" - * android:drawable="@drawable/vectordrawable" > + * android:drawable="@drawable/vectordrawable" > * <target * android:name="rotationGroup" * android:animation="@anim/rotation" /> @@ -114,39 +134,43 @@ import java.util.ArrayList; * android:name="v" * android:animation="@anim/path_morph" /> * </animated-vector> - *
- * Last is the Animator XML file, which is the same as a normal ObjectAnimator - * or AnimatorSet. - * To complete this example, here are the 2 animator files used in avd.xml: - * rotation.xml and path_morph.xml. + * From the previous example of AnimatedVectorDrawable, two animations + * were used: rotation.xml and path_morph.xml. *
- ** <objectAnimator * android:duration="6000" * android:propertyName="rotation" * android:valueFrom="0" * android:valueTo="360" /> - *
* <set xmlns:android="http://schemas.android.com/apk/res/android"> * <objectAnimator * android:duration="3000" * android:propertyName="pathData" - * android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z" + * android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z" * android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z" * android:valueType="pathType"/> * </set> - *
- * Since AAPT tool is now supporting a new format which can bundle several related XML files into - * one, we can merge the previous example into one XML file, like this: + * Since the AAPT tool supports a new format that bundles several related XML files together, we can + * merge the XML files from the previous examples into one XML file: *
*
* <animated-vector xmlns:android="http://schemas.android.com/apk/res/android" >
@@ -185,7 +209,7 @@ import java.util.ArrayList;
* <objectAnimator
* android:duration="3000"
* android:propertyName="pathData"
- * android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
+ * android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
* android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z"
* android:valueType="pathType"/>
* </set>
@@ -286,6 +310,17 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
return super.getChangingConfigurations() | mAnimatedVectorState.getChangingConfigurations();
}
+ /**
+ * Draws the AnimatedVectorDrawable into the given canvas.
+ *
+ * Note: Calling this method with a software canvas when the
+ * AnimatedVectorDrawable is being animated on RenderThread (for API 25 and later) may yield
+ * outdated result, as the UI thread is not guaranteed to be in sync with RenderThread on
+ * VectorDrawable's property changes during RenderThread animations.
+ *
+ *
+ * @param canvas The canvas to draw into
+ */
@Override
public void draw(Canvas canvas) {
if (!canvas.isHardwareAccelerated() && mAnimatorSet instanceof VectorDrawableAnimatorRT) {
@@ -321,9 +356,9 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
}
/**
- * AnimatedVectorDrawable is running on render thread now. Therefore, if the root alpha is being
- * animated, then the root alpha value we get from this call could be out of sync with alpha
- * value used in the render thread. Otherwise, the root alpha should be always the same value.
+ * For API 25 and later, AnimatedVectorDrawable runs on RenderThread. Therefore, when the
+ * root alpha is being animated, this getter does not guarantee to return an up-to-date alpha
+ * value.
*
* @return the containing vector drawable's root alpha value.
*/
@@ -1495,7 +1530,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
} else {
addPendingAction(START_ANIMATION);
}
-
}
@Override