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

Commit 1ffb280a authored by George Mount's avatar George Mount
Browse files

Add ofArgb to ObjectAnimator and ValueAnimator.

Bug 10396985

Change-Id: Ib1fcea04b5a915800fc415b3d548a8853b05389c
parent b44c4439
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2527,6 +2527,8 @@ package android.animation {
    ctor public ObjectAnimator();
    method public java.lang.String getPropertyName();
    method public java.lang.Object getTarget();
    method public static android.animation.ObjectAnimator ofArgb(java.lang.Object, java.lang.String, int...);
    method public static android.animation.ObjectAnimator ofArgb(T, android.util.Property<T, java.lang.Integer>, int...);
    method public static android.animation.ObjectAnimator ofFloat(java.lang.Object, java.lang.String, float...);
    method public static android.animation.ObjectAnimator ofFloat(T, android.util.Property<T, java.lang.Float>, float...);
    method public static android.animation.ObjectAnimator ofInt(java.lang.Object, java.lang.String, int...);
@@ -2615,6 +2617,7 @@ package android.animation {
    method public long getStartDelay();
    method public android.animation.PropertyValuesHolder[] getValues();
    method public boolean isRunning();
    method public static android.animation.ValueAnimator ofArgb(int...);
    method public static android.animation.ValueAnimator ofFloat(float...);
    method public static android.animation.ValueAnimator ofInt(int...);
    method public static android.animation.ValueAnimator ofObject(android.animation.TypeEvaluator, java.lang.Object...);
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public class AnimatorInflater {
                (toType <= TypedValue.TYPE_LAST_COLOR_INT))) {
            // special case for colors: ignore valueType and get ints
            getFloats = false;
            evaluator = new ArgbEvaluator();
            evaluator = ArgbEvaluator.getInstance();
        }

        if (getFloats) {
+13 −0
Original line number Diff line number Diff line
@@ -21,6 +21,19 @@ package android.animation;
 * values that represent ARGB colors.
 */
public class ArgbEvaluator implements TypeEvaluator {
    private static final ArgbEvaluator sInstance = new ArgbEvaluator();

    /**
     * Returns an instance of <code>ArgbEvaluator</code> that may be used in
     * {@link ValueAnimator#setEvaluator(TypeEvaluator)}. The same instance may
     * be used in multiple <code>Animator</code>s because it holds no state.
     * @return An instance of <code>ArgbEvalutor</code>.
     *
     * @hide
     */
    public static ArgbEvaluator getInstance() {
        return sInstance;
    }

    /**
     * This function returns the calculated in-between value for a color
+39 −0
Original line number Diff line number Diff line
@@ -274,6 +274,45 @@ public final class ObjectAnimator extends ValueAnimator {
        return ObjectAnimator.ofPropertyValuesHolder(target, pvh);
    }

    /**
     * Constructs and returns an ObjectAnimator that animates between color values. A single
     * value implies that that value is the one being animated to. Two values imply starting
     * and ending values. More than two values imply a starting value, values to animate through
     * along the way, and an ending value (these values will be distributed evenly across
     * the duration of the animation).
     *
     * @param target The object whose property is to be animated. This object should
     * have a public method on it called <code>setName()</code>, where <code>name</code> is
     * the value of the <code>propertyName</code> parameter.
     * @param propertyName The name of the property being animated.
     * @param values A set of values that the animation will animate between over time.
     * @return An ObjectAnimator object that is set up to animate between the given values.
     */
    public static ObjectAnimator ofArgb(Object target, String propertyName, int... values) {
        ObjectAnimator animator = ofInt(target, propertyName, values);
        animator.setEvaluator(ArgbEvaluator.getInstance());
        return animator;
    }

    /**
     * Constructs and returns an ObjectAnimator that animates between color values. A single
     * value implies that that value is the one being animated to. Two values imply starting
     * and ending values. More than two values imply a starting value, values to animate through
     * along the way, and an ending value (these values will be distributed evenly across
     * the duration of the animation).
     *
     * @param target The object whose property is to be animated.
     * @param property The property being animated.
     * @param values A set of values that the animation will animate between over time.
     * @return An ObjectAnimator object that is set up to animate between the given values.
     */
    public static <T> ObjectAnimator ofArgb(T target, Property<T, Integer> property,
            int... values) {
        ObjectAnimator animator = ofInt(target, property, values);
        animator.setEvaluator(ArgbEvaluator.getInstance());
        return animator;
    }

    /**
     * Constructs and returns an ObjectAnimator that animates between float values. A single
     * value implies that that value is the one being animated to. Two values imply starting
+18 −0
Original line number Diff line number Diff line
@@ -279,6 +279,24 @@ public class ValueAnimator extends Animator {
        return anim;
    }

    /**
     * Constructs and returns a ValueAnimator that animates between color values. A single
     * value implies that that value is the one being animated to. However, this is not typically
     * useful in a ValueAnimator object because there is no way for the object to determine the
     * starting value for the animation (unlike ObjectAnimator, which can derive that value
     * from the target object and property being animated). Therefore, there should typically
     * be two or more values.
     *
     * @param values A set of values that the animation will animate between over time.
     * @return A ValueAnimator object that is set up to animate between the given values.
     */
    public static ValueAnimator ofArgb(int... values) {
        ValueAnimator anim = new ValueAnimator();
        anim.setIntValues(values);
        anim.setEvaluator(ArgbEvaluator.getInstance());
        return anim;
    }

    /**
     * Constructs and returns a ValueAnimator that animates between float values. A single
     * value implies that that value is the one being animated to. However, this is not typically
Loading