summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-10-21 21:13:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-21 21:13:08 +0000
commite6702cb0f6eab83442b097081c3888a1fde87e6a (patch)
tree085bb36964a8b9562ea169f76bce2690d44524b1
parentf7e6c3cb8a76bee9ff4060180dcaee93b27e9835 (diff)
parent1ffb280a7d2c70cc16d709c685f5d31fdb86b5e4 (diff)
downloadframeworks_base-e6702cb0f6eab83442b097081c3888a1fde87e6a.zip
frameworks_base-e6702cb0f6eab83442b097081c3888a1fde87e6a.tar.gz
frameworks_base-e6702cb0f6eab83442b097081c3888a1fde87e6a.tar.bz2
Merge "Add ofArgb to ObjectAnimator and ValueAnimator."
-rw-r--r--api/current.txt3
-rw-r--r--core/java/android/animation/AnimatorInflater.java2
-rw-r--r--core/java/android/animation/ArgbEvaluator.java13
-rw-r--r--core/java/android/animation/ObjectAnimator.java39
-rw-r--r--core/java/android/animation/ValueAnimator.java18
-rw-r--r--core/java/android/transition/Recolor.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java3
7 files changed, 78 insertions, 8 deletions
diff --git a/api/current.txt b/api/current.txt
index cf09f21..0b605b5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -2524,6 +2524,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...);
@@ -2612,6 +2614,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...);
diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java
index c024c27..20236aa 100644
--- a/core/java/android/animation/AnimatorInflater.java
+++ b/core/java/android/animation/AnimatorInflater.java
@@ -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) {
diff --git a/core/java/android/animation/ArgbEvaluator.java b/core/java/android/animation/ArgbEvaluator.java
index 717a3d9..ed07195 100644
--- a/core/java/android/animation/ArgbEvaluator.java
+++ b/core/java/android/animation/ArgbEvaluator.java
@@ -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
diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java
index 07a2821..3adbf08 100644
--- a/core/java/android/animation/ObjectAnimator.java
+++ b/core/java/android/animation/ObjectAnimator.java
@@ -275,6 +275,45 @@ public final class ObjectAnimator extends ValueAnimator {
}
/**
+ * 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
* and ending values. More than two values imply a starting value, values to animate through
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index 86da673..7880f39 100644
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -280,6 +280,24 @@ public class ValueAnimator extends Animator {
}
/**
+ * 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
* useful in a ValueAnimator object because there is no way for the object to determine the
diff --git a/core/java/android/transition/Recolor.java b/core/java/android/transition/Recolor.java
index 70111d1..1638f67 100644
--- a/core/java/android/transition/Recolor.java
+++ b/core/java/android/transition/Recolor.java
@@ -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;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
index 1c8702a..149ca79 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
@@ -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();
}