OSDN Git Service

Deferring zoom out animation until after snapToPage and animateDragViewToOriginalPosi...
authorWinson Chung <winsonc@google.com>
Tue, 30 Oct 2012 00:43:18 +0000 (17:43 -0700)
committerWinson Chung <winsonc@google.com>
Tue, 30 Oct 2012 00:43:51 +0000 (17:43 -0700)
- Fixing issue where you can long press a widget to reorder while the challenge is up

Change-Id: I6ef2fa050a5ebc35d1c3e373bb27519580ebe03d

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewStateManager.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java
policy/src/com/android/internal/policy/impl/keyguard/PagedView.java

index fb7beba..545b371 100644 (file)
@@ -49,6 +49,13 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
         mChallengeLayout = layout;
     }
 
+    public boolean isChallengeShowing() {
+        if (mChallengeLayout != null) {
+            return mChallengeLayout.isChallengeShowing();
+        }
+        return false;
+    }
+
     public void setSecurityViewContainer(KeyguardSecurityView container) {
         mKeyguardSecurityContainer = container;
     }
index 539cdd1..747ce07 100644 (file)
@@ -510,7 +510,8 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
 
     @Override
     public boolean onLongClick(View v) {
-        if (startReordering()) {
+        // Disallow long pressing to reorder if the challenge is showing
+        if (!mViewStateManager.isChallengeShowing() && startReordering()) {
             return true;
         }
         return false;
index 25ce6d0..657a31f 100644 (file)
@@ -201,9 +201,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     // We use the min scale to determine how much to expand the actually PagedView measured
     // dimensions such that when we are zoomed out, the view is not clipped
     private int REORDERING_DROP_REPOSITION_DURATION = 200;
-    protected int REORDERING_REORDER_REPOSITION_DURATION = 350;
+    protected int REORDERING_REORDER_REPOSITION_DURATION = 300;
     protected int REORDERING_ZOOM_IN_OUT_DURATION = 250;
-    private int REORDERING_SIDE_PAGE_HOVER_TIMEOUT = 500;
+    private int REORDERING_SIDE_PAGE_HOVER_TIMEOUT = 300;
     private float REORDERING_SIDE_PAGE_BUFFER_PERCENTAGE = 0.1f;
     private float mMinScale = 1f;
     protected View mDragView;
@@ -215,6 +215,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     // This variable's scope is for the duration of startReordering() and after the zoomIn()
     // animation after endReordering()
     private boolean mIsReordering;
+    // The runnable that settles the page after snapToPage and animateDragViewToOriginalPosition
+    private int NUM_ANIMATIONS_RUNNING_BEFORE_ZOOM_OUT = 2;
+    private int mPostReorderingPreZoomInRemainingAnimationCount;
+    private Runnable mPostReorderingPreZoomInRunnable;
 
     // Edge swiping
     private boolean mOnlyAllowEdgeSwipes = false;
@@ -536,6 +540,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
                 pageEndMoving();
             }
 
+            onPostReorderingAnimationCompleted();
+
             // Notify the user when the page changes
             AccessibilityManager accessibilityManager = (AccessibilityManager)
                     getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
@@ -1971,13 +1977,19 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
     }
 
     // Animate the drag view back to the original position
-    void animateChildrenToOriginalPosition() {
+    void animateDragViewToOriginalPosition() {
         if (mDragView != null) {
             AnimatorSet anim = new AnimatorSet();
             anim.setDuration(REORDERING_DROP_REPOSITION_DURATION);
             anim.playTogether(
                     ObjectAnimator.ofFloat(mDragView, "translationX", 0f),
                     ObjectAnimator.ofFloat(mDragView, "translationY", 0f));
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    onPostReorderingAnimationCompleted();
+                }
+            });
             anim.start();
         }
     }
@@ -2010,6 +2022,16 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         invalidate();
     }
 
+    private void onPostReorderingAnimationCompleted() {
+        // Trigger the callback when reordering has settled
+        --mPostReorderingPreZoomInRemainingAnimationCount;
+        if (mPostReorderingPreZoomInRunnable != null &&
+                mPostReorderingPreZoomInRemainingAnimationCount == 0) {
+            mPostReorderingPreZoomInRunnable.run();
+            mPostReorderingPreZoomInRunnable = null;
+        }
+    }
+
     protected void onEndReordering() {
         mIsReordering = false;
     }
@@ -2047,21 +2069,28 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
         // In that case, we don't want to do anything.
         if (!mReorderingStarted) return;
         mReorderingStarted = false;
-        Runnable onCompleteRunnable = new Runnable() {
-            @Override
-            public void run() {
-                onEndReordering();
-            }
-        };
-        zoomIn(onCompleteRunnable);
 
         // If we haven't flung-to-delete the current child, then we just animate the drag view
         // back into position
         if (!mIsFlingingToDelete) {
-            // Snap to the current page
-            snapToDestination();
+            mPostReorderingPreZoomInRunnable = new Runnable() {
+                public void run() {
+                    Runnable onCompleteRunnable = new Runnable() {
+                        @Override
+                        public void run() {
+                            onEndReordering();
+                        }
+                    };
+                    zoomIn(onCompleteRunnable);
+                };
+            };
 
-            animateChildrenToOriginalPosition();
+            mPostReorderingPreZoomInRemainingAnimationCount =
+                    NUM_ANIMATIONS_RUNNING_BEFORE_ZOOM_OUT;
+            // Snap to the current page
+            snapToPage(indexOfChild(mDragView), 0);
+            // Animate the drag view back to the front position
+            animateDragViewToOriginalPosition();
         }
     }