setName(), where name is
* the value of the propertyName parameter.
* @param propertyName The name of the property being animated.
- * @param values The set of values to animate between. If there is only one value, it
- * is assumed to be the final value being animated to, and the initial value will be
- * derived on the fly.
*/
- public ObjectAnimator(long duration, Object target, String propertyName, T...values) {
- super(duration, (T[]) values);
+ private ObjectAnimator(Object target, String propertyName) {
mTarget = target;
setPropertyName(propertyName);
}
+ /**
+ * Constructs and returns an ObjectAnimator that animates between int 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 target The object whose property is to be animated. This object should
+ * have a public method on it called setName(), where name is
+ * the value of the propertyName 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 A ValueAnimator object that is set up to animate between the given values.
+ */
+ public static ObjectAnimator ofInt(Object target, String propertyName, int... values) {
+ ObjectAnimator anim = new ObjectAnimator(target, propertyName);
+ anim.setIntValues(values);
+ return anim;
+ }
+
+ /**
+ * Constructs and returns an ObjectAnimator 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
+ * 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 target The object whose property is to be animated. This object should
+ * have a public method on it called setName(), where name is
+ * the value of the propertyName 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 A ValueAnimator object that is set up to animate between the given values.
+ */
+ public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
+ ObjectAnimator anim = new ObjectAnimator(target, propertyName);
+ anim.setFloatValues(values);
+ return anim;
+ }
+
+ /**
+ * Constructs and returns an ObjectAnimator that animates between long 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 target The object whose property is to be animated. This object should
+ * have a public method on it called setName(), where name is
+ * the value of the propertyName 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 A ValueAnimator object that is set up to animate between the given values.
+ */
+ public static ObjectAnimator ofLong(Object target, String propertyName, long... values) {
+ ObjectAnimator anim = new ObjectAnimator(target, propertyName);
+ anim.setLongValues(values);
+ return anim;
+ }
+
+ /**
+ * Constructs and returns an ObjectAnimator that animates between double 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 target The object whose property is to be animated. This object should
+ * have a public method on it called setName(), where name is
+ * the value of the propertyName 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 A ValueAnimator object that is set up to animate between the given values.
+ */
+ public static ObjectAnimator ofDouble(Object target, String propertyName, double... values) {
+ ObjectAnimator anim = new ObjectAnimator(target, propertyName);
+ anim.setDoubleValues(values);
+ return anim;
+ }
+
/**
* A constructor that takes PropertyValueHolder values. This constructor should
* be used when animating several properties at once with the same ObjectAnimator, since
* PropertyValuesHolder allows you to associate a set of animation values with a property
* name.
*
- * @param duration The length of the animation, in milliseconds.
* @param target The object whose property is to be animated. This object should
* have public methods on it called setName(), where name is
* the name of the property passed in as the propertyName parameter for
* each of the PropertyValuesHolder objects.
+ * @param propertyName The name of the property being animated.
+ * @param evaluator A TypeEvaluator that will be called on each animation frame to
+ * provide the ncessry interpolation between the Object values to derive the animated
+ * value.
* @param values The PropertyValuesHolder objects which hold each the property name and values
* to animate that property between.
*/
- public ObjectAnimator(long duration, Object target, PropertyValuesHolder...values) {
- super(duration);
- setValues(values);
- mTarget = target;
+ public static ObjectAnimator ofObject(Object target, String propertyName,
+ TypeEvaluator evaluator, Object... values) {
+ ObjectAnimator anim = new ObjectAnimator(target, propertyName);
+ anim.setObjectValues(values);
+ anim.setEvaluator(evaluator);
+ return anim;
}
- @Override
- public void setValues(T... values) {
- if (mValues == null || mValues.length == 0) {
- // No values yet - this animator is being constructed piecemeal. Init the values with
- // whatever the current propertyName is
- setValues(new PropertyValuesHolder[]{
- new PropertyValuesHolder(mPropertyName, (Object[])values)});
- } else {
- super.setValues((T[]) values);
- }
+ /**
+ * Constructs and returns an ObjectAnimator that animates between the sets of values
+ * specifed in PropertyValueHolder objects. This variant should
+ * be used when animating several properties at once with the same ObjectAnimator, since
+ * PropertyValuesHolder allows you to associate a set of animation values with a property
+ * name.
+ *
+ * @param target The object whose property is to be animated. This object should
+ * have public methods on it called setName(), where name is
+ * the name of the property passed in as the propertyName parameter for
+ * each of the PropertyValuesHolder objects.
+ * @param values A set of PropertyValuesHolder objects whose values will be animated
+ * between over time.
+ * @return A ValueAnimator object that is set up to animate between the given values.
+ */
+ public static ObjectAnimator ofPropertyValuesHolder(Object target,
+ PropertyValuesHolder... values) {
+ ObjectAnimator anim = new ObjectAnimator();
+ anim.setValues(values);
+ return anim;
}
-
/**
* This function is called immediately before processing the first animation
* frame of an animation. If there is a nonzero startDelay, the
@@ -194,6 +287,21 @@ public final class ObjectAnimatorObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start().
+ */
+ @Override
+ public ObjectAnimator setDuration(long duration) {
+ super.setDuration(duration);
+ return this;
+ }
+
/**
* The target object whose property will be animated by this animation
diff --git a/core/java/android/animation/PropertyValuesHolder.java b/core/java/android/animation/PropertyValuesHolder.java
index 1d46123db4375..d546f310718c6 100644
--- a/core/java/android/animation/PropertyValuesHolder.java
+++ b/core/java/android/animation/PropertyValuesHolder.java
@@ -30,7 +30,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* animations with ValueAnimator or ObjectAnimator that operate on several different properties
* in parallel.
*/
-public class PropertyValuesHolderIf there is only one value, it is assumed to be the end value of an animation,
@@ -151,9 +217,120 @@ public class PropertyValuesHolderpropertyName or set explicitly via
+ * {@link #setGetter(java.lang.reflect.Method)}, since otherwise PropertyValuesHolder has
+ * no way of determining what the value should be.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setIntValues(int... values) {
+ mValueType = int.class;
+ mKeyframeSet = KeyframeSet.ofInt(values);
+ }
+
+ /**
+ * Set the animated values for this object to this set of floats.
+ * If there is only one value, it is assumed to be the end value of an animation,
+ * and an initial value will be derived, if possible, by calling a getter function
+ * on the object. Also, if any value is null, the value will be filled in when the animation
+ * starts in the same way. This mechanism of automatically getting null values only works
+ * if the PropertyValuesHolder object is used in conjunction
+ * {@link ObjectAnimator}, and with a getter function either
+ * derived automatically from propertyName or set explicitly via
+ * {@link #setGetter(java.lang.reflect.Method)}, since otherwise PropertyValuesHolder has
+ * no way of determining what the value should be.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setFloatValues(float... values) {
+ mValueType = float.class;
+ mKeyframeSet = KeyframeSet.ofFloat(values);
+ }
+
+ /**
+ * Set the animated values for this object to this set of doubles.
+ * If there is only one value, it is assumed to be the end value of an animation,
+ * and an initial value will be derived, if possible, by calling a getter function
+ * on the object. Also, if any value is null, the value will be filled in when the animation
+ * starts in the same way. This mechanism of automatically getting null values only works
+ * if the PropertyValuesHolder object is used in conjunction
+ * {@link ObjectAnimator}, and with a getter function either
+ * derived automatically from propertyName or set explicitly via
+ * {@link #setGetter(java.lang.reflect.Method)}, since otherwise PropertyValuesHolder has
+ * no way of determining what the value should be.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setDoubleValues(double... values) {
+ mValueType = double.class;
+ mKeyframeSet = KeyframeSet.ofDouble(values);
+ }
+
+ /**
+ * Set the animated values for this object to this set of longs.
+ * If there is only one value, it is assumed to be the end value of an animation,
+ * and an initial value will be derived, if possible, by calling a getter function
+ * on the object. Also, if any value is null, the value will be filled in when the animation
+ * starts in the same way. This mechanism of automatically getting null values only works
+ * if the PropertyValuesHolder object is used in conjunction
+ * {@link ObjectAnimator}, and with a getter function either
+ * derived automatically from propertyName or set explicitly via
+ * {@link #setGetter(java.lang.reflect.Method)}, since otherwise PropertyValuesHolder has
+ * no way of determining what the value should be.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setLongValues(long... values) {
+ mValueType = long.class;
+ mKeyframeSet = KeyframeSet.ofLong(values);
+ }
+
+ /**
+ * Set the animated values for this object to this set of Keyframes.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setKeyframes(Keyframe... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ mValueType = ((Keyframe)values[0]).getType();
+ for (int i = 0; i < numKeyframes; ++i) {
+ keyframes[i] = (Keyframe)values[i];
+ }
+ mKeyframeSet = new KeyframeSet(keyframes);
+ }
+
+ /**
+ * Set the animated values for this object to this set of Objects.
+ * If there is only one value, it is assumed to be the end value of an animation,
+ * and an initial value will be derived, if possible, by calling a getter function
+ * on the object. Also, if any value is null, the value will be filled in when the animation
+ * starts in the same way. This mechanism of automatically getting null values only works
+ * if the PropertyValuesHolder object is used in conjunction
+ * {@link ObjectAnimator}, and with a getter function either
+ * derived automatically from propertyName or set explicitly via
+ * {@link #setGetter(java.lang.reflect.Method)}, since otherwise PropertyValuesHolder has
+ * no way of determining what the value should be.
+ *
+ * @param values One or more values that the animation will animate between.
+ */
+ public void setObjectValues(Object... values) {
+ mValueType = values[0].getClass();
+ mKeyframeSet = KeyframeSet.ofObject(values);
}
/**
@@ -169,6 +346,7 @@ public class PropertyValuesHolder
Since ValueAnimator does not know how to animate between arbitrary Objects, this + * factory method also takes a TypeEvaluator object that the ValueAnimator will use + * to perform that interpolation. + * + * @param evaluator A TypeEvaluator that will be called on each animation frame to + * provide the ncessry interpolation between the Object values to derive the animated + * value. + * @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 ofObject(TypeEvaluator evaluator, Object... values) { + ValueAnimator anim = new ValueAnimator(); + anim.setObjectValues(values); + anim.setEvaluator(evaluator); + return anim; + } + + /** + * Sets int values that will be animated between. 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. + * + *
If there are already multiple sets of values defined for this ValueAnimator via more + * than one PropertyValuesHolder object, this method will set the values for the first + * of those objects.
+ * + * @param values A set of values that the animation will animate between over time. + */ + public void setIntValues(int... values) { + if (values == null || values.length == 0) { + return; } + if (mValues == null || mValues.length == 0) { + setValues(new PropertyValuesHolder[]{PropertyValuesHolder.ofInt("", values)}); + } else { + PropertyValuesHolder valuesHolder = mValues[0]; + valuesHolder.setIntValues(values); + } + // New property/values/target should cause re-initialization prior to starting + mInitialized = false; + } + + /** + * Sets float values that will be animated between. 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. + * + *If there are already multiple sets of values defined for this ValueAnimator via more + * than one PropertyValuesHolder object, this method will set the values for the first + * of those objects.
+ * + * @param values A set of values that the animation will animate between over time. + */ + public void setFloatValues(float... values) { + if (values == null || values.length == 0) { + return; + } + if (mValues == null || mValues.length == 0) { + setValues(new PropertyValuesHolder[]{PropertyValuesHolder.ofFloat("", values)}); + } else { + PropertyValuesHolder valuesHolder = mValues[0]; + valuesHolder.setFloatValues(values); + } + // New property/values/target should cause re-initialization prior to starting + mInitialized = false; + } + + /** + * Sets long values that will be animated between. 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. + * + *If there are already multiple sets of values defined for this ValueAnimator via more + * than one PropertyValuesHolder object, this method will set the values for the first + * of those objects.
+ * + * @param values A set of values that the animation will animate between over time. + */ + public void setLongValues(long... values) { + if (values == null || values.length == 0) { + return; + } + if (mValues == null || mValues.length == 0) { + setValues(new PropertyValuesHolder[]{PropertyValuesHolder.ofLong("", values)}); + } else { + PropertyValuesHolder valuesHolder = mValues[0]; + valuesHolder.setLongValues(values); + } + // New property/values/target should cause re-initialization prior to starting + mInitialized = false; + } + + /** + * Sets double values that will be animated between. 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. + * + *If there are already multiple sets of values defined for this ValueAnimator via more + * than one PropertyValuesHolder object, this method will set the values for the first + * of those objects.
+ * + * @param values A set of values that the animation will animate between over time. + */ + public void setDoubleValues(double... values) { + if (values == null || values.length == 0) { + return; + } + if (mValues == null || mValues.length == 0) { + setValues(new PropertyValuesHolder[]{PropertyValuesHolder.ofDouble("", values)}); + } else { + PropertyValuesHolder valuesHolder = mValues[0]; + valuesHolder.setDoubleValues(values); + } + // New property/values/target should cause re-initialization prior to starting + mInitialized = false; + } + + /** + * Sets the values to animate between for this animation. 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. + * + *If there are already multiple sets of values defined for this ValueAnimator via more + * than one PropertyValuesHolder object, this method will set the values for the first + * of those objects.
+ * + *There should be a TypeEvaluator set on the ValueAnimator that knows how to interpolate + * between these value objects. ValueAnimator only knows how to interpolate between the + * primitive types specified in the other setValues() methods.
+ * + * @param values The set of values to animate between. + */ + public void setObjectValues(Object... values) { + if (values == null || values.length == 0) { + return; + } + if (mValues == null || mValues.length == 0) { + setValues(new PropertyValuesHolder[]{PropertyValuesHolder.ofObject("", + (TypeEvaluator)null, values)}); + } else { + PropertyValuesHolder valuesHolder = mValues[0]; + valuesHolder.setObjectValues(values); + } + // New property/values/target should cause re-initialization prior to starting + mInitialized = false; } /** @@ -274,30 +507,6 @@ public class ValueAnimatorvalues 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 ValueAnimator. Also, if the values are not
- * PropertyValuesHolder objects and if there are already multiple sets of
- * values defined for this ValueAnimator via
- * more than one PropertyValuesHolder objects, this method will set the values for
- * the first of those objects.
- *
- * @param values The set of values to animate between.
- */
- public void setValues(T... values) {
- if (mValues == null || mValues.length == 0) {
- setValues(new PropertyValuesHolder[]{
- new PropertyValuesHolder("", (Object[])values)});
- } else {
- PropertyValuesHolder valuesHolder = mValues[0];
- valuesHolder.setValues(values);
- }
- // New property/values/target should cause re-initialization prior to starting
- mInitialized = false;
- }
-
/**
* This function is called immediately before processing the first animation
* frame of an animation. If there is a nonzero startDelay, the
@@ -321,16 +530,20 @@ public class ValueAnimatorValueAnimator.ofInt(0, 10).setDuration(500).start().
*/
- public void setDuration(long duration) {
+ public ValueAnimator setDuration(long duration) {
mDuration = duration;
+ return this;
}
/**
- * Gets the length of the animation.
+ * Gets the length of the animation. The default duration is 300 milliseconds.
*
* @return The length of the animation, in milliseconds.
*/
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java
index b7b1a2309efb5..b5934b03c0967 100644
--- a/core/java/android/widget/AdapterViewAnimator.java
+++ b/core/java/android/widget/AdapterViewAnimator.java
@@ -138,8 +138,8 @@ public abstract class AdapterViewAnimator extends AdapterView