diff options
| author | 2010-10-04 13:56:11 -0700 | |
|---|---|---|
| committer | 2010-10-05 11:02:25 -0700 | |
| commit | ef52176f1244a5bb98d82a0c8c7f4351edec17a1 (patch) | |
| tree | e4a298d382e690c0f0f1ba0c857d78ea47f4b3dd | |
| parent | 066b5c5166c1f5342bd42aa0d68f784a5f4c1dd1 (diff) | |
Changing AdapterViewAnimator to use the new animation APIs
Change-Id: Ifefb83c391914ac623d75e0faca723b95786861d
| -rw-r--r-- | api/current.xml | 8 | ||||
| -rw-r--r-- | core/java/android/widget/AdapterViewAnimator.java | 58 | ||||
| -rw-r--r-- | core/java/android/widget/AdapterViewFlipper.java | 17 |
3 files changed, 34 insertions, 49 deletions
diff --git a/api/current.xml b/api/current.xml index 9da64f8cb7ab..c6fc34e856a2 100644 --- a/api/current.xml +++ b/api/current.xml @@ -223783,7 +223783,7 @@ > </method> <method name="getInAnimation" - return="android.view.animation.Animation" + return="android.animation.ObjectAnimator<?>" abstract="false" native="false" synchronized="false" @@ -223794,7 +223794,7 @@ > </method> <method name="getOutAnimation" - return="android.view.animation.Animation" + return="android.animation.ObjectAnimator<?>" abstract="false" native="false" synchronized="false" @@ -223910,7 +223910,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="inAnimation" type="android.view.animation.Animation"> +<parameter name="inAnimation" type="android.animation.ObjectAnimator<?>"> </parameter> </method> <method name="setInAnimation" @@ -223938,7 +223938,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="outAnimation" type="android.view.animation.Animation"> +<parameter name="outAnimation" type="android.animation.ObjectAnimator<?>"> </parameter> </method> <method name="setOutAnimation" diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index 9983d549f692..1d1e601ae71c 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -19,6 +19,7 @@ package android.widget; import java.util.ArrayList; import java.util.HashMap; +import android.animation.AnimatorInflater; import android.animation.ObjectAnimator; import android.content.Context; import android.content.Intent; @@ -135,12 +136,15 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> int mReferenceChildHeight = -1; /** - * TODO: Animation stuff is still in flux, waiting on the new framework to settle a bit. + * In and out animations. */ - Animation mInAnimation; - Animation mOutAnimation; + ObjectAnimator<?> mInAnimation; + ObjectAnimator<?> mOutAnimation; + private ArrayList<View> mViewsToBringToFront; + private static final int DEFAULT_ANIMATION_DURATION = 200; + public AdapterViewAnimator(Context context) { super(context); initViewAnimator(); @@ -155,11 +159,15 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> com.android.internal.R.styleable.AdapterViewAnimator_inAnimation, 0); if (resource > 0) { setInAnimation(context, resource); + } else { + setInAnimation(getDefaultInAnimation()); } resource = a.getResourceId(com.android.internal.R.styleable.AdapterViewAnimator_outAnimation, 0); if (resource > 0) { setOutAnimation(context, resource); + } else { + setOutAnimation(getDefaultOutAnimation()); } boolean flag = a.getBoolean( @@ -229,17 +237,23 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @param view The view that is being animated */ void animateViewForTransition(int fromIndex, int toIndex, View view) { - ObjectAnimator pa; if (fromIndex == -1) { - view.setAlpha(0.0f); - pa = new ObjectAnimator(400, view, "alpha", 0.0f, 1.0f); - pa.start(); + mInAnimation.setTarget(view); + mInAnimation.start(); } else if (toIndex == -1) { - pa = new ObjectAnimator(400, view, "alpha", 1.0f, 0.0f); - pa.start(); + mOutAnimation.setTarget(view); + mOutAnimation.start(); } } + ObjectAnimator<?> getDefaultInAnimation() { + return new ObjectAnimator<Float>(DEFAULT_ANIMATION_DURATION, null, "alpha", 0.0f, 1.0f); + } + + ObjectAnimator<?> getDefaultOutAnimation() { + return new ObjectAnimator<Float>(DEFAULT_ANIMATION_DURATION, null, "alpha", 1.0f, 0.0f); + } + /** * Sets which child view will be displayed. * @@ -265,20 +279,6 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> } /** - * Return default inAnimation. To be overriden by subclasses. - */ - Animation getDefaultInAnimation() { - return null; - } - - /** - * Return default outAnimation. To be overridden by subclasses. - */ - Animation getDefaultOutAnimation() { - return null; - } - - /** * To be overridden by subclasses. This method applies a view / index specific * transform to the child view. * @@ -690,7 +690,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #setInAnimation(android.view.animation.Animation) * @see #setInAnimation(android.content.Context, int) */ - public Animation getInAnimation() { + public ObjectAnimator<?> getInAnimation() { return mInAnimation; } @@ -702,7 +702,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #getInAnimation() * @see #setInAnimation(android.content.Context, int) */ - public void setInAnimation(Animation inAnimation) { + public void setInAnimation(ObjectAnimator<?> inAnimation) { mInAnimation = inAnimation; } @@ -714,7 +714,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #setOutAnimation(android.view.animation.Animation) * @see #setOutAnimation(android.content.Context, int) */ - public Animation getOutAnimation() { + public ObjectAnimator<?> getOutAnimation() { return mOutAnimation; } @@ -726,7 +726,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #getOutAnimation() * @see #setOutAnimation(android.content.Context, int) */ - public void setOutAnimation(Animation outAnimation) { + public void setOutAnimation(ObjectAnimator<?> outAnimation) { mOutAnimation = outAnimation; } @@ -740,7 +740,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #setInAnimation(android.view.animation.Animation) */ public void setInAnimation(Context context, int resourceID) { - setInAnimation(AnimationUtils.loadAnimation(context, resourceID)); + setInAnimation((ObjectAnimator<?>) AnimatorInflater.loadAnimator(context, resourceID)); } /** @@ -753,7 +753,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> * @see #setOutAnimation(android.view.animation.Animation) */ public void setOutAnimation(Context context, int resourceID) { - setOutAnimation(AnimationUtils.loadAnimation(context, resourceID)); + setOutAnimation((ObjectAnimator<?>) AnimatorInflater.loadAnimator(context, resourceID)); } /** diff --git a/core/java/android/widget/AdapterViewFlipper.java b/core/java/android/widget/AdapterViewFlipper.java index 95ebdd31a2f5..b09ade745719 100644 --- a/core/java/android/widget/AdapterViewFlipper.java +++ b/core/java/android/widget/AdapterViewFlipper.java @@ -16,6 +16,7 @@ package android.widget; +import android.animation.ObjectAnimator; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -43,10 +44,8 @@ public class AdapterViewFlipper extends AdapterViewAnimator { private static final boolean LOGD = false; private static final int DEFAULT_INTERVAL = 10000; - private static final int DEFAULT_ANIMATION_DURATION = 200; private int mFlipInterval = DEFAULT_INTERVAL; - private int mAnimationDuration = DEFAULT_ANIMATION_DURATION; private boolean mAutoStart = false; private boolean mRunning = false; @@ -56,7 +55,6 @@ public class AdapterViewFlipper extends AdapterViewAnimator { public AdapterViewFlipper(Context context) { super(context); - initDefaultAnimations(); } public AdapterViewFlipper(Context context, AttributeSet attrs) { @@ -74,19 +72,6 @@ public class AdapterViewFlipper extends AdapterViewAnimator { com.android.internal.R.styleable.AdapterViewAnimator_loopViews, true); a.recycle(); - initDefaultAnimations(); - } - - private void initDefaultAnimations() { - // Set the default animations to be fade in/out - if (mInAnimation == null) { - mInAnimation = new AlphaAnimation(0.0f, 1.0f); - mInAnimation.setDuration(mAnimationDuration); - } - if (mOutAnimation == null) { - mOutAnimation = new AlphaAnimation(1.0f, 0.0f); - mOutAnimation.setDuration(mAnimationDuration); - } } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |