Adjusting animations for home screen widget reordering.

Change-Id: Ic019b0db8456159d9577acb9a03e24f0d669869b
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index ba20a76..ee759a2 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -17,6 +17,8 @@
 package com.android.launcher2;
 
 import android.animation.Animator;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
@@ -149,7 +151,7 @@
     static final int LANDSCAPE = 0;
     static final int PORTRAIT = 1;
 
-    private static final float REORDER_HINT_MAGNITUDE = 0.27f;
+    private static final float REORDER_HINT_MAGNITUDE = 0.10f;
     private static final int REORDER_ANIMATION_DURATION = 150;
     private float mReorderHintAnimationMagnitude;
 
@@ -1962,7 +1964,7 @@
         View child;
         float deltaX;
         float deltaY;
-        private static final int DURATION = 140;
+        private static final int DURATION = 300;
         private int repeatCount;
         private boolean cancelOnCycleComplete = false;
         ValueAnimator va;
@@ -1991,6 +1993,8 @@
                     deltaY = (int) (Math.sin(angle) * mReorderHintAnimationMagnitude);
                 }
             }
+            child.setPivotY(child.getMeasuredHeight() * 0.5f);
+            child.setPivotX(child.getMeasuredWidth() * 0.5f);
             this.child = child;
         }
 
@@ -2006,7 +2010,7 @@
             va = ValueAnimator.ofFloat(0f, 1f);
             va.setRepeatMode(ValueAnimator.REVERSE);
             va.setRepeatCount(ValueAnimator.INFINITE);
-            va.setDuration(DURATION);
+            va.setDuration((int) (DURATION * (1.0f + Math.random()*.08f)));
             va.addUpdateListener(new AnimatorUpdateListener() {
                 @Override
                 public void onAnimationUpdate(ValueAnimator animation) {
@@ -2015,6 +2019,10 @@
                     float y = r * deltaY;
                     child.setTranslationX(x);
                     child.setTranslationY(y);
+                    float sf = 4.0f / child.getWidth();
+                    float s = 1.0f - r * sf;
+                    child.setScaleX(s);
+                    child.setScaleY(s);
                 }
             });
             va.addListener(new AnimatorListenerAdapter() {
@@ -2035,6 +2043,21 @@
         private void completeAnimation() {
             cancelOnCycleComplete = true;
         }
+        private void completeAnimationImmediately() {
+            va.cancel();
+
+            AnimatorSet s = new AnimatorSet();
+            s.playTogether(
+                ObjectAnimator.ofFloat(child, "scaleX", 1f),
+                ObjectAnimator.ofFloat(child, "scaleY", 1f),
+                ObjectAnimator.ofFloat(child, "translationX", 0f),
+                ObjectAnimator.ofFloat(child, "translationX", 0f)
+            );
+            s.setDuration(REORDER_ANIMATION_DURATION);
+            s.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f));
+            s.start();
+        }
+
 
         // Returns the time required to complete the current oscillating animation
         private int completionTime() {
@@ -2048,7 +2071,7 @@
 
     private void completeAndClearReorderHintAnimations() {
         for (ReorderHintAnimation a: mShakeAnimators.values()) {
-            a.completeAnimation();
+            a.completeAnimationImmediately();
         }
         mShakeAnimators.clear();
     }