Updating code to use new non-generified animator APIs

Change-Id: Ie1928a22f774b226d90fa0918f61dba35d183dd6
diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java
index aff8ddd..cc6a149 100644
--- a/src/com/android/launcher2/AllAppsTabbed.java
+++ b/src/com/android/launcher2/AllAppsTabbed.java
@@ -103,7 +103,8 @@
                 // animate the changing of the tab content by fading pages in and out
                 final int duration = 150;
                 final float alpha = mAllApps.getAlpha();
-                ValueAnimator alphaAnim = new ObjectAnimator(duration, mAllApps, "alpha", alpha, 0.0f);
+                ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
+                        setDuration(duration);
                 alphaAnim.addListener(new AnimatorListenerAdapter() {
                     public void onAnimationEnd(Animator animation) {
                         String tag = getCurrentTabTag();
@@ -118,9 +119,8 @@
                         }
 
                         final float alpha = mAllApps.getAlpha();
-                        ValueAnimator alphaAnim =
-                            new ObjectAnimator(duration, mAllApps, "alpha", alpha, 1.0f);
-                        alphaAnim.start();
+                        ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
+                                setDuration(duration).start();
                     }
                 });
                 alphaAnim.start();
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 3c6a8aa..c7c850b 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -94,7 +94,7 @@
     // These arrays are used to implement the drag visualization on x-large screens.
     // They are used as circular arrays, indexed by mDragOutlineCurrent.
     private Point[] mDragOutlines = new Point[8];
-    private int[] mDragOutlineAlphas = new int[mDragOutlines.length];
+    private float[] mDragOutlineAlphas = new float[mDragOutlines.length];
     private InterruptibleInOutAnimator[] mDragOutlineAnims =
             new InterruptibleInOutAnimator[mDragOutlines.length];
 
@@ -175,13 +175,13 @@
         // Set up the animation for fading the crosshairs in and out
         int animDuration = res.getInteger(R.integer.config_crosshairsFadeInTime);
         mCrosshairsAnimator = new InterruptibleInOutAnimator(animDuration, 0.0f, 1.0f);
-        mCrosshairsAnimator.addUpdateListener(new AnimatorUpdateListener() {
+        mCrosshairsAnimator.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
             public void onAnimationUpdate(ValueAnimator animation) {
                 mCrosshairsVisibility = ((Float) animation.getAnimatedValue()).floatValue();
                 CellLayout.this.invalidate();
             }
         });
-        mCrosshairsAnimator.setInterpolator(interp);
+        mCrosshairsAnimator.getAnimator().setInterpolator(interp);
 
         for (int i = 0; i < mDragOutlines.length; i++) {
             mDragOutlines[i] = new Point(-1, -1);
@@ -192,8 +192,8 @@
         // behind the drag path.
         // Set up all the animations that are used to implement this fading.
         final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
-        final int fromAlphaValue = 0;
-        final int toAlphaValue = res.getInteger(R.integer.config_dragOutlineMaxAlpha);
+        final float fromAlphaValue = 0;
+        final float toAlphaValue = (float)res.getInteger(R.integer.config_dragOutlineMaxAlpha);
 
         for (int i = 0; i < mDragOutlineAlphas.length; i++) {
             mDragOutlineAlphas[i] = fromAlphaValue;
@@ -202,10 +202,9 @@
         for (int i = 0; i < mDragOutlineAnims.length; i++) {
             final InterruptibleInOutAnimator anim =
                 new InterruptibleInOutAnimator(duration, fromAlphaValue, toAlphaValue);
-            anim.setInterpolator(interp);
-
+            anim.getAnimator().setInterpolator(interp);
             final int thisIndex = i;
-            anim.addUpdateListener(new AnimatorUpdateListener() {
+            anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
                 public void onAnimationUpdate(ValueAnimator animation) {
                     final Bitmap outline = (Bitmap)anim.getTag();
 
@@ -221,7 +220,7 @@
                         // Try to prevent it from continuing to run
                         animation.cancel();
                     } else {
-                        mDragOutlineAlphas[thisIndex] = (Integer) animation.getAnimatedValue();
+                        mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                         final int left = mDragOutlines[thisIndex].x;
                         final int top = mDragOutlines[thisIndex].y;
                         CellLayout.this.invalidate(left, top,
@@ -231,9 +230,9 @@
             });
             // The animation holds a reference to the drag outline bitmap as long is it's
             // running. This way the bitmap can be GCed when the animations are complete.
-            anim.addListener(new AnimatorListenerAdapter() {
+            anim.getAnimator().addListener(new AnimatorListenerAdapter() {
                 public void onAnimationEnd(Animator animation) {
-                    if ((Integer) anim.getAnimatedValue() == 0) {
+                    if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                         anim.setTag(null);
                     }
                 }
@@ -311,11 +310,11 @@
 
         final Paint paint = new Paint();
         for (int i = 0; i < mDragOutlines.length; i++) {
-            final int alpha = mDragOutlineAlphas[i];
+            final float alpha = mDragOutlineAlphas[i];
             if (alpha > 0) {
                 final Point p = mDragOutlines[i];
                 final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
-                paint.setAlpha(alpha);
+                paint.setAlpha((int)(alpha + .5f));
                 canvas.drawBitmap(b, p.x, p.y, paint);
             }
         }
diff --git a/src/com/android/launcher2/InterruptibleInOutAnimator.java b/src/com/android/launcher2/InterruptibleInOutAnimator.java
index 0b2f345..bed7e6b 100644
--- a/src/com/android/launcher2/InterruptibleInOutAnimator.java
+++ b/src/com/android/launcher2/InterruptibleInOutAnimator.java
@@ -18,6 +18,7 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.util.Log;
 
@@ -28,10 +29,11 @@
  * be exactly reversed. Using this class, both the 'in' and the 'out' animation use the
  * interpolator in the same direction.
  */
-public class InterruptibleInOutAnimator extends ValueAnimator {
+public class InterruptibleInOutAnimator {
     private long mOriginalDuration;
-    private Object mOriginalFromValue;
-    private Object mOriginalToValue;
+    private float mOriginalFromValue;
+    private float mOriginalToValue;
+    private ValueAnimator mAnimator;
 
     private boolean mFirstRun = true;
 
@@ -41,41 +43,41 @@
     private static final int IN = 1;
     private static final int OUT = 2;
 
+
     private int mDirection = STOPPED;
 
-    public InterruptibleInOutAnimator(long duration, Object fromValue, Object toValue) {
-        super(duration, fromValue, toValue);
+    public InterruptibleInOutAnimator(long duration, float fromValue, float toValue) {
+        mAnimator = ValueAnimator.ofFloat(fromValue, toValue).setDuration(duration);
         mOriginalDuration = duration;
         mOriginalFromValue = fromValue;
         mOriginalToValue = toValue;
     }
 
     private void animate(int direction) {
-        final long currentPlayTime = getCurrentPlayTime();
-        final Object toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue;
-        final Object startValue = mFirstRun ? mOriginalFromValue : getAnimatedValue();
+        final long currentPlayTime = mAnimator.getCurrentPlayTime();
+        final float toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue;
+        final float startValue = mFirstRun ? mOriginalFromValue :
+                ((Float) mAnimator.getAnimatedValue()).floatValue();
 
         // Make sure it's stopped before we modify any values
         cancel();
 
         if (startValue != toValue) {
             mDirection = direction;
-            setDuration(mOriginalDuration - currentPlayTime);
-            setValues(startValue, toValue);
-            start();
+            mAnimator.setDuration(mOriginalDuration - currentPlayTime);
+            mAnimator.setFloatValues(startValue, toValue);
+            mAnimator.start();
             mFirstRun = false;
         }
     }
 
-    @Override
     public void cancel() {
-        super.cancel();
+        mAnimator.cancel();
         mDirection = STOPPED;
     }
 
-    @Override
     public void end() {
-        super.end();
+        mAnimator.end();
         mDirection = STOPPED;
     }
 
@@ -112,4 +114,8 @@
     public Object getTag() {
         return mTag;
     }
+
+    public ValueAnimator getAnimator() {
+        return mAnimator;
+    }
 }
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index d7c2f5b..6fcf432 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -318,8 +318,9 @@
                     // animate the changing of the tab content by fading pages in and out
                     final int duration = 150;
                     final float alpha = mCustomizePagedView.getAlpha();
-                    ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
+                    ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
                             "alpha", alpha, 0.0f);
+                    alphaAnim.setDuration(duration);
                     alphaAnim.addListener(new AnimatorListenerAdapter() {
                         public void onAnimationEnd(Animator animation) {
                             String tag = mHomeCustomizationDrawer.getCurrentTabTag();
@@ -341,8 +342,9 @@
                             }
 
                             final float alpha = mCustomizePagedView.getAlpha();
-                            ValueAnimator alphaAnim = new ObjectAnimator(duration,
+                            ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
                                     mCustomizePagedView, "alpha", alpha, 1.0f);
+                            alphaAnim.setDuration(duration);
                             alphaAnim.start();
                         }
                     });
@@ -2284,7 +2286,8 @@
                 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
 
         if (seq != null) {
-            Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
+            Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
+            anim.setDuration(duration);
             anim.addListener(new AnimatorListenerAdapter() {
                 public void onAnimationStart(Animator animation) {
                     if (showing) showToolbarButton(view);
@@ -2383,9 +2386,10 @@
         }
 
         if (animated) {
-            ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
-                    new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
-                    new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
+            ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
+                    PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
+                    PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
+            scaleAnim.setDuration(duration);
             scaleAnim.setInterpolator(new DecelerateInterpolator());
             scaleAnim.addListener(new AnimatorListenerAdapter() {
                 public void onAnimationStart(Animator animation) {
@@ -2445,9 +2449,10 @@
         if (animated) {
             if (mStateAnimation != null) mStateAnimation.cancel();
             mStateAnimation = new AnimatorSet();
-            ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
-                    new PropertyValuesHolder<Float>("scaleX", scaleFactor),
-                    new PropertyValuesHolder<Float>("scaleY", scaleFactor));
+            ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
+                    PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
+                    PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
+            scaleAnim.setDuration(duration);
             scaleAnim.setInterpolator(new AccelerateInterpolator());
             mStateAnimation.addListener(new AnimatorListenerAdapter() {
                 public void onAnimationEnd(Animator animation) {
@@ -2522,10 +2527,13 @@
             AnimatorSet toolbarShowAnim = new AnimatorSet();
             hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
 
-            mStateAnimation.playTogether(
-                    toolbarHideAnim,
-                    new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
-                    new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
+            ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
+                    fromViewStartY, fromViewEndY);
+            fromAnim.setDuration(duration);
+            ObjectAnimator toAnim = ObjectAnimator.ofFloat(toView, "y",
+                    toViewStartY, toViewEndY);
+            fromAnim.setDuration(duration);
+            mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
 
             // Show the new toolbar buttons just as the main animation is ending
             final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 75e39e0..4de18221 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -16,6 +16,7 @@
 
 package com.android.launcher2;
 
+import android.animation.AnimatorListenerAdapter;
 import com.android.launcher.R;
 
 import android.animation.Animator;
@@ -80,8 +81,8 @@
     private static final int BACKGROUND_FADE_IN_DURATION = 100;
 
     // These animators are used to fade the background
-    private ObjectAnimator<Float> mBackgroundFadeInAnimation;
-    private ObjectAnimator<Float> mBackgroundFadeOutAnimation;
+    private ObjectAnimator mBackgroundFadeInAnimation;
+    private ObjectAnimator mBackgroundFadeOutAnimation;
     private float mBackgroundAlpha = 0;
 
     private final WallpaperManager mWallpaperManager;
@@ -194,15 +195,13 @@
         LauncherApplication app = (LauncherApplication)context.getApplicationContext();
         mIconCache = app.getIconCache();
 
-        mUnshrinkAnimationListener = new AnimatorListener() {
+        mUnshrinkAnimationListener = new AnimatorListenerAdapter() {
             public void onAnimationStart(Animator animation) {
                 mIsInUnshrinkAnimation = true;
             }
             public void onAnimationEnd(Animator animation) {
                 mIsInUnshrinkAnimation = false;
             }
-            public void onAnimationCancel(Animator animation) {}
-            public void onAnimationRepeat(Animator animation) {}
         };
 
         mSnapVelocity = 600;
@@ -477,8 +476,8 @@
         if (!mIsSmall && !mIsInUnshrinkAnimation) {
             if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
             if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
-            mBackgroundFadeInAnimation = new ObjectAnimator<Float>(BACKGROUND_FADE_IN_DURATION,
-                    this, new PropertyValuesHolder<Float>("backgroundAlpha", 1.0f));
+            mBackgroundFadeInAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 1.0f);
+            mBackgroundFadeInAnimation.setDuration(BACKGROUND_FADE_IN_DURATION);
             mBackgroundFadeInAnimation.start();
         }
     }
@@ -487,8 +486,8 @@
         if (!mIsSmall && !mIsInUnshrinkAnimation) {
             if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
             if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
-            mBackgroundFadeOutAnimation = new ObjectAnimator<Float>(BACKGROUND_FADE_OUT_DURATION,
-                    this, new PropertyValuesHolder<Float>("backgroundAlpha", 0.0f));
+            mBackgroundFadeOutAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 0.0f);
+            mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
             mBackgroundFadeOutAnimation.setStartDelay(BACKGROUND_FADE_OUT_DELAY);
             mBackgroundFadeOutAnimation.start();
         }
@@ -750,16 +749,18 @@
 
             if (animated) {
                 final int duration = res.getInteger(R.integer.config_workspaceShrinkTime);
-                new ObjectAnimator<Float>(duration, cl,
-                        new PropertyValuesHolder<Float>("x", newX),
-                        new PropertyValuesHolder<Float>("y", newY),
-                        new PropertyValuesHolder<Float>("scaleX",
+                ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(cl,
+                        PropertyValuesHolder.ofFloat("x", newX),
+                        PropertyValuesHolder.ofFloat("y", newY),
+                        PropertyValuesHolder.ofFloat("scaleX",
                                 SHRINK_FACTOR * rotationScaleX * extraShrinkFactor),
-                        new PropertyValuesHolder<Float>("scaleY",
+                        PropertyValuesHolder.ofFloat("scaleY",
                                 SHRINK_FACTOR * rotationScaleY * extraShrinkFactor),
-                        new PropertyValuesHolder<Float>("backgroundAlpha", finalAlpha),
-                        new PropertyValuesHolder<Float>("alpha", finalAlpha),
-                        new PropertyValuesHolder<Float>("rotationY", rotation)).start();
+                        PropertyValuesHolder.ofFloat("backgroundAlpha", finalAlpha),
+                        PropertyValuesHolder.ofFloat("alpha", finalAlpha),
+                        PropertyValuesHolder.ofFloat("rotationY", rotation));
+                anim.setDuration(duration);
+                anim.start();
             } else {
                 cl.setX((int)newX);
                 cl.setY((int)newY);
@@ -902,14 +903,15 @@
                 }
 
                 if (animated) {
+
                     s.playTogether(
-                            new ObjectAnimator<Float>(duration, cl, "translationX", 0.0f),
-                            new ObjectAnimator<Float>(duration, cl, "translationY", 0.0f),
-                            new ObjectAnimator<Float>(duration, cl, "scaleX", 1.0f),
-                            new ObjectAnimator<Float>(duration, cl, "scaleY", 1.0f),
-                            new ObjectAnimator<Float>(duration, cl, "backgroundAlpha", 0.0f),
-                            new ObjectAnimator<Float>(duration, cl, "alpha", finalAlphaValue),
-                            new ObjectAnimator<Float>(duration, cl, "rotationY", rotation));
+                            ObjectAnimator.ofFloat(cl, "translationX", 0.0f).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "translationY", 0.0f).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "scaleX", 1.0f).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "scaleY", 1.0f).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "backgroundAlpha", 0.0f).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "alpha", finalAlphaValue).setDuration(duration),
+                            ObjectAnimator.ofFloat(cl, "rotationY", rotation).setDuration(duration));
                 } else {
                     cl.setTranslationX(0.0f);
                     cl.setTranslationY(0.0f);