From d953d08e9299072130d9f4411cbcf6678bbce822 Mon Sep 17 00:00:00 2001
From: Chet Haase
float values.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- public Animator(long duration, float valueFrom, float valueTo) {
- this(duration, valueFrom, valueTo, float.class);
- }
-
- /**
- * A constructor that takes int values.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- public Animator(long duration, int valueFrom, int valueTo) {
- this(duration, valueFrom, valueTo, int.class);
- }
-
- /**
- * A constructor that takes double values.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- public Animator(long duration, double valueFrom, double valueTo) {
- this(duration, valueFrom, valueTo, double.class);
- }
-
- /**
- * A constructor that takes Object values.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- public Animator(long duration, Object valueFrom, Object valueTo) {
- this(duration, valueFrom, valueTo,
- (valueFrom != null) ? valueFrom.getClass() : valueTo.getClass());
- }
-
- /**
- * Internal constructor that takes a single float value.
- * This constructor is called by PropertyAnimator.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- Animator(long duration, float valueTo) {
- this(duration, null, valueTo, float.class);
+ if (values.length > 0) {
+ setValues(values);
+ }
}
- /**
- * Internal constructor that takes a single int value.
- * This constructor is called by PropertyAnimator.
- *
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
- */
- Animator(long duration, int valueTo) {
- this(duration, null, valueTo, int.class);
+ public void setValues(PropertyValuesHolder... values) {
+ int numValues = values.length;
+ mValues = new HashMapdouble value.
- * This constructor is called by PropertyAnimator.
+ * Sets the values to animate between for this animation. If values is
+ * a set of PropertyValuesHolder objects, these objects will become the set of properties
+ * animated and the values that those properties are animated between. Otherwise, this method
+ * will set only one set of values for the Animator. Also, if the values are not
+ * PropertyValuesHolder objects and if there are already multiple sets of
+ * values defined for this Animator via
+ * more than one PropertyValuesHolder objects, this method will set the values for
+ * the first of those objects.
*
- * @param duration The length of the animation, in milliseconds.
- * @param valueFrom The initial value of the property when the animation begins.
- * @param valueTo The value to which the property will animate.
+ * @param values The set of values to animate between.
*/
- Animator(long duration, double valueTo) {
- this(duration, null, valueTo, double.class);
+ public void setValues(T... values) {
+ if (values[0] instanceof PropertyValuesHolder) {
+ int numValues = values.length;
+ mValues = new HashMapAnimator for the property
- * being animated. This value is only sensible while the animation is running. The main
+ * The most recent value calculated by this Animator when there is just one
+ * property being animated. This value is only sensible while the animation is running. The main
* purpose for this read-only property is to retrieve the value from the Animator
* during a call to {@link AnimatorUpdateListener#onAnimationUpdate(Animator)}, which
* is called during each animation frame, immediately after the value is calculated.
*
* @return animatedValue The value most recently calculated by this Animator for
- * the property specified in the constructor.
+ * the single property being animated. If there are several properties being animated
+ * (specified by several PropertyValuesHolder objects in the constructor), this function
+ * returns the animated value for the first of those objects.
*/
public Object getAnimatedValue() {
- return mAnimatedValue;
+ return getAnimatedValue(mFirstPropertyName);
+ }
+
+ /**
+ * The most recent value calculated by this Animator for propertyName.
+ * The main purpose for this read-only property is to retrieve the value from the
+ * Animator during a call to
+ * {@link AnimatorUpdateListener#onAnimationUpdate(Animator)}, which
+ * is called during each animation frame, immediately after the value is calculated.
+ *
+ * @return animatedValue The value most recently calculated for the named property
+ * by this Animator.
+ */
+ public Object getAnimatedValue(String propertyName) {
+ return mValues.get(mFirstPropertyName).getAnimatedValue();
}
/**
@@ -781,14 +699,26 @@ public class Animator extends Animatable {
* For example, when running an animation on color values, the {@link RGBEvaluator}
* should be used to get correct RGB color interpolation.
*
+ * If this Animator has only one set of values being animated between, this evaluator + * will be used for that set. If there are several sets of values being animated, which is + * the case if PropertyValuesHOlder objects were set on the Animator, then the evaluator + * is assigned just to the first PropertyValuesHolder object.
+ * * @param value the evaluator to be used this animation */ public void setEvaluator(TypeEvaluator value) { - if (value != null) { - mEvaluator = value; + if (value != null && mValues != null) { + mValues.get(mFirstPropertyName).setEvaluator(value); } } + /** + * Start the animation playing. This version of start() takes a boolean flag that indicates + * whether the animation should play in reverse. The flag is usually false, but may be set + * to true if called from the reverse() method/ + * + * @param playBackwards Whether the Animator should start playing in reverse. + */ private void start(boolean playBackwards) { mPlayingBackwards = playBackwards; mPlayingState = STOPPED; @@ -998,10 +928,8 @@ public class Animator extends Animatable { */ void animateValue(float fraction) { fraction = mInterpolator.getInterpolation(fraction); - if (mKeyframeSet != null) { - mAnimatedValue = mKeyframeSet.getValue(fraction, mEvaluator); - } else { - mAnimatedValue = mEvaluator.evaluate(fraction, mValueFrom, mValueTo); + for (PropertyValuesHolder valuesHolder : mValues.values()) { + valuesHolder.calculateValue(fraction); } if (mUpdateListeners != null) { int numListeners = mUpdateListeners.size(); diff --git a/core/java/android/animation/DoubleEvaluator.java b/core/java/android/animation/DoubleEvaluator.java index 86e3f225e64c..e46eb372e554 100644 --- a/core/java/android/animation/DoubleEvaluator.java +++ b/core/java/android/animation/DoubleEvaluator.java @@ -36,7 +36,7 @@ public class DoubleEvaluator implements TypeEvaluator { *fraction parameter.
*/
public Object evaluate(float fraction, Object startValue, Object endValue) {
- double startDouble = (Double) startValue;
- return startDouble + fraction * ((Double) endValue - startDouble);
+ double startDouble = ((Number) startValue).doubleValue();
+ return startDouble + fraction * (((Number) endValue).doubleValue() - startDouble);
}
}
\ No newline at end of file
diff --git a/core/java/android/animation/FloatEvaluator.java b/core/java/android/animation/FloatEvaluator.java
index 29a6f71c2246..9e2054d0dc02 100644
--- a/core/java/android/animation/FloatEvaluator.java
+++ b/core/java/android/animation/FloatEvaluator.java
@@ -36,7 +36,7 @@ public class FloatEvaluator implements TypeEvaluator {
* fraction parameter.
*/
public Object evaluate(float fraction, Object startValue, Object endValue) {
- float startFloat = (Float) startValue;
- return startFloat + fraction * ((Float) endValue - startFloat);
+ float startFloat = ((Number) startValue).floatValue();
+ return startFloat + fraction * (((Number) endValue).floatValue() - startFloat);
}
}
\ No newline at end of file
diff --git a/core/java/android/animation/IntEvaluator.java b/core/java/android/animation/IntEvaluator.java
index 7a2911a5a2b3..7288927f783b 100644
--- a/core/java/android/animation/IntEvaluator.java
+++ b/core/java/android/animation/IntEvaluator.java
@@ -36,7 +36,7 @@ public class IntEvaluator implements TypeEvaluator {
* fraction parameter.
*/
public Object evaluate(float fraction, Object startValue, Object endValue) {
- int startInt = (Integer) startValue;
- return (int) (startInt + fraction * ((Integer) endValue - startInt));
+ int startInt = ((Number) startValue).intValue();
+ return (int) (startInt + fraction * (((Number) endValue).intValue() - startInt));
}
}
\ No newline at end of file
diff --git a/core/java/android/animation/PropertyAnimator.java b/core/java/android/animation/PropertyAnimator.java
index eac9798548c4..9366a713971e 100644
--- a/core/java/android/animation/PropertyAnimator.java
+++ b/core/java/android/animation/PropertyAnimator.java
@@ -33,35 +33,13 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* are then determined internally and the animation will call these functions as necessary to
* animate the property.
*/
-public final class PropertyAnimator extends Animator {
+public final class PropertyAnimator