Synchronizing bouncer duration with page scaling duration.

Change-Id: I9fba381582a083ce2ab26375698c5a6f3d554a1b
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/ChallengeLayout.java b/policy/src/com/android/internal/policy/impl/keyguard/ChallengeLayout.java
index 605a738..8ece559 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/ChallengeLayout.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/ChallengeLayout.java
@@ -59,6 +59,11 @@
     boolean isBouncing();
 
     /**
+     * Returns the duration of the bounce animation.
+     */
+    int getBouncerAnimationDuration();
+
+    /**
      * Set a listener that will respond to changes in bouncer state.
      *
      * @param listener listener to register
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
index e89888c..1ae6454 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
@@ -207,6 +207,7 @@
         ChallengeLayout challenge = slider != null ? slider :
             (ChallengeLayout) findViewById(R.id.multi_pane_challenge);
         challenge.setOnBouncerStateChangedListener(mViewStateManager);
+        mAppWidgetContainer.setBouncerAnimationDuration(challenge.getBouncerAnimationDuration());
         mViewStateManager.setPagedView(mAppWidgetContainer);
         mViewStateManager.setChallengeLayout(challenge);
         mSecurityViewContainer = (KeyguardSecurityViewFlipper) findViewById(R.id.view_flipper);
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
index 7df1512..c21e04f 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
@@ -36,6 +36,7 @@
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
+import android.view.animation.DecelerateInterpolator;
 import android.widget.FrameLayout;
 
 import com.android.internal.widget.LockPatternUtils;
@@ -71,7 +72,7 @@
     private int mWidgetToResetAfterFadeOut;
 
     // Bouncer
-    protected int BOUNCER_ZOOM_IN_OUT_DURATION = 250;
+    private int mBouncerZoomInOutDuration = 250;
     private float BOUNCER_SCALE_FACTOR = 0.67f;
 
     // Background worker thread: used here for persistence, also made available to widget frames
@@ -747,6 +748,10 @@
         }
     }
 
+    void setBouncerAnimationDuration(int duration) {
+        mBouncerZoomInOutDuration = duration;
+    }
+
     // Zoom in after the bouncer is dismissed
     void zoomInFromBouncer() {
         if (mZoomInOutAnim != null && mZoomInOutAnim.isRunning()) {
@@ -755,10 +760,11 @@
         final View currentPage = getPageAt(getCurrentPage());
         if (currentPage.getScaleX() < 1f || currentPage.getScaleY() < 1f) {
             mZoomInOutAnim = new AnimatorSet();
-            mZoomInOutAnim.setDuration(BOUNCER_ZOOM_IN_OUT_DURATION);
             mZoomInOutAnim.playTogether(
                     ObjectAnimator.ofFloat(currentPage, "scaleX", 1f),
                     ObjectAnimator.ofFloat(currentPage , "scaleY", 1f));
+            mZoomInOutAnim.setDuration(mBouncerZoomInOutDuration);
+            mZoomInOutAnim.setInterpolator(new DecelerateInterpolator(1.5f));
             mZoomInOutAnim.start();
         }
     }
@@ -768,18 +774,22 @@
         if (mZoomInOutAnim != null && mZoomInOutAnim.isRunning()) {
             mZoomInOutAnim.cancel();
         }
-        View currentPage = getPageAt(getCurrentPage());
-        currentPage.setPivotY(0);
-        // Note: we are working around the issue that setting the x-pivot to the same value as it
-        //       was does not actually work.
-        currentPage.setPivotX(0);
-        currentPage.setPivotX(currentPage.getMeasuredWidth() / 2);
+        int curPage = getCurrentPage();
+        View currentPage = getPageAt(curPage);
+        if (shouldSetTopAlignedPivotForWidget(curPage)) {
+            currentPage.setPivotY(0);
+            // Note: we are working around the issue that setting the x-pivot to the same value as it
+            //       was does not actually work.
+            currentPage.setPivotX(0);
+            currentPage.setPivotX(currentPage.getMeasuredWidth() / 2);
+        }
         if (!(currentPage.getScaleX() < 1f || currentPage.getScaleY() < 1f)) {
             mZoomInOutAnim = new AnimatorSet();
-            mZoomInOutAnim.setDuration(BOUNCER_ZOOM_IN_OUT_DURATION);
             mZoomInOutAnim.playTogether(
                     ObjectAnimator.ofFloat(currentPage, "scaleX", BOUNCER_SCALE_FACTOR),
                     ObjectAnimator.ofFloat(currentPage, "scaleY", BOUNCER_SCALE_FACTOR));
+            mZoomInOutAnim.setDuration(mBouncerZoomInOutDuration);
+            mZoomInOutAnim.setInterpolator(new DecelerateInterpolator(1.5f));
             mZoomInOutAnim.start();
         }
     }
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/MultiPaneChallengeLayout.java b/policy/src/com/android/internal/policy/impl/keyguard/MultiPaneChallengeLayout.java
index 026f1bd..0ca46c3 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/MultiPaneChallengeLayout.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/MultiPaneChallengeLayout.java
@@ -40,7 +40,7 @@
 
     public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
     public static final int VERTICAL = LinearLayout.VERTICAL;
-    protected static final int ANIMATE_BOUNCE_DURATION = 750;
+    public static final int ANIMATE_BOUNCE_DURATION = 350;
 
     private KeyguardSecurityContainer mChallengeView;
     private View mUserSwitcherView;
@@ -97,6 +97,11 @@
     }
 
     @Override
+    public int getBouncerAnimationDuration() {
+        return ANIMATE_BOUNCE_DURATION;
+    }
+
+    @Override
     public void showBouncer() {
         if (mIsBouncing) return;
         mIsBouncing = true;
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java b/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java
index c734423..15d06f7 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java
@@ -56,7 +56,7 @@
     private static final int DRAG_HANDLE_OPEN_ABOVE = 8; // dp
     private static final int DRAG_HANDLE_OPEN_BELOW = 0; // dp
 
-    private static final int HANDLE_ANIMATE_DURATION = 200; // ms
+    private static final int HANDLE_ANIMATE_DURATION = 250; // ms
 
     // Drawn to show the drag handle in closed state; crossfades to the challenge view
     // when challenge is fully visible
@@ -469,13 +469,26 @@
     }
 
     @Override
+    public int getBouncerAnimationDuration() {
+        return HANDLE_ANIMATE_DURATION;
+    }
+
+    @Override
     public void showBouncer() {
         if (mIsBouncing) return;
         mWasChallengeShowing = mChallengeShowing;
         mIsBouncing = true;
         showChallenge(true);
         if (mScrimView != null) {
-            mScrimView.setVisibility(VISIBLE);
+            Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 1f);
+            anim.setDuration(HANDLE_ANIMATE_DURATION);
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationStart(Animator animation) {
+                    mScrimView.setVisibility(VISIBLE);
+                }
+            });
+            anim.start();
         }
         if (mChallengeView != null) {
             mChallengeView.showBouncer(HANDLE_ANIMATE_DURATION);
@@ -498,8 +511,17 @@
         if (!mIsBouncing) return;
         if (!mWasChallengeShowing) showChallenge(false);
         mIsBouncing = false;
+
         if (mScrimView != null) {
-            mScrimView.setVisibility(GONE);
+            Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 0f);
+            anim.setDuration(HANDLE_ANIMATE_DURATION);
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    mScrimView.setVisibility(GONE);
+                }
+            });
+            anim.start();
         }
         if (mChallengeView != null) {
             mChallengeView.hideBouncer(HANDLE_ANIMATE_DURATION);