OSDN Git Service

Changing AdapterViewAnimator to use the new animation APIs
authorAdam Cohen <adamcohen@google.com>
Mon, 4 Oct 2010 20:56:11 +0000 (13:56 -0700)
committerAdam Cohen <adamcohen@google.com>
Tue, 5 Oct 2010 18:02:25 +0000 (11:02 -0700)
Change-Id: Ifefb83c391914ac623d75e0faca723b95786861d

api/current.xml
core/java/android/widget/AdapterViewAnimator.java
core/java/android/widget/AdapterViewFlipper.java

index 9da64f8..c6fc34e 100644 (file)
 >
 </method>
 <method name="getInAnimation"
- return="android.view.animation.Animation"
+ return="android.animation.ObjectAnimator&lt;?&gt;"
  abstract="false"
  native="false"
  synchronized="false"
 >
 </method>
 <method name="getOutAnimation"
- return="android.view.animation.Animation"
+ return="android.animation.ObjectAnimator&lt;?&gt;"
  abstract="false"
  native="false"
  synchronized="false"
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="inAnimation" type="android.view.animation.Animation">
+<parameter name="inAnimation" type="android.animation.ObjectAnimator&lt;?&gt;">
 </parameter>
 </method>
 <method name="setInAnimation"
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="outAnimation" type="android.view.animation.Animation">
+<parameter name="outAnimation" type="android.animation.ObjectAnimator&lt;?&gt;">
 </parameter>
 </method>
 <method name="setOutAnimation"
index 9983d54..1d1e601 100644 (file)
@@ -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));
     }
 
     /**
index 95ebdd3..b09ade7 100644 (file)
@@ -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() {