Add ofArgb to ObjectAnimator and ValueAnimator.
Bug 10396985 Change-Id: Ib1fcea04b5a915800fc415b3d548a8853b05389c
This commit is contained in:
@@ -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...);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package android.transition;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -75,8 +74,8 @@ public class Recolor extends Transition {
|
||||
if (startColor.getColor() != endColor.getColor()) {
|
||||
endColor.setColor(startColor.getColor());
|
||||
changed = true;
|
||||
return ObjectAnimator.ofObject(endBackground, "color",
|
||||
new ArgbEvaluator(), startColor.getColor(), endColor.getColor());
|
||||
return ObjectAnimator.ofArgb(endBackground, "color", startColor.getColor(),
|
||||
endColor.getColor());
|
||||
}
|
||||
}
|
||||
if (view instanceof TextView) {
|
||||
@@ -86,8 +85,7 @@ public class Recolor extends Transition {
|
||||
if (start != end) {
|
||||
textView.setTextColor(end);
|
||||
changed = true;
|
||||
return ObjectAnimator.ofObject(textView, "textColor",
|
||||
new ArgbEvaluator(), start, end);
|
||||
return ObjectAnimator.ofArgb(textView, "textColor", start, end);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.app.ActivityManager;
|
||||
@@ -142,7 +141,7 @@ public class BarTransitions {
|
||||
|
||||
private void startColorAnimation(int from, int to) {
|
||||
if (DEBUG) Log.d(mTag, String.format("startColorAnimation %08x -> %08x", from, to));
|
||||
mColorDrawableAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), from, to);
|
||||
mColorDrawableAnimator = ValueAnimator.ofArgb(from, to);
|
||||
mColorDrawableAnimator.addUpdateListener(mAnimatorListener);
|
||||
mColorDrawableAnimator.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user