Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2d0020d authored by ztenghui's avatar ztenghui Committed by Android (Google) Code Review
Browse files

Merge "Make AnimatedVectorDrawable public."

parents b72351da 7e7ea9da
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -11253,6 +11253,17 @@ package android.graphics.drawable {
    method public void addTransition(int, int, android.graphics.drawable.AnimationDrawable, boolean);
  }
  public class AnimatedVectorDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Animatable {
    ctor public AnimatedVectorDrawable();
    method public void draw(android.graphics.Canvas);
    method public int getOpacity();
    method public boolean isRunning();
    method public void setAlpha(int);
    method public void setColorFilter(android.graphics.ColorFilter);
    method public void start();
    method public void stop();
  }
  public class AnimationDrawable extends android.graphics.drawable.DrawableContainer implements android.graphics.drawable.Animatable java.lang.Runnable {
    ctor public AnimationDrawable();
    method public void addFrame(android.graphics.drawable.Drawable, int);
@@ -11652,8 +11663,6 @@ package android.graphics.drawable {
    method public int getOpacity();
    method public void setAlpha(int);
    method public void setColorFilter(android.graphics.ColorFilter);
    method public void setPadding(android.graphics.Rect);
    method public void setPadding(int, int, int, int);
  }
}
+84 −3
Original line number Diff line number Diff line
@@ -34,10 +34,91 @@ import java.io.IOException;
import java.util.ArrayList;

/**
 * AnimatedVectorDrawable can use ObjectAnimator and AnimatorSet to animate
 * the property of the VectorDrawable.
 * 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.
 * <p>
 * AnimatedVectorDrawable are normally defined as 3 separate XML files.
 * </p>
 * <p>
 * First is the XML file for {@link android.graphics.drawable.VectorDrawable}.
 * Note that we allow the animation 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.
 * </p>
 * <li>Here is a simple VectorDrawable in this vectordrawable.xml file.
 * <pre>
 * &lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; &gt;
 *     &lt;size
 *         android:height=&quot;64dp&quot;
 *         android:width=&quot;64dp&quot; /&gt;
 *     &lt;viewport
 *         android:viewportHeight=&quot;600&quot;
 *         android:viewportWidth=&quot;600&quot; /&gt;
 *     &lt;group
 *         android:name=&quot;rotationGroup&quot;
 *         android:pivotX=&quot;300.0&quot;
 *         android:pivotY=&quot;300.0&quot;
 *         android:rotation=&quot;45.0&quot; &gt;
 *         &lt;path
 *             android:name=&quot;v&quot;
 *             android:fill=&quot;#000000&quot;
 *             android:pathData=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot; /&gt;
 *     &lt;/group&gt;
 * &lt;/vector&gt;
 * </pre></li>
 * <p>
 * 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.
 * </p>
 * <li>Here is a simple AnimatedVectorDrawable defined in this avd.xml file.
 * Note how we use the names to refer to the groups and paths in the vectordrawable.xml.
 * <pre>
 * &lt;animated-vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
 *   android:drawable=&quot;@drawable/vectordrawable&quot; &gt;
 *     &lt;target
 *         android:name=&quot;rotationGroup&quot;
 *         android:animation=&quot;@anim/rotation&quot; /&gt;
 *     &lt;target
 *         android:name=&quot;v&quot;
 *         android:animation=&quot;@anim/path_morph&quot; /&gt;
 * &lt;/animated-vector&gt;
 * </pre></li>
 * <p>
 * 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.
 * </p>
 * <li>Here is the rotation.xml, which will rotate the target group for 360 degrees.
 * <pre>
 * &lt;objectAnimator
 *     android:duration=&quot;6000&quot;
 *     android:propertyName=&quot;rotation&quot;
 *     android:valueFrom=&quot;0&quot;
 *     android:valueTo=&quot;360&quot; /&gt;
 * </pre></li>
 * <li>Here is the path_morph.xml, which will morph the path from one shape to
 * the other. Note that the paths must be compatible for morphing.
 * In more details, the paths should have exact same length of commands , and
 * exact same length of parameters for each commands.
 * Note that the path string are better stored in strings.xml for reusing.
 * <pre>
 * &lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
 *     &lt;objectAnimator
 *         android:duration=&quot;3000&quot;
 *         android:propertyName=&quot;pathData&quot;
 *         android:valueFrom=&quot;M300,70 l 0,-70 70,70 0,0   -70,70z&quot;
 *         android:valueTo=&quot;M300,70 l 0,-70 70,0  0,140 -70,0 z&quot;
 *         android:valueType=&quot;pathType&quot;/&gt;
 * &lt;/set&gt;
 * </pre></li>
 *
 * @hide
 * @attr ref android.R.styleable#AnimatedVectorDrawable_drawable
 * @attr ref android.R.styleable#AnimatedVectorDrawableTarget_name
 * @attr ref android.R.styleable#AnimatedVectorDrawableTarget_animation
 */
public class AnimatedVectorDrawable extends Drawable implements Animatable {
    private static final String LOGTAG = AnimatedVectorDrawable.class.getSimpleName();
+0 −40
Original line number Diff line number Diff line
@@ -237,34 +237,6 @@ public class VectorDrawable extends Drawable {
        return PixelFormat.TRANSLUCENT;
    }

    /**
     * Sets padding for this shape, defined by a Rect object. Define the padding
     * in the Rect object as: left, top, right, bottom.
     */
    public void setPadding(Rect padding) {
        setPadding(padding.left, padding.top, padding.right, padding.bottom);
    }

    /**
     * Sets padding for the shape.
     *
     * @param left padding for the left side (in pixels)
     * @param top padding for the top (in pixels)
     * @param right padding for the right side (in pixels)
     * @param bottom padding for the bottom (in pixels)
     */
    public void setPadding(int left, int top, int right, int bottom) {
        if ((left | top | right | bottom) == 0) {
            mVectorState.mPadding = null;
        } else {
            if (mVectorState.mPadding == null) {
                mVectorState.mPadding = new Rect();
            }
            mVectorState.mPadding.set(left, top, right, bottom);
        }
        invalidateSelf();
    }

    @Override
    public int getIntrinsicWidth() {
        return (int) mVectorState.mVPathRenderer.mBaseWidth;
@@ -275,16 +247,6 @@ public class VectorDrawable extends Drawable {
        return (int) mVectorState.mVPathRenderer.mBaseHeight;
    }

    @Override
    public boolean getPadding(Rect padding) {
        if (mVectorState.mPadding != null) {
            padding.set(mVectorState.mPadding);
            return true;
        } else {
            return super.getPadding(padding);
        }
    }

    @Override
    public boolean canApplyTheme() {
        return super.canApplyTheme() || mVectorState != null && mVectorState.canApplyTheme();
@@ -462,7 +424,6 @@ public class VectorDrawable extends Drawable {
        int[] mThemeAttrs;
        int mChangingConfigurations;
        VPathRenderer mVPathRenderer;
        Rect mPadding;
        ColorStateList mTint;
        Mode mTintMode;

@@ -472,7 +433,6 @@ public class VectorDrawable extends Drawable {
                mChangingConfigurations = copy.mChangingConfigurations;
                // TODO: Make sure the constant state are handled correctly.
                mVPathRenderer = new VPathRenderer(copy.mVPathRenderer);
                mPadding = new Rect(copy.mPadding);
                mTint = copy.mTint;
                mTintMode = copy.mTintMode;
            }