Revert "Revert "Adding a separate state for QuickScrub""

This reverts commit 2687257c9881f44243924db7a064cff4f59fcc1b.

Reason for revert: Reverting post-build

Change-Id: Ic3a1e8ed84a227b42bc35b91d4f0eed60bb2e29c
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index a5af173..91f74a6 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -218,7 +218,7 @@
     private LauncherTransitionAnimator composeRecentsLaunchAnimator(View v,
             RemoteAnimationTargetCompat[] targets) {
         // Ensure recents is actually visible
-        if (!mLauncher.isInState(LauncherState.OVERVIEW)) {
+        if (!mLauncher.getStateManager().getState().overviewUi) {
             return null;
         }
 
@@ -720,7 +720,7 @@
                 postAtFrontOfQueueAsynchronously(handler, () -> {
                     if ((Utilities.getPrefs(mLauncher)
                             .getBoolean("pref_use_screenshot_for_swipe_up", false)
-                            && mLauncher.isInState(LauncherState.OVERVIEW))
+                            && mLauncher.getStateManager().getState().overviewUi)
                             || !launcherIsATargetWithMode(targets, MODE_OPENING)) {
                         // We use a separate transition for Overview mode. And we can skip the
                         // animation in cases where Launcher is not in the set of opening targets.
diff --git a/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java
new file mode 100644
index 0000000..acd4fc1
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.uioverrides;
+
+import com.android.launcher3.Launcher;
+
+/**
+ * Extension of overview state used for QuickScrub
+ */
+public class FastOverviewState extends OverviewState {
+
+    private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_DISABLE_RESTORE
+            | FLAG_PAGE_BACKGROUNDS | FLAG_DISABLE_INTERACTION | FLAG_OVERVIEW_UI;
+
+    private static final boolean DEBUG_DIFFERENT_UI = false;
+
+    public FastOverviewState(int id) {
+        super(id, STATE_FLAGS);
+    }
+
+    @Override
+    public float getHoseatAlpha(Launcher launcher) {
+        if (DEBUG_DIFFERENT_UI) {
+            return 0;
+        }
+        return super.getHoseatAlpha(launcher);
+    }
+}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/IgnoreTouchesInQuickScrub.java b/quickstep/src/com/android/launcher3/uioverrides/IgnoreTouchesInQuickScrub.java
deleted file mode 100644
index 2d5eb5a..0000000
--- a/quickstep/src/com/android/launcher3/uioverrides/IgnoreTouchesInQuickScrub.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.uioverrides;
-
-import android.view.MotionEvent;
-
-import com.android.launcher3.util.TouchController;
-import com.android.quickstep.TouchInteractionService;
-
-/**
- * Consumes touches when quick scrub is enabled.
- */
-public class IgnoreTouchesInQuickScrub implements TouchController {
-
-    public IgnoreTouchesInQuickScrub() {
-    }
-
-    @Override
-    public boolean onControllerTouchEvent(MotionEvent ev) {
-        return true;
-    }
-
-    @Override
-    public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
-        return TouchInteractionService.isQuickScrubEnabled();
-    }
-}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
index 77fb842..3f305e9 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
@@ -34,10 +34,14 @@
 public class OverviewState extends LauncherState {
 
     private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED
-            | FLAG_DISABLE_RESTORE | FLAG_PAGE_BACKGROUNDS;
+            | FLAG_DISABLE_RESTORE | FLAG_PAGE_BACKGROUNDS | FLAG_OVERVIEW_UI;
 
     public OverviewState(int id) {
-        super(id, ContainerType.TASKSWITCHER, OVERVIEW_TRANSITION_MS, STATE_FLAGS);
+        this(id, STATE_FLAGS);
+    }
+
+    protected OverviewState(int id, int stateFlags) {
+        super(id, ContainerType.TASKSWITCHER, OVERVIEW_TRANSITION_MS, stateFlags);
     }
 
     @Override
diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
index 80ecb92..4542431 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
@@ -60,10 +60,10 @@
 
     @Override
     public void setState(LauncherState state) {
-        mWorkspaceCard.setWorkspaceScrollingEnabled(state == OVERVIEW);
-        setVisibility(state == OVERVIEW);
-        setTransitionProgress(state == OVERVIEW ? 1 : 0);
-        if (state == OVERVIEW) {
+        mWorkspaceCard.setWorkspaceScrollingEnabled(state.overviewUi);
+        setVisibility(state.overviewUi);
+        setTransitionProgress(state.overviewUi ? 1 : 0);
+        if (state.overviewUi) {
             for (int i = mRecentsView.getFirstTaskIndex(); i < mRecentsView.getPageCount(); i++) {
                 ((TaskView) mRecentsView.getPageAt(i)).resetVisualProperties();
             }
@@ -92,20 +92,20 @@
         }
 
         ObjectAnimator progressAnim =
-                mTransitionProgress.animateToValue(toState == OVERVIEW ? 1 : 0);
+                mTransitionProgress.animateToValue(toState.overviewUi ? 1 : 0);
         progressAnim.setDuration(config.duration);
         progressAnim.setInterpolator(Interpolators.LINEAR);
         progressAnim.addListener(new AnimationSuccessListener() {
 
             @Override
             public void onAnimationSuccess(Animator animator) {
-                mWorkspaceCard.setWorkspaceScrollingEnabled(toState == OVERVIEW);
+                mWorkspaceCard.setWorkspaceScrollingEnabled(toState.overviewUi);
                 mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen());
             }
         });
         builder.play(progressAnim);
 
-        ObjectAnimator visibilityAnim = animateVisibility(toState == OVERVIEW);
+        ObjectAnimator visibilityAnim = animateVisibility(toState.overviewUi);
         visibilityAnim.setDuration(config.duration);
         visibilityAnim.setInterpolator(Interpolators.LINEAR);
         builder.play(visibilityAnim);
diff --git a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
index 71cdd10..7f98935 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
@@ -43,13 +43,11 @@
     public static TouchController[] createTouchControllers(Launcher launcher) {
         if (FeatureFlags.ENABLE_TWO_SWIPE_TARGETS) {
             return new TouchController[] {
-                    new IgnoreTouchesInQuickScrub(),
                     new EdgeSwipeController(launcher),
                     new TwoStepSwipeController(launcher),
                     new OverviewSwipeController(launcher)};
         } else {
             return new TouchController[] {
-                    new IgnoreTouchesInQuickScrub(),
                     new TwoStepSwipeController(launcher),
                     new OverviewSwipeController(launcher)};
         }
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index c166292..e5af3e5 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -21,6 +21,8 @@
 import static android.view.MotionEvent.ACTION_POINTER_DOWN;
 import static android.view.MotionEvent.ACTION_POINTER_UP;
 import static android.view.MotionEvent.ACTION_UP;
+
+import static com.android.launcher3.LauncherState.FAST_OVERVIEW;
 import static com.android.launcher3.LauncherState.OVERVIEW;
 import static com.android.quickstep.QuickScrubController.QUICK_SWITCH_START_DURATION;
 
@@ -117,7 +119,6 @@
         @Override
         public void onQuickScrubStart() {
             mEventQueue.onQuickScrubStart();
-            sQuickScrubEnabled = true;
             TraceHelper.partitionSection("SysUiBinder", "onQuickScrubStart");
         }
 
@@ -130,23 +131,17 @@
         public void onQuickScrubEnd() {
             mEventQueue.onQuickScrubEnd();
             TraceHelper.endSection("SysUiBinder", "onQuickScrubEnd");
-            sQuickScrubEnabled = false;
         }
     };
 
     private final TouchConsumer mNoOpTouchConsumer = (ev) -> {};
 
     private static boolean sConnected = false;
-    private static boolean sQuickScrubEnabled = false;
 
     public static boolean isConnected() {
         return sConnected;
     }
 
-    public static boolean isQuickScrubEnabled() {
-        return sQuickScrubEnabled;
-    }
-
     private ActivityManagerWrapper mAM;
     private RunningTaskInfo mRunningTask;
     private RecentsModel mRecentsModel;
@@ -190,7 +185,6 @@
     @Override
     public void onDestroy() {
         sConnected = false;
-        sQuickScrubEnabled = false;
         super.onDestroy();
     }
 
@@ -315,7 +309,7 @@
                     } else if (interactionType == INTERACTION_QUICK_SWITCH) {
                         onComplete = mQuickScrubController::onQuickSwitch;
                     }
-                    mLauncher.getStateManager().goToState(OVERVIEW, true, 0,
+                    mLauncher.getStateManager().goToState(FAST_OVERVIEW, true, 0,
                             QUICK_SWITCH_START_DURATION, onComplete);
                 };
 
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 3198790..25f395f 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -15,6 +15,7 @@
  */
 package com.android.quickstep;
 
+import static com.android.launcher3.LauncherState.FAST_OVERVIEW;
 import static com.android.launcher3.LauncherState.OVERVIEW;
 import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
 import static com.android.launcher3.anim.Interpolators.LINEAR;
@@ -493,6 +494,8 @@
     }
 
     private void onQuickInteractionStart() {
+        mLauncher.getStateManager().goToState(FAST_OVERVIEW,
+                mWasLauncherAlreadyVisible || mGestureStarted);
         mQuickScrubController.onQuickScrubStart(false);
     }
 
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index 402d73d..54df1da 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -26,6 +26,7 @@
 
 import com.android.launcher3.uioverrides.AllAppsState;
 import com.android.launcher3.states.SpringLoadedState;
+import com.android.launcher3.uioverrides.FastOverviewState;
 import com.android.launcher3.uioverrides.OverviewState;
 import com.android.launcher3.uioverrides.UiFactory;
 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -46,6 +47,9 @@
     protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5;
     protected static final int FLAG_PAGE_BACKGROUNDS = 1 << 6;
     protected static final int FLAG_ALL_APPS_SCRIM = 1 << 7;
+    protected static final int FLAG_DISABLE_INTERACTION = 1 << 8;
+    protected static final int FLAG_OVERVIEW_UI = 1 << 9;
+
 
     protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
             new PageAlphaProvider(ACCEL_2) {
@@ -55,7 +59,7 @@
                 }
             };
 
-    private static final LauncherState[] sAllStates = new LauncherState[4];
+    private static final LauncherState[] sAllStates = new LauncherState[5];
 
     /**
      * TODO: Create a separate class for NORMAL state.
@@ -69,6 +73,8 @@
 
     public static final LauncherState OVERVIEW = new OverviewState(3);
 
+    public static final LauncherState FAST_OVERVIEW = new FastOverviewState(4);
+
     public final int ordinal;
 
     /**
@@ -114,6 +120,16 @@
      */
     public final boolean disablePageClipping;
 
+    /**
+     * True if launcher can not be directly interacted in this state;
+     */
+    public final boolean disableInteraction;
+
+    /**
+     * True if the state has overview panel visible.
+     */
+    public final boolean overviewUi;
+
     public LauncherState(int id, int containerType, int transitionDuration, int flags) {
         this.containerType = containerType;
         this.transitionDuration = transitionDuration;
@@ -129,6 +145,8 @@
         this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0;
         this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
         this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0;
+        this.disableInteraction = (flags & FLAG_DISABLE_INTERACTION) != 0;
+        this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0;
 
         this.ordinal = id;
         sAllStates[id] = this;
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 7e3335a..301070c 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -172,6 +172,11 @@
             return true;
         }
 
+        if (mLauncher.getStateManager().getState().disableInteraction) {
+            // You Shall Not Pass!!!
+            return true;
+        }
+
         if (mDragController.onControllerInterceptTouchEvent(ev)) {
             mActiveController = mDragController;
             return true;
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 993663e..b3310c7 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -930,7 +930,7 @@
         int centeredTop = centerY - height / 2;
 
         // We need to bound the folder to the currently visible workspace area
-        if (mLauncher.isInState(OVERVIEW)) {
+        if (mLauncher.getStateManager().getState().overviewUi) {
             mLauncher.getDragLayer().getDescendantRectRelativeToSelf(mLauncher.getOverviewPanel(),
                     sTempRect);
         } else {
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/FastOverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/FastOverviewState.java
new file mode 100644
index 0000000..147d194
--- /dev/null
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/FastOverviewState.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.uioverrides;
+
+/**
+ * A dummy overview state
+ */
+public class FastOverviewState extends OverviewState {
+
+    public FastOverviewState(int id) {
+        super(id);
+    }
+}
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java
index 14806c0..37d0aa2 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java
@@ -37,7 +37,7 @@
     private static final float SCALE_FACTOR = 0.7f;
 
     private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE |
-            FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS;
+            FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS | FLAG_OVERVIEW_UI;
 
     public OverviewState(int id) {
         super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, STATE_FLAGS);