diff options
author | Romain Guy <romainguy@google.com> | 2010-10-14 10:13:53 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2010-10-14 10:13:53 -0700 |
commit | 83d6e8213230fb0805aa019d266842253baeb114 (patch) | |
tree | 2d3b230eee1a9645c8f2c93e5e32e3ea906d9b20 | |
parent | 70ea25fa8ac1f2005ec4e69023e05af4a8d9bd4a (diff) | |
download | frameworks_base-83d6e8213230fb0805aa019d266842253baeb114.zip frameworks_base-83d6e8213230fb0805aa019d266842253baeb114.tar.gz frameworks_base-83d6e8213230fb0805aa019d266842253baeb114.tar.bz2 |
Revert "Remove generics from Animator APIs"
This reverts commit 41f041d9986f8a5d45b6cb0b86e881c81a412168.
-rw-r--r-- | api/current.xml | 465 | ||||
-rw-r--r-- | core/java/android/animation/Animator.java | 2 | ||||
-rw-r--r-- | core/java/android/animation/AnimatorInflater.java | 120 | ||||
-rw-r--r-- | core/java/android/animation/AnimatorSet.java | 10 | ||||
-rw-r--r-- | core/java/android/animation/KeyframeSet.java | 80 | ||||
-rw-r--r-- | core/java/android/animation/LayoutTransition.java | 19 | ||||
-rw-r--r-- | core/java/android/animation/ObjectAnimator.java | 154 | ||||
-rw-r--r-- | core/java/android/animation/PropertyValuesHolder.java | 219 | ||||
-rwxr-xr-x | core/java/android/animation/ValueAnimator.java | 297 | ||||
-rw-r--r-- | core/java/android/widget/AdapterViewAnimator.java | 36 | ||||
-rw-r--r-- | core/java/android/widget/StackView.java | 57 | ||||
-rw-r--r-- | core/java/com/android/internal/widget/DrawableHolder.java | 19 |
12 files changed, 257 insertions, 1221 deletions
diff --git a/api/current.xml b/api/current.xml index 5f08249..1d84c39 100644 --- a/api/current.xml +++ b/api/current.xml @@ -20416,7 +20416,7 @@ </parameter> </method> <method name="setDuration" - return="android.animation.Animator" + return="void" abstract="true" native="false" synchronized="false" @@ -20766,7 +20766,7 @@ </parameter> </method> <method name="setDuration" - return="android.animation.AnimatorSet" + return="void" abstract="false" native="false" synchronized="false" @@ -21536,129 +21536,57 @@ visibility="public" > </constructor> -<method name="getPropertyName" - return="java.lang.String" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> -<method name="getTarget" - return="java.lang.Object" - abstract="false" - native="false" - synchronized="false" +<constructor name="ObjectAnimator" + type="android.animation.ObjectAnimator" static="false" final="false" deprecated="not deprecated" visibility="public" > -</method> -<method name="ofDouble" - return="android.animation.ObjectAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="target" type="java.lang.Object"> -</parameter> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="double..."> +<parameter name="duration" type="long"> </parameter> -</method> -<method name="ofFloat" - return="android.animation.ObjectAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> <parameter name="target" type="java.lang.Object"> </parameter> <parameter name="propertyName" type="java.lang.String"> </parameter> -<parameter name="values" type="float..."> +<parameter name="values" type="T..."> </parameter> -</method> -<method name="ofInt" - return="android.animation.ObjectAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" +</constructor> +<constructor name="ObjectAnimator" + type="android.animation.ObjectAnimator" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="target" type="java.lang.Object"> -</parameter> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="int..."> +<parameter name="duration" type="long"> </parameter> -</method> -<method name="ofLong" - return="android.animation.ObjectAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> <parameter name="target" type="java.lang.Object"> </parameter> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="long..."> +<parameter name="values" type="android.animation.PropertyValuesHolder..."> </parameter> -</method> -<method name="ofObject" - return="android.animation.ObjectAnimator" +</constructor> +<method name="getPropertyName" + return="java.lang.String" abstract="false" native="false" synchronized="false" - static="true" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="target" type="java.lang.Object"> -</parameter> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="evaluator" type="android.animation.TypeEvaluator"> -</parameter> -<parameter name="values" type="java.lang.Object..."> -</parameter> </method> -<method name="ofPropertyValuesHolder" - return="android.animation.ObjectAnimator" +<method name="getTarget" + return="java.lang.Object" abstract="false" native="false" synchronized="false" - static="true" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="target" type="java.lang.Object"> -</parameter> -<parameter name="values" type="android.animation.PropertyValuesHolder..."> -</parameter> </method> <method name="setPropertyName" return="void" @@ -21684,144 +21612,63 @@ > <implements name="java.lang.Cloneable"> </implements> -<method name="clone" - return="android.animation.PropertyValuesHolder" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> -<method name="getGetter" - return="java.lang.reflect.Method" - abstract="false" - native="false" - synchronized="false" +<constructor name="PropertyValuesHolder" + type="android.animation.PropertyValuesHolder" static="false" final="false" deprecated="not deprecated" visibility="public" > -</method> -<method name="getPropertyName" - return="java.lang.String" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> -<method name="getSetter" - return="java.lang.reflect.Method" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</method> -<method name="ofDouble" - return="android.animation.PropertyValuesHolder" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="double..."> -</parameter> -</method> -<method name="ofFloat" - return="android.animation.PropertyValuesHolder" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="float..."> +<parameter name="values" type="T..."> </parameter> -</method> -<method name="ofInt" - return="android.animation.PropertyValuesHolder" - abstract="false" - native="false" - synchronized="false" - static="true" +</constructor> +<constructor name="PropertyValuesHolder" + type="android.animation.PropertyValuesHolder" + static="false" final="false" deprecated="not deprecated" visibility="public" > <parameter name="propertyName" type="java.lang.String"> </parameter> -<parameter name="values" type="int..."> +<parameter name="values" type="T..."> </parameter> -</method> -<method name="ofKeyframe" +</constructor> +<method name="clone" return="android.animation.PropertyValuesHolder" abstract="false" native="false" synchronized="false" - static="true" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="android.animation.Keyframe..."> -</parameter> </method> -<method name="ofLong" - return="android.animation.PropertyValuesHolder" +<method name="getGetter" + return="java.lang.reflect.Method" abstract="false" native="false" synchronized="false" - static="true" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="values" type="long..."> -</parameter> </method> -<method name="ofObject" - return="android.animation.PropertyValuesHolder" +<method name="getPropertyName" + return="java.lang.String" abstract="false" native="false" synchronized="false" - static="true" + static="false" final="false" deprecated="not deprecated" visibility="public" > -<parameter name="propertyName" type="java.lang.String"> -</parameter> -<parameter name="evaluator" type="android.animation.TypeEvaluator"> -</parameter> -<parameter name="values" type="java.lang.Object..."> -</parameter> </method> -<method name="setDoubleValues" - return="void" +<method name="getSetter" + return="java.lang.reflect.Method" abstract="false" native="false" synchronized="false" @@ -21830,8 +21677,6 @@ deprecated="not deprecated" visibility="public" > -<parameter name="values" type="double..."> -</parameter> </method> <method name="setEvaluator" return="void" @@ -21846,19 +21691,6 @@ <parameter name="evaluator" type="android.animation.TypeEvaluator"> </parameter> </method> -<method name="setFloatValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="float..."> -</parameter> -</method> <method name="setGetter" return="void" abstract="false" @@ -21872,46 +21704,7 @@ <parameter name="getter" type="java.lang.reflect.Method"> </parameter> </method> -<method name="setIntValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="int..."> -</parameter> -</method> -<method name="setKeyframes" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="android.animation.Keyframe..."> -</parameter> -</method> -<method name="setLongValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="long..."> -</parameter> -</method> -<method name="setObjectValues" +<method name="setPropertyName" return="void" abstract="false" native="false" @@ -21921,10 +21714,10 @@ deprecated="not deprecated" visibility="public" > -<parameter name="values" type="java.lang.Object..."> +<parameter name="propertyName" type="java.lang.String"> </parameter> </method> -<method name="setPropertyName" +<method name="setSetter" return="void" abstract="false" native="false" @@ -21934,10 +21727,10 @@ deprecated="not deprecated" visibility="public" > -<parameter name="propertyName" type="java.lang.String"> +<parameter name="setter" type="java.lang.reflect.Method"> </parameter> </method> -<method name="setSetter" +<method name="setValues" return="void" abstract="false" native="false" @@ -21947,7 +21740,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="setter" type="java.lang.reflect.Method"> +<parameter name="values" type="T..."> </parameter> </method> </class> @@ -22049,6 +21842,18 @@ visibility="public" > </constructor> +<constructor name="ValueAnimator" + type="android.animation.ValueAnimator" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="duration" type="long"> +</parameter> +<parameter name="values" type="T..."> +</parameter> +</constructor> <method name="addUpdateListener" return="void" abstract="false" @@ -22185,86 +21990,6 @@ visibility="public" > </method> -<method name="ofDouble" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="double..."> -</parameter> -</method> -<method name="ofFloat" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="float..."> -</parameter> -</method> -<method name="ofInt" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="int..."> -</parameter> -</method> -<method name="ofLong" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="long..."> -</parameter> -</method> -<method name="ofObject" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="evaluator" type="android.animation.TypeEvaluator"> -</parameter> -<parameter name="values" type="java.lang.Object..."> -</parameter> -</method> -<method name="ofPropertyValuesHolder" - return="android.animation.ValueAnimator" - abstract="false" - native="false" - synchronized="false" - static="true" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="android.animation.PropertyValuesHolder..."> -</parameter> -</method> <method name="removeAllUpdateListeners" return="void" abstract="false" @@ -22313,21 +22038,8 @@ <parameter name="playTime" type="long"> </parameter> </method> -<method name="setDoubleValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="double..."> -</parameter> -</method> <method name="setDuration" - return="android.animation.ValueAnimator" + return="void" abstract="false" native="false" synchronized="false" @@ -22352,19 +22064,6 @@ <parameter name="value" type="android.animation.TypeEvaluator"> </parameter> </method> -<method name="setFloatValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="float..."> -</parameter> -</method> <method name="setFrameDelay" return="void" abstract="false" @@ -22378,19 +22077,6 @@ <parameter name="frameDelay" type="long"> </parameter> </method> -<method name="setIntValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="int..."> -</parameter> -</method> <method name="setInterpolator" return="void" abstract="false" @@ -22404,20 +22090,7 @@ <parameter name="value" type="android.animation.TimeInterpolator"> </parameter> </method> -<method name="setLongValues" - return="void" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="values" type="long..."> -</parameter> -</method> -<method name="setObjectValues" +<method name="setRepeatCount" return="void" abstract="false" native="false" @@ -22427,10 +22100,10 @@ deprecated="not deprecated" visibility="public" > -<parameter name="values" type="java.lang.Object..."> +<parameter name="value" type="int"> </parameter> </method> -<method name="setRepeatCount" +<method name="setRepeatMode" return="void" abstract="false" native="false" @@ -22443,7 +22116,7 @@ <parameter name="value" type="int"> </parameter> </method> -<method name="setRepeatMode" +<method name="setStartDelay" return="void" abstract="false" native="false" @@ -22453,10 +22126,10 @@ deprecated="not deprecated" visibility="public" > -<parameter name="value" type="int"> +<parameter name="startDelay" type="long"> </parameter> </method> -<method name="setStartDelay" +<method name="setValues" return="void" abstract="false" native="false" @@ -22466,7 +22139,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="startDelay" type="long"> +<parameter name="values" type="android.animation.PropertyValuesHolder..."> </parameter> </method> <method name="setValues" @@ -22479,7 +22152,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="values" type="android.animation.PropertyValuesHolder..."> +<parameter name="values" type="T..."> </parameter> </method> <field name="INFINITE" @@ -227292,7 +226965,7 @@ > </method> <method name="getInAnimation" - return="android.animation.ObjectAnimator" + return="android.animation.ObjectAnimator<?>" abstract="false" native="false" synchronized="false" @@ -227303,7 +226976,7 @@ > </method> <method name="getOutAnimation" - return="android.animation.ObjectAnimator" + return="android.animation.ObjectAnimator<?>" abstract="false" native="false" synchronized="false" @@ -227419,7 +227092,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="inAnimation" type="android.animation.ObjectAnimator"> +<parameter name="inAnimation" type="android.animation.ObjectAnimator<?>"> </parameter> </method> <method name="setInAnimation" @@ -227447,7 +227120,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="outAnimation" type="android.animation.ObjectAnimator"> +<parameter name="outAnimation" type="android.animation.ObjectAnimator<?>"> </parameter> </method> <method name="setOutAnimation" diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java index 22e04a7..d3e0797 100644 --- a/core/java/android/animation/Animator.java +++ b/core/java/android/animation/Animator.java @@ -78,7 +78,7 @@ public abstract class Animator implements Cloneable { * * @param duration The length of the animation, in milliseconds. */ - public abstract Animator setDuration(long duration); + public abstract void setDuration(long duration); /** * Gets the length of the animation. diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java index 4a6c460..0016459 100644 --- a/core/java/android/animation/AnimatorInflater.java +++ b/core/java/android/animation/AnimatorInflater.java @@ -52,9 +52,8 @@ public class AnimatorInflater { private static final int VALUE_TYPE_FLOAT = 0; private static final int VALUE_TYPE_INT = 1; private static final int VALUE_TYPE_DOUBLE = 2; - private static final int VALUE_TYPE_LONG = 3; - private static final int VALUE_TYPE_COLOR = 4; - private static final int VALUE_TYPE_CUSTOM = 5; + private static final int VALUE_TYPE_COLOR = 3; + private static final int VALUE_TYPE_CUSTOM = 4; /** * Loads an {@link Animator} object from a resource @@ -193,113 +192,56 @@ public class AnimatorInflater { int valueType = a.getInt(com.android.internal.R.styleable.Animator_valueType, VALUE_TYPE_FLOAT); - if (anim == null) { - anim = new ValueAnimator(); - } + Object valueFrom = null; + Object valueTo = null; TypeEvaluator evaluator = null; - boolean hasFrom = a.hasValue(com.android.internal.R.styleable.Animator_valueFrom); - boolean hasTo = a.hasValue(com.android.internal.R.styleable.Animator_valueTo); switch (valueType) { - - case VALUE_TYPE_FLOAT: { - float valueFrom; - float valueTo; - if (hasFrom) { + case VALUE_TYPE_FLOAT: + if (a.hasValue(com.android.internal.R.styleable.Animator_valueFrom)) { valueFrom = a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f); - if (hasTo) { - valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setFloatValues(valueFrom, valueTo); - } else { - anim.setFloatValues(valueFrom); - } - } else { + } + if (a.hasValue(com.android.internal.R.styleable.Animator_valueTo)) { valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setFloatValues(valueTo); } - } - break; - + break; case VALUE_TYPE_COLOR: evaluator = new RGBEvaluator(); - anim.setEvaluator(evaluator); // fall through to pick up values - case VALUE_TYPE_INT: { - int valueFrom; - int valueTo; - if (hasFrom) { + case VALUE_TYPE_INT: + if (a.hasValue(com.android.internal.R.styleable.Animator_valueFrom)) { valueFrom = a.getInteger(com.android.internal.R.styleable.Animator_valueFrom, 0); - if (hasTo) { - valueTo = a.getInteger(com.android.internal.R.styleable.Animator_valueTo, 0); - anim.setIntValues(valueFrom, valueTo); - } else { - anim.setIntValues(valueFrom); - } - } else { - valueTo = a.getInteger(com.android.internal.R.styleable.Animator_valueTo, 0); - anim.setIntValues(valueTo); } - } - break; - - case VALUE_TYPE_LONG: { - int valueFrom; - int valueTo; - if (hasFrom) { - valueFrom = a.getInteger(com.android.internal.R.styleable.Animator_valueFrom, 0); - if (hasTo) { - valueTo = a.getInteger(com.android.internal.R.styleable.Animator_valueTo, 0); - anim.setLongValues(valueFrom, valueTo); - } else { - anim.setLongValues(valueFrom); - } - } else { + if (a.hasValue(com.android.internal.R.styleable.Animator_valueTo)) { valueTo = a.getInteger(com.android.internal.R.styleable.Animator_valueTo, 0); - anim.setLongValues(valueTo); } - } - break; - - case VALUE_TYPE_DOUBLE: { - double valueFrom; - double valueTo; - if (hasFrom) { - valueFrom = a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f); - if (hasTo) { - valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setDoubleValues(valueFrom, valueTo); - } else { - anim.setDoubleValues(valueFrom); - } - } else { - valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setDoubleValues(valueTo); + break; + case VALUE_TYPE_DOUBLE: + if (a.hasValue(com.android.internal.R.styleable.Animator_valueFrom)) { + valueFrom = (Double)((Float)(a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f))).doubleValue(); } - } - break; - - case VALUE_TYPE_CUSTOM: { + if (a.hasValue(com.android.internal.R.styleable.Animator_valueTo)) { + valueTo = (Double)((Float)a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f)).doubleValue(); + } + break; + case VALUE_TYPE_CUSTOM: // TODO: How to get an 'Object' value? - float valueFrom; - float valueTo; - if (hasFrom) { + if (a.hasValue(com.android.internal.R.styleable.Animator_valueFrom)) { valueFrom = a.getFloat(com.android.internal.R.styleable.Animator_valueFrom, 0f); - if (hasTo) { - valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setFloatValues(valueFrom, valueTo); - } else { - anim.setFloatValues(valueFrom); - } - } else { + } + if (a.hasValue(com.android.internal.R.styleable.Animator_valueTo)) { valueTo = a.getFloat(com.android.internal.R.styleable.Animator_valueTo, 0f); - anim.setFloatValues(valueTo); } - } - break; + break; } + if (anim == null) { + anim = new ValueAnimator(duration, valueFrom, valueTo); + } else { + anim.setDuration(duration); + anim.setValues(valueFrom, valueTo); + } - anim.setDuration(duration); anim.setStartDelay(startDelay); if (a.hasValue(com.android.internal.R.styleable.Animator_repeatCount)) { diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java index 8fc45f4..5de0293 100644 --- a/core/java/android/animation/AnimatorSet.java +++ b/core/java/android/animation/AnimatorSet.java @@ -328,7 +328,7 @@ public final class AnimatorSet extends Animator { * animations of this AnimatorSet. */ @Override - public AnimatorSet setDuration(long duration) { + public void setDuration(long duration) { if (duration < 0) { throw new IllegalArgumentException("duration must be a value of zero or greater"); } @@ -338,7 +338,6 @@ public final class AnimatorSet extends Animator { node.animation.setDuration(duration); } mDuration = duration; - return this; } /** @@ -385,8 +384,7 @@ public final class AnimatorSet extends Animator { } } else { // TODO: Need to cancel out of the delay appropriately - ValueAnimator delayAnim = ValueAnimator.ofFloat(0f, 1f); - delayAnim.setDuration(mStartDelay); + ValueAnimator delayAnim = new ValueAnimator(mStartDelay, 0f, 1f); delayAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator anim) { for (Node node : nodesToStart) { @@ -931,9 +929,7 @@ public final class AnimatorSet extends Animator { */ public void after(long delay) { // setup dummy ValueAnimator just to run the clock - ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); - anim.setDuration(delay); - after(anim); + after(new ValueAnimator(delay, 0f, 1f)); } } diff --git a/core/java/android/animation/KeyframeSet.java b/core/java/android/animation/KeyframeSet.java index 1741e60..a24b1fb 100644 --- a/core/java/android/animation/KeyframeSet.java +++ b/core/java/android/animation/KeyframeSet.java @@ -17,7 +17,6 @@ package android.animation; import java.util.ArrayList; -import java.util.Arrays; /** * This class holds a collection of Keyframe objects and is called by ValueAnimator to calculate @@ -32,83 +31,10 @@ class KeyframeSet { public KeyframeSet(Keyframe... keyframes) { mKeyframes = new ArrayList<Keyframe>(); - mKeyframes.addAll(Arrays.asList(keyframes)); - mNumKeyframes = mKeyframes.size(); - } - - public static KeyframeSet ofInt(int... values) { - int numKeyframes = values.length; - Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; - if (numKeyframes == 1) { - keyframes[0] = new Keyframe(0f, (Object) null); - keyframes[1] = new Keyframe(1f, values[0]); - } else { - keyframes[0] = new Keyframe(0f, values[0]); - for (int i = 1; i < numKeyframes; ++i) { - keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]); - } + for (Keyframe keyframe : keyframes) { + mKeyframes.add(keyframe); } - return new KeyframeSet(keyframes); - } - - public static KeyframeSet ofFloat(float... values) { - int numKeyframes = values.length; - Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; - if (numKeyframes == 1) { - keyframes[0] = new Keyframe(0f, (Object) null); - keyframes[1] = new Keyframe(1f, values[0]); - } else { - keyframes[0] = new Keyframe(0f, values[0]); - for (int i = 1; i < numKeyframes; ++i) { - keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]); - } - } - return new KeyframeSet(keyframes); - } - - public static KeyframeSet ofDouble(double... values) { - int numKeyframes = values.length; - Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; - if (numKeyframes == 1) { - keyframes[0] = new Keyframe(0f, (Object) null); - keyframes[1] = new Keyframe(1f, values[0]); - } else { - keyframes[0] = new Keyframe(0f, values[0]); - for (int i = 1; i < numKeyframes; ++i) { - keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]); - } - } - return new KeyframeSet(keyframes); - } - - public static KeyframeSet ofLong(long... values) { - int numKeyframes = values.length; - Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; - if (numKeyframes == 1) { - keyframes[0] = new Keyframe(0f, (Object) null); - keyframes[1] = new Keyframe(1f, values[0]); - } else { - keyframes[0] = new Keyframe(0f, values[0]); - for (int i = 1; i < numKeyframes; ++i) { - keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]); - } - } - return new KeyframeSet(keyframes); - } - - public static KeyframeSet ofObject(Object... values) { - int numKeyframes = values.length; - Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; - if (numKeyframes == 1) { - keyframes[0] = new Keyframe(0f, (Object) null); - keyframes[1] = new Keyframe(1f, values[0]); - } else { - keyframes[0] = new Keyframe(0f, values[0]); - for (int i = 1; i < numKeyframes; ++i) { - keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]); - } - } - return new KeyframeSet(keyframes); + mNumKeyframes = mKeyframes.size(); } /** diff --git a/core/java/android/animation/LayoutTransition.java b/core/java/android/animation/LayoutTransition.java index d843737..56ad857 100644 --- a/core/java/android/animation/LayoutTransition.java +++ b/core/java/android/animation/LayoutTransition.java @@ -189,24 +189,23 @@ public class LayoutTransition { public LayoutTransition() { if (defaultChangeIn == null) { // "left" is just a placeholder; we'll put real properties/values in when needed - PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 1); - PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 1); - PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", 0, 1); - PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom", 0, 1); - defaultChangeIn = ObjectAnimator.ofPropertyValuesHolder(this, + PropertyValuesHolder<Integer> pvhLeft = new PropertyValuesHolder<Integer>("left", 0, 1); + PropertyValuesHolder<Integer> pvhTop = new PropertyValuesHolder<Integer>("top", 0, 1); + PropertyValuesHolder<Integer> pvhRight = new PropertyValuesHolder<Integer>("right", 0, 1); + PropertyValuesHolder<Integer> pvhBottom = new PropertyValuesHolder<Integer>("bottom", 0, 1); + defaultChangeIn = new ObjectAnimator<PropertyValuesHolder>(DEFAULT_DURATION, this, pvhLeft, pvhTop, pvhRight, pvhBottom); - defaultChangeIn.setDuration(DEFAULT_DURATION); defaultChangeIn.setStartDelay(mChangingAppearingDelay); defaultChangeIn.setInterpolator(mChangingAppearingInterpolator); defaultChangeOut = defaultChangeIn.clone(); defaultChangeOut.setStartDelay(mChangingDisappearingDelay); defaultChangeOut.setInterpolator(mChangingDisappearingInterpolator); - defaultFadeIn = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f); - defaultFadeIn.setDuration(DEFAULT_DURATION); + defaultFadeIn = + new ObjectAnimator<Float>(DEFAULT_DURATION, this, "alpha", 0f, 1f); defaultFadeIn.setStartDelay(mAppearingDelay); defaultFadeIn.setInterpolator(mAppearingInterpolator); - defaultFadeOut = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f); - defaultFadeOut.setDuration(DEFAULT_DURATION); + defaultFadeOut = + new ObjectAnimator<Float>(DEFAULT_DURATION, this, "alpha", 1f, 0f); defaultFadeOut.setStartDelay(mDisappearingDelay); defaultFadeOut.setInterpolator(mDisappearingInterpolator); } diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java index 135dfdb..31ddb0b 100644 --- a/core/java/android/animation/ObjectAnimator.java +++ b/core/java/android/animation/ObjectAnimator.java @@ -27,7 +27,7 @@ import java.lang.reflect.Method; * are then determined internally and the animation will call these functions as necessary to * animate the property. */ -public final class ObjectAnimator extends ValueAnimator { +public final class ObjectAnimator<T> extends ValueAnimator<T> { // The target object on which the property exists, set in the constructor private Object mTarget; @@ -122,146 +122,53 @@ public final class ObjectAnimator extends ValueAnimator { * A constructor that takes a single property name and set of values. This constructor is * used in the simple case of animating a single property. * + * @param duration The length of the animation, in milliseconds. * @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 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. */ - private ObjectAnimator(Object target, String propertyName) { + public ObjectAnimator(long duration, Object target, String propertyName, T...values) { + super(duration, (T[]) values); 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 <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 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 <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 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 <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 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 <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 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 <code>PropertyValueHolder</code> 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 <code>setName()</code>, where <code>name</code> is * the name of the property passed in as the <code>propertyName</code> 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 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; + public ObjectAnimator(long duration, Object target, PropertyValuesHolder...values) { + super(duration); + setValues(values); + mTarget = target; } - /** - * Constructs and returns an ObjectAnimator that animates between the sets of values - * specifed in <code>PropertyValueHolder</code> 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 <code>setName()</code>, where <code>name</code> is - * the name of the property passed in as the <code>propertyName</code> 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; + @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); + } } + /** * This function is called immediately before processing the first animation * frame of an animation. If there is a nonzero <code>startDelay</code>, the @@ -287,21 +194,6 @@ public final class ObjectAnimator extends ValueAnimator { } } - /** - * Sets the length of the animation. The default duration is 300 milliseconds. - * - * @param duration The length of the animation, in milliseconds. - * @return ObjectAnimator The object called with setDuration(). This return - * value makes it easier to compose statements together that construct and then set the - * duration, as in - * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>. - */ - @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 d546f31..1d46123 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 PropertyValuesHolder implements Cloneable { +public class PropertyValuesHolder<T> implements Cloneable { /** * The name of the property associated with the values. This need not be a real property, @@ -118,88 +118,22 @@ public class PropertyValuesHolder implements Cloneable { private Object mAnimatedValue; /** - * Internal utility constructor, used by the factory methods to set the property name. - * @param propertyName The name of the property for this holder. + * Constructs a PropertyValuesHolder object with just a set of values. This constructor + * is typically not used when animating objects with ObjectAnimator, because that + * object needs distinct and meaningful property names. Simpler animations of one + * set of values using ValueAnimator may use this constructor, however, because no + * distinguishing name is needed. + * @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. */ - private PropertyValuesHolder(String propertyName) { - mPropertyName = propertyName; - } - - /** - * Constructs and returns a PropertyValuesHolder with a given property name and - * set of int values. - * @param propertyName The name of the property being animated. - * @param values The values that the named property will animate between. - * @return PropertyValuesHolder The constructed PropertyValuesHolder object. - */ - public static PropertyValuesHolder ofInt(String propertyName, int... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setIntValues(values); - return pvh; - } - - /** - * Constructs and returns a PropertyValuesHolder with a given property name and - * set of float values. - * @param propertyName The name of the property being animated. - * @param values The values that the named property will animate between. - * @return PropertyValuesHolder The constructed PropertyValuesHolder object. - */ - public static PropertyValuesHolder ofFloat(String propertyName, float... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setFloatValues(values); - return pvh; - } - - /** - * Constructs and returns a PropertyValuesHolder with a given property name and - * set of double values. - * @param propertyName The name of the property being animated. - * @param values The values that the named property will animate between. - * @return PropertyValuesHolder The constructed PropertyValuesHolder object. - */ - public static PropertyValuesHolder ofDouble(String propertyName, double... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setDoubleValues(values); - return pvh; - } - - /** - * Constructs and returns a PropertyValuesHolder with a given property name and - * set of long values. - * @param propertyName The name of the property being animated. - * @param values The values that the named property will animate between. - * @return PropertyValuesHolder The constructed PropertyValuesHolder object. - */ - public static PropertyValuesHolder ofLong(String propertyName, long... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setLongValues(values); - return pvh; - } - - /** - * Constructs and returns a PropertyValuesHolder with a given property name and - * set of Object values. This variant also takes a TypeEvaluator because the system - * cannot interpolate between objects of unknown type. - * - * @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 values that the named property will animate between. - * @return PropertyValuesHolder The constructed PropertyValuesHolder object. - */ - public static PropertyValuesHolder ofObject(String propertyName, TypeEvaluator evaluator, - Object... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setObjectValues(values); - pvh.setEvaluator(evaluator); - return pvh; + public PropertyValuesHolder(T...values) { + this(null, values); } /** - * Constructs and returns a PropertyValuesHolder object with the specified property name and set - * of values. These values can be of any type, but the type should be consistent so that + * Constructs a PropertyValuesHolder object with the specified property name and set of + * values. These values can be of any type, but the type should be consistent so that * an appropriate {@link android.animation.TypeEvaluator} can be found that matches * the common type. * <p>If there is only one value, it is assumed to be the end value of an animation, @@ -217,120 +151,9 @@ public class PropertyValuesHolder implements Cloneable { * ValueAnimator object. * @param values The set of values to animate between. */ - public static PropertyValuesHolder ofKeyframe(String propertyName, Keyframe... values) { - PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); - pvh.setKeyframes(values); - return pvh; - } - - /** - * Set the animated values for this object to this set of ints. - * 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 <code>propertyName</code> 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 <code>propertyName</code> 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 <code>propertyName</code> 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 <code>propertyName</code> 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 <code>propertyName</code> 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); + public PropertyValuesHolder(String propertyName, T... values) { + mPropertyName = propertyName; + setValues(values); } /** @@ -346,7 +169,6 @@ public class PropertyValuesHolder implements Cloneable { * no way of determining what the value should be. * @param values The set of values to animate between. */ - /* public void setValues(T... values) { int numKeyframes = values.length; for (int i = 0; i < numKeyframes; ++i) { @@ -388,7 +210,6 @@ public class PropertyValuesHolder implements Cloneable { } mKeyframeSet = new KeyframeSet(keyframes); } - */ @@ -530,7 +351,7 @@ public class PropertyValuesHolder implements Cloneable { setupGetter(targetClass); } try { - kf.setValue(mGetter.invoke(target)); + kf.setValue((T) mGetter.invoke(target)); } catch (InvocationTargetException e) { Log.e("PropertyValuesHolder", e.toString()); } catch (IllegalAccessException e) { @@ -553,7 +374,7 @@ public class PropertyValuesHolder implements Cloneable { Class targetClass = target.getClass(); setupGetter(targetClass); } - kf.setValue(mGetter.invoke(target)); + kf.setValue((T) mGetter.invoke(target)); } catch (InvocationTargetException e) { Log.e("PropertyValuesHolder", e.toString()); } catch (IllegalAccessException e) { @@ -593,7 +414,9 @@ public class PropertyValuesHolder implements Cloneable { for (int i = 0; i < numKeyframes; ++i) { newKeyframes[i] = keyframes.get(i).clone(); } - return PropertyValuesHolder.ofKeyframe(mPropertyName, newKeyframes); + PropertyValuesHolder pvhClone = new PropertyValuesHolder(mPropertyName, + (Object[]) newKeyframes); + return pvhClone; } /** * Internal function to set the value on the target object, using the setter set up diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index 8aa2995..a6f061d 100755 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -37,7 +37,7 @@ import java.util.HashMap; * out of an animation. This behavior can be changed by calling * {@link ValueAnimator#setInterpolator(TimeInterpolator)}.</p> */ -public class ValueAnimator extends Animator { +public class ValueAnimator<T> extends Animator { /** * Internal constants @@ -154,7 +154,7 @@ public class ValueAnimator extends Animator { // // How long the animation should last in ms - private long mDuration = 300; + private long mDuration; // The amount of time in ms to delay starting the animation after start() is called private long mStartDelay = 0; @@ -218,261 +218,28 @@ public class ValueAnimator extends Animator { /** * Creates a new ValueAnimator object. This default constructor is primarily for - * use internally; the factory methods which take parameters are more generally + * use internally; the other constructors which take parameters are more generally * useful. */ public ValueAnimator() { } /** - * Constructs and returns a ValueAnimator 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. + * Constructs an ValueAnimator object with the specified duration and set of + * values. If the values are a set of PropertyValuesHolder objects, then these objects + * define the potentially multiple properties being animated and the values the properties are + * animated between. Otherwise, the values define a single set of values animated between. * - * @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 ofInt(int... values) { - ValueAnimator anim = new ValueAnimator(); - anim.setIntValues(values); - 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 - * 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 ofFloat(float... values) { - ValueAnimator anim = new ValueAnimator(); - anim.setFloatValues(values); - return anim; - } - - /** - * Constructs and returns a ValueAnimator 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 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 ofDouble(double... values) { - ValueAnimator anim = new ValueAnimator(); - anim.setDoubleValues(values); - return anim; - } - - /** - * Constructs and returns a ValueAnimator 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 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 ofLong(long... values) { - ValueAnimator anim = new ValueAnimator(); - anim.setLongValues(values); - return anim; - } - - /** - * Constructs and returns a ValueAnimator that animates between the values - * specified in 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 ValueAnimator ofPropertyValuesHolder(PropertyValuesHolder... values) { - ValueAnimator anim = new ValueAnimator(); - anim.setValues(values); - return anim; - } - /** - * Constructs and returns a ValueAnimator that animates between Object 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. - * - * <p>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. - * - * <p>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.</p> - * - * @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. - * - * <p>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.</p> - * - * @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. - * - * <p>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.</p> - * - * @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. - * - * <p>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.</p> - * - * @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. - * - * <p>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.</p> - * - * <p>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.</p> - * - * @param values The set of values to animate between. + * @param duration The length of the animation, in milliseconds. + * @param values The set of values to animate between. If these values are not + * PropertyValuesHolder objects, then there should be more than one value, since the values + * determine the interval 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); + public ValueAnimator(long duration, T...values) { + mDuration = duration; + if (values.length > 0) { + setValues(values); } - // New property/values/target should cause re-initialization prior to starting - mInitialized = false; } /** @@ -508,6 +275,30 @@ public class ValueAnimator extends Animator { } /** + * Sets the values to animate between for this animation. If <code>values</code> 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 <code>startDelay</code>, the * function is called after that delay ends. @@ -530,20 +321,16 @@ public class ValueAnimator extends Animator { /** - * Sets the length of the animation. The default duration is 300 milliseconds. + * Sets the length of the animation. * * @param duration The length of the animation, in milliseconds. - * @return ValueAnimator The object called with setDuration(). This return - * value makes it easier to compose statements together that construct and then set the - * duration, as in <code>ValueAnimator.ofInt(0, 10).setDuration(500).start()</code>. */ - public ValueAnimator setDuration(long duration) { + public void setDuration(long duration) { mDuration = duration; - return this; } /** - * Gets the length of the animation. The default duration is 300 milliseconds. + * Gets the length of the animation. * * @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 b5934b0..b7b1a23 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<Adapter> /** * In and out animations. */ - ObjectAnimator mInAnimation; - ObjectAnimator mOutAnimation; + ObjectAnimator<?> mInAnimation; + ObjectAnimator<?> mOutAnimation; private ArrayList<View> mViewsToBringToFront; @@ -246,16 +246,12 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> } } - ObjectAnimator getDefaultInAnimation() { - ObjectAnimator anim = ObjectAnimator.ofFloat(null, "alpha", 0.0f, 1.0f); - anim.setDuration(DEFAULT_ANIMATION_DURATION); - return anim; + ObjectAnimator<?> getDefaultInAnimation() { + return new ObjectAnimator<Float>(DEFAULT_ANIMATION_DURATION, null, "alpha", 0.0f, 1.0f); } - ObjectAnimator getDefaultOutAnimation() { - ObjectAnimator anim = ObjectAnimator.ofFloat(null, "alpha", 1.0f, 0.0f); - anim.setDuration(DEFAULT_ANIMATION_DURATION); - return anim; + ObjectAnimator<?> getDefaultOutAnimation() { + return new ObjectAnimator<Float>(DEFAULT_ANIMATION_DURATION, null, "alpha", 1.0f, 0.0f); } /** @@ -696,10 +692,10 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * * @return An Animation or null if none is set. * - * @see #setInAnimation(android.animation.ObjectAnimator) + * @see #setInAnimation(android.view.animation.Animation) * @see #setInAnimation(android.content.Context, int) */ - public ObjectAnimator getInAnimation() { + public ObjectAnimator<?> getInAnimation() { return mInAnimation; } @@ -711,7 +707,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #getInAnimation() * @see #setInAnimation(android.content.Context, int) */ - public void setInAnimation(ObjectAnimator inAnimation) { + public void setInAnimation(ObjectAnimator<?> inAnimation) { mInAnimation = inAnimation; } @@ -720,10 +716,10 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * * @return An Animation or null if none is set. * - * @see #setOutAnimation(android.animation.ObjectAnimator) + * @see #setOutAnimation(android.view.animation.Animation) * @see #setOutAnimation(android.content.Context, int) */ - public ObjectAnimator getOutAnimation() { + public ObjectAnimator<?> getOutAnimation() { return mOutAnimation; } @@ -735,7 +731,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #getOutAnimation() * @see #setOutAnimation(android.content.Context, int) */ - public void setOutAnimation(ObjectAnimator outAnimation) { + public void setOutAnimation(ObjectAnimator<?> outAnimation) { mOutAnimation = outAnimation; } @@ -746,10 +742,10 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @param resourceID The resource id of the animation. * * @see #getInAnimation() - * @see #setInAnimation(android.animation.ObjectAnimator) + * @see #setInAnimation(android.view.animation.Animation) */ public void setInAnimation(Context context, int resourceID) { - setInAnimation((ObjectAnimator) AnimatorInflater.loadAnimator(context, resourceID)); + setInAnimation((ObjectAnimator<?>) AnimatorInflater.loadAnimator(context, resourceID)); } /** @@ -759,10 +755,10 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @param resourceID The resource id of the animation. * * @see #getOutAnimation() - * @see #setOutAnimation(android.animation.ObjectAnimator) + * @see #setOutAnimation(android.view.animation.Animation) */ public void setOutAnimation(Context context, int resourceID) { - setOutAnimation((ObjectAnimator) AnimatorInflater.loadAnimator(context, resourceID)); + setOutAnimation((ObjectAnimator<?>) AnimatorInflater.loadAnimator(context, resourceID)); } /** diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index 7e01506..f0954e2 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -175,8 +175,8 @@ public class StackView extends AdapterViewAnimator { } view.setVisibility(VISIBLE); - ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1.0f); - fadeIn.setDuration(DEFAULT_ANIMATION_DURATION); + ObjectAnimator<Float> fadeIn = new ObjectAnimator<Float>(DEFAULT_ANIMATION_DURATION, + view, "alpha", view.getAlpha(), 1.0f); fadeIn.start(); } else if (fromIndex == mNumActiveViews - 1 && toIndex == mNumActiveViews - 2) { // Slide item in @@ -186,11 +186,12 @@ public class StackView extends AdapterViewAnimator { int duration = Math.round(mStackSlider.getDurationForNeutralPosition(mYVelocity)); StackSlider animationSlider = new StackSlider(mStackSlider); - PropertyValuesHolder slideInY = PropertyValuesHolder.ofFloat("YProgress", 0.0f); - PropertyValuesHolder slideInX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, + PropertyValuesHolder<Float> slideInY = + new PropertyValuesHolder<Float>("YProgress", 0.0f); + PropertyValuesHolder<Float> slideInX = + new PropertyValuesHolder<Float>("XProgress", 0.0f); + ObjectAnimator pa = new ObjectAnimator(duration, animationSlider, slideInX, slideInY); - pa.setDuration(duration); pa.setInterpolator(new LinearInterpolator()); pa.start(); } else if (fromIndex == mNumActiveViews - 2 && toIndex == mNumActiveViews - 1) { @@ -200,11 +201,12 @@ public class StackView extends AdapterViewAnimator { int duration = Math.round(mStackSlider.getDurationForOffscreenPosition(mYVelocity)); StackSlider animationSlider = new StackSlider(mStackSlider); - PropertyValuesHolder slideOutY = PropertyValuesHolder.ofFloat("YProgress", 1.0f); - PropertyValuesHolder slideOutX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, - slideOutX, slideOutY); - pa.setDuration(duration); + PropertyValuesHolder<Float> slideOutY = + new PropertyValuesHolder<Float>("YProgress", 1.0f); + PropertyValuesHolder<Float> slideOutX = + new PropertyValuesHolder<Float>("XProgress", 0.0f); + ObjectAnimator pa = new ObjectAnimator(duration, animationSlider, + slideOutX, slideOutY); pa.setInterpolator(new LinearInterpolator()); pa.start(); } else if (fromIndex == -1 && toIndex == mNumActiveViews - 1) { @@ -215,8 +217,8 @@ public class StackView extends AdapterViewAnimator { lp.setVerticalOffset(-mSlideAmount); } else if (toIndex == -1) { // Fade item out - ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 0.0f); - fadeOut.setDuration(DEFAULT_ANIMATION_DURATION); + ObjectAnimator<Float> fadeOut = new ObjectAnimator<Float> + (DEFAULT_ANIMATION_DURATION, view, "alpha", view.getAlpha(), 0.0f); fadeOut.start(); } @@ -234,8 +236,8 @@ public class StackView extends AdapterViewAnimator { float r = (index * 1.0f) / (mNumActiveViews - 2); float scale = 1 - PERSPECTIVE_SCALE_FACTOR * (1 - r); - PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", scale); - PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", scale); + PropertyValuesHolder<Float> scaleX = new PropertyValuesHolder<Float>("scaleX", scale); + PropertyValuesHolder<Float> scaleY = new PropertyValuesHolder<Float>("scaleY", scale); r = (float) Math.pow(r, 2); @@ -245,9 +247,9 @@ public class StackView extends AdapterViewAnimator { (mMeasuredHeight * (1 - PERSPECTIVE_SHIFT_FACTOR) / 2.0f); float transY = perspectiveTranslation + scaleShiftCorrection; - PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(view, scaleX, scaleY, translationY); - pa.setDuration(100); + PropertyValuesHolder<Float> translationY = + new PropertyValuesHolder<Float>("translationY", transY); + ObjectAnimator pa = new ObjectAnimator(100, view, scaleX, scaleY, translationY); pa.start(); } @@ -536,11 +538,12 @@ public class StackView extends AdapterViewAnimator { } StackSlider animationSlider = new StackSlider(mStackSlider); - PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress); - PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, + PropertyValuesHolder<Float> snapBackY = + new PropertyValuesHolder<Float>("YProgress", finalYProgress); + PropertyValuesHolder<Float> snapBackX = + new PropertyValuesHolder<Float>("XProgress", 0.0f); + ObjectAnimator pa = new ObjectAnimator(duration, animationSlider, snapBackX, snapBackY); - pa.setDuration(duration); pa.setInterpolator(new LinearInterpolator()); pa.start(); } else if (mSwipeGestureType == GESTURE_SLIDE_DOWN) { @@ -554,12 +557,12 @@ public class StackView extends AdapterViewAnimator { } StackSlider animationSlider = new StackSlider(mStackSlider); - PropertyValuesHolder snapBackY = - PropertyValuesHolder.ofFloat("YProgress",finalYProgress); - PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, + PropertyValuesHolder<Float> snapBackY = + new PropertyValuesHolder<Float>("YProgress", finalYProgress); + PropertyValuesHolder<Float> snapBackX = + new PropertyValuesHolder<Float>("XProgress", 0.0f); + ObjectAnimator pa = new ObjectAnimator(duration, animationSlider, snapBackX, snapBackY); - pa.setDuration(duration); pa.start(); } diff --git a/core/java/com/android/internal/widget/DrawableHolder.java b/core/java/com/android/internal/widget/DrawableHolder.java index 958cabb..d53860c 100644 --- a/core/java/com/android/internal/widget/DrawableHolder.java +++ b/core/java/com/android/internal/widget/DrawableHolder.java @@ -41,8 +41,8 @@ public class DrawableHolder implements AnimatorListener { private float mScaleY = 1.0f; private BitmapDrawable mDrawable; private float mAlpha = 1f; - private ArrayList<ObjectAnimator> mAnimators = new ArrayList<ObjectAnimator>(); - private ArrayList<ObjectAnimator> mNeedToStart = new ArrayList<ObjectAnimator>(); + private ArrayList<ObjectAnimator<Float>> mAnimators = new ArrayList<ObjectAnimator<Float>>(); + private ArrayList<ObjectAnimator<Float>> mNeedToStart = new ArrayList<ObjectAnimator<Float>>(); public DrawableHolder(BitmapDrawable drawable) { this(drawable, 0.0f, 0.0f); @@ -67,13 +67,12 @@ public class DrawableHolder implements AnimatorListener { * @param toValue the target value * @param replace if true, replace the current animation with this one. */ - public ObjectAnimator addAnimTo(long duration, long delay, + public ObjectAnimator<Float> addAnimTo(long duration, long delay, String property, float toValue, boolean replace) { if (replace) removeAnimationFor(property); - ObjectAnimator anim = ObjectAnimator.ofFloat(this, property, toValue); - anim.setDuration(duration); + ObjectAnimator<Float> anim = new ObjectAnimator<Float>(duration, this, property, toValue); anim.setStartDelay(delay); anim.setInterpolator(EASE_OUT_INTERPOLATOR); this.addAnimation(anim, replace); @@ -87,8 +86,8 @@ public class DrawableHolder implements AnimatorListener { * @param property */ public void removeAnimationFor(String property) { - ArrayList<ObjectAnimator> removalList = new ArrayList<ObjectAnimator>(); - for (ObjectAnimator currentAnim : mAnimators) { + ArrayList<ObjectAnimator<Float>> removalList = new ArrayList<ObjectAnimator<Float>>(); + for (ObjectAnimator<Float> currentAnim : mAnimators) { if (property.equals(currentAnim.getPropertyName())) { currentAnim.cancel(); removalList.add(currentAnim); @@ -102,7 +101,7 @@ public class DrawableHolder implements AnimatorListener { * Stops all animations and removes them from the list. */ public void clearAnimations() { - for (ObjectAnimator currentAnim : mAnimators) { + for (ObjectAnimator<Float> currentAnim : mAnimators) { currentAnim.cancel(); } mAnimators.clear(); @@ -115,7 +114,7 @@ public class DrawableHolder implements AnimatorListener { * @param overwrite * @return */ - private DrawableHolder addAnimation(ObjectAnimator anim, boolean overwrite) { + private DrawableHolder addAnimation(ObjectAnimator<Float> anim, boolean overwrite) { if (anim != null) mAnimators.add(anim); mNeedToStart.add(anim); @@ -149,7 +148,7 @@ public class DrawableHolder implements AnimatorListener { */ public void startAnimations(ValueAnimator.AnimatorUpdateListener listener) { for (int i = 0; i < mNeedToStart.size(); i++) { - ObjectAnimator anim = mNeedToStart.get(i); + ObjectAnimator<Float> anim = mNeedToStart.get(i); anim.addUpdateListener(listener); anim.addListener(this); anim.start(); |