Protecting QSB scroll while transition animation is running.

During transition animation the qorkspace scroll changes while the actual
workspace UI is mostly stable. This causes the QSB to animate while the
pages are not changing.
Bug: 30229069

Change-Id: I66ec41276c0e26164d20da6a5e0e251975390428
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 78ef074..201f0cb 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -53,11 +53,9 @@
 import android.view.View;
 import android.view.ViewDebug;
 import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
 import android.view.accessibility.AccessibilityManager;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
-import android.widget.Space;
 import android.widget.TextView;
 
 import com.android.launcher3.Launcher.CustomContentCallbacks;
@@ -315,6 +313,7 @@
     // Total over scrollX in the overlay direction.
     private float mOverlayTranslation;
     private int mFirstPageScrollX;
+    private boolean mIgnoreQsbScroll;
 
     // Handles workspace state transitions
     private WorkspaceStateTransitionAnimation mStateTransitionAnimation;
@@ -1395,8 +1394,10 @@
     }
 
     private void onWorkspaceOverallScrollChanged() {
-        mLauncher.getQsbContainer().setTranslationX(
-                mOverlayTranslation + mFirstPageScrollX - getScrollX());
+        if (!mIgnoreQsbScroll) {
+            mLauncher.getQsbContainer().setTranslationX(
+                    mOverlayTranslation + mFirstPageScrollX - getScrollX());
+        }
     }
 
     @Override
@@ -1805,6 +1806,33 @@
         super.onLayout(changed, left, top, right, bottom);
         mFirstPageScrollX = getScrollForPage(0);
         onWorkspaceOverallScrollChanged();
+
+        final LayoutTransition transition = getLayoutTransition();
+        // If the transition is running defer updating max scroll, as some empty pages could
+        // still be present, and a max scroll change could cause sudden jumps in scroll.
+        if (transition != null && transition.isRunning()) {
+            transition.addTransitionListener(new LayoutTransition.TransitionListener() {
+
+                @Override
+                public void startTransition(LayoutTransition transition, ViewGroup container,
+                                            View view, int transitionType) {
+                    mIgnoreQsbScroll = true;
+                }
+
+                @Override
+                public void endTransition(LayoutTransition transition, ViewGroup container,
+                                          View view, int transitionType) {
+                    // Wait until all transitions are complete.
+                    if (!transition.isRunning()) {
+                        mIgnoreQsbScroll = false;
+                        transition.removeTransitionListener(this);
+                        mFirstPageScrollX = getScrollForPage(0);
+                        onWorkspaceOverallScrollChanged();
+                    }
+                }
+            });
+        }
+
     }
 
     @Override