Stop animating All Apps during transition to Home

One of the sources of jank in launcher is during the All Apps -> Home
transition. specifically, if the user has started a fling operation (where
we are animating between pages in All Apps) and then hits the Home button,
we continue the fling animation while also doing the transition to Home
scale/fade animations. This causes a lot of work for launcher, particularly because
the fling animation is causing the All Apps layer to get recreated on every frame.

The fix is to simply pause the fling animation, then snap to its end state when the
animation to Home is complete. We also need to pause/snap the scroll indicator animation,
because it's fading animation causes the same layer-recreation jank that the fling
itself causes.

Issue #7387124 Home <-> All Apps transition animation is janky while flinging

Change-Id: Icbcaf2d5b3b2f6ce8fd7419419d258248aa1475b
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 56fdbb6..b2fbb3e 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2682,6 +2682,7 @@
 
             dispatchOnLauncherTransitionPrepare(fromView, animated, true);
             dispatchOnLauncherTransitionPrepare(toView, animated, true);
+            mAppsCustomizeContent.pauseScrolling();
 
             mStateAnimation.addListener(new AnimatorListenerAdapter() {
                 @Override
@@ -2696,6 +2697,8 @@
                     if (onCompleteRunnable != null) {
                         onCompleteRunnable.run();
                     }
+                    mAppsCustomizeContent.updateCurrentPageScroll();
+                    mAppsCustomizeContent.resumeScrolling();
                 }
             });
 
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 9b97384..81ce6ea 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -181,6 +181,7 @@
     protected static final int sScrollIndicatorFadeInDuration = 150;
     protected static final int sScrollIndicatorFadeOutDuration = 650;
     protected static final int sScrollIndicatorFlashDuration = 650;
+    private boolean mScrollingPaused = false;
 
     // If set, will defer loading associated pages until the scrolling settles
     private boolean mDeferLoadAssociatedPagesUntilScrollCompletes;
@@ -304,6 +305,24 @@
     }
 
     /**
+     * Called during AllApps/Home transitions to avoid unnecessary work. When that other animation
+     * ends, {@link #resumeScrolling()} should be called, along with
+     * {@link #updateCurrentPageScroll()} to correctly set the final state and re-enable scrolling.
+     */
+    void pauseScrolling() {
+        mScroller.forceFinished(true);
+        cancelScrollingIndicatorAnimations();
+        mScrollingPaused = true;
+    }
+
+    /**
+     * Enables scrolling again.
+     * @see #pauseScrolling()
+     */
+    void resumeScrolling() {
+        mScrollingPaused = false;
+    }
+    /**
      * Sets the current page.
      */
     void setCurrentPage(int currentPage) {
@@ -1743,7 +1762,7 @@
             updateScrollingIndicatorPosition();
             mScrollIndicator.setVisibility(View.VISIBLE);
             cancelScrollingIndicatorAnimations();
-            if (immediately) {
+            if (immediately || mScrollingPaused) {
                 mScrollIndicator.setAlpha(1f);
             } else {
                 mScrollIndicatorAnimator = LauncherAnimUtils.ofFloat(mScrollIndicator, "alpha", 1f);
@@ -1768,7 +1787,7 @@
             // Fade the indicator out
             updateScrollingIndicatorPosition();
             cancelScrollingIndicatorAnimations();
-            if (immediately) {
+            if (immediately || mScrollingPaused) {
                 mScrollIndicator.setVisibility(View.INVISIBLE);
                 mScrollIndicator.setAlpha(0f);
             } else {