Merge "Fixing LauncherState not getting applied in some cases" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
index 1e006e5..7d9cce4 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/PortraitStatesTouchController.java
@@ -207,6 +207,14 @@
     @Override
     protected void updateSwipeCompleteAnimation(ValueAnimator animator, long expectedDuration,
             LauncherState targetState, float velocity, boolean isFling) {
+        handleFirstSwipeToOverview(animator, expectedDuration, targetState, velocity, isFling);
+        super.updateSwipeCompleteAnimation(animator, expectedDuration, targetState,
+                velocity, isFling);
+    }
+
+    private void handleFirstSwipeToOverview(final ValueAnimator animator,
+            final long expectedDuration, final LauncherState targetState, final float velocity,
+            final boolean isFling) {
         if (mFromState == NORMAL && mToState == OVERVIEW && targetState == OVERVIEW) {
             mFinishFastOnSecondTouch = true;
 
@@ -220,7 +228,7 @@
                 // TODO: Clean up these magic calculations
                 // Linearly interpolate the max value based on the velocity.
                 float maxValue = Math.max(absVelocity > 4 ? 1 + MAX_OVERSHOOT :
-                        1 + (absVelocity - 1) * MAX_OVERSHOOT / 3,
+                                1 + (absVelocity - 1) * MAX_OVERSHOOT / 3,
                         currentValue);
                 double angleToPeak = PI_BY_2 - Math.asin(currentValue / maxValue);
 
@@ -248,8 +256,6 @@
 
             if (currentFraction < LINEAR_SCALE_LIMIT) {
                 mAllAppsInterpolatorWrapper.baseInterpolator = LINEAR;
-                super.updateSwipeCompleteAnimation(animator, expectedDuration, targetState,
-                        velocity, isFling);
                 return;
             }
             float extraValue = mAllAppsDampedInterpolator.getInterpolation(currentFraction) - 1;
@@ -267,8 +273,6 @@
             return;
         }
         mFinishFastOnSecondTouch = false;
-        super.updateSwipeCompleteAnimation(animator, expectedDuration, targetState,
-                velocity, isFling);
     }
 
     @Override
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 25f2f87..98597c8 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -749,6 +749,10 @@
     }
 
     private void setupLauncherUiAfterSwipeUpAnimation() {
+        if (mLauncherTransitionController != null) {
+            mLauncherTransitionController.getAnimationPlayer().end();
+            mLauncherTransitionController = null;
+        }
         mActivityControlHelper.onSwipeUpComplete(mActivity);
 
         // Animate the first icon.
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index bac8fc7..6fb8a36 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -46,6 +46,7 @@
 import android.util.SparseBooleanArray;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewDebug;
 
@@ -275,6 +276,13 @@
         }
     }
 
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        super.onTouchEvent(ev);
+        // Do not let touch escape to siblings below this view.
+        return true;
+    }
+
     private void applyLoadPlan(RecentsTaskLoadPlan loadPlan) {
         if (mPendingAnimation != null) {
             mPendingAnimation.addEndListener((b) -> applyLoadPlan(loadPlan));
diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
index 1a63326..baf6d87 100644
--- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java
+++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
@@ -16,9 +16,12 @@
 
 package com.android.launcher3;
 
+import static android.view.MotionEvent.ACTION_DOWN;
+
 import android.app.WallpaperManager;
 import android.content.Context;
 import android.graphics.Rect;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -174,6 +177,15 @@
     }
 
     @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        if (ev.getAction() == ACTION_DOWN && getAlpha() == 0) {
+            // Dont let children handle touch, if we are not visible.
+            return true;
+        }
+        return super.onInterceptTouchEvent(ev);
+    }
+
+    @Override
     public boolean shouldDelayChildPressedState() {
         return false;
     }