Split out recents logic from UiFactory

This CL splits out RecentsView specific logic from UiFactory and
overrides it in the Go IconRecents version, stubbing out much of the
functionality.

Bug: 114136250
Test: Manual test NexusLauncher, Launcher3GoQuickstep
Test: Build Launcher3GoIconRecents
Change-Id: I043f7f2b2581831f1a74a80110e9c4c25231c046
diff --git a/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java
new file mode 100644
index 0000000..f2c9455
--- /dev/null
+++ b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2019 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 static android.view.View.VISIBLE;
+
+import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
+
+import android.view.View;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherStateManager;
+import com.android.launcher3.LauncherStateManager.StateHandler;
+import com.android.launcher3.uioverrides.RecentsViewStateController;
+import com.android.launcher3.util.TouchController;
+
+/**
+ * Provides recents-related {@link UiFactory} logic and classes.
+ */
+public final class RecentsUiFactory {
+
+    // Scale recents takes before animating in
+    private static final float RECENTS_PREPARE_SCALE = 1.33f;
+
+    private RecentsUiFactory() {}
+
+    /**
+     * Creates and returns a touch controller for swiping recents tasks.
+     *
+     * @param launcher the launcher activity
+     * @return the touch controller for recents tasks
+     */
+    public static TouchController createTaskSwipeController(Launcher launcher) {
+        // We leave all input handling to the view itself.
+        return null;
+    }
+
+    /**
+     * Creates and returns the controller responsible for recents view state transitions.
+     *
+     * @param launcher the launcher activity
+     * @return state handler for recents
+     */
+    public static StateHandler createRecentsViewStateController(Launcher launcher) {
+        //TODO Override RecentsViewStateController on low RAM.
+        return new RecentsViewStateController(launcher);
+    }
+
+    /**
+     * Prepare the recents view to animate in.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void prepareToShowRecents(Launcher launcher) {
+        View overview = launcher.getOverviewPanel();
+        if (overview.getVisibility() != VISIBLE) {
+            SCALE_PROPERTY.set(overview, RECENTS_PREPARE_SCALE);
+        }
+    }
+
+    /**
+     * Clean-up logic that occurs when recents is no longer in use/visible.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void resetRecents(Launcher launcher) {}
+
+    /**
+     * Recents logic that triggers when launcher state changes or launcher activity stops/resumes.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void onLauncherStateOrResumeChanged(Launcher launcher) {}
+}
diff --git a/quickstep/recents_ui_overrides/src/.keep b/quickstep/recents_ui_overrides/src/.keep
deleted file mode 100644
index e69de29..0000000
--- a/quickstep/recents_ui_overrides/src/.keep
+++ /dev/null
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java
new file mode 100644
index 0000000..f18f43c
--- /dev/null
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2019 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 static android.view.View.VISIBLE;
+
+import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
+import static com.android.launcher3.LauncherState.NORMAL;
+import static com.android.launcher3.LauncherState.OVERVIEW;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherState;
+import com.android.launcher3.LauncherStateManager.StateHandler;
+import com.android.launcher3.anim.AnimatorPlaybackController;
+import com.android.launcher3.util.TouchController;
+import com.android.quickstep.views.RecentsView;
+
+/**
+ * Provides recents-related {@link UiFactory} logic and classes.
+ */
+public final class RecentsUiFactory {
+
+    // Scale recents takes before animating in
+    private static final float RECENTS_PREPARE_SCALE = 1.33f;
+
+    private RecentsUiFactory() {}
+
+    /**
+     * Creates and returns a touch controller for swiping recents tasks.
+     *
+     * @param launcher the launcher activity
+     * @return the touch controller for recents tasks
+     */
+    public static TouchController createTaskSwipeController(Launcher launcher) {
+        return new LauncherTaskViewController(launcher);
+    }
+
+    /**
+     * Creates and returns the controller responsible for recents view state transitions.
+     *
+     * @param launcher the launcher activity
+     * @return state handler for recents
+     */
+    public static StateHandler createRecentsViewStateController(Launcher launcher) {
+        return new RecentsViewStateController(launcher);
+    }
+
+    /**
+     * Prepare the recents view to animate in.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void prepareToShowRecents(Launcher launcher) {
+        RecentsView overview = launcher.getOverviewPanel();
+        if (overview.getVisibility() != VISIBLE || overview.getContentAlpha() == 0) {
+            SCALE_PROPERTY.set(overview, RECENTS_PREPARE_SCALE);
+        }
+    }
+
+    /**
+     * Clean-up logic that occurs when recents is no longer in use/visible.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void resetRecents(Launcher launcher) {
+        RecentsView recents = launcher.getOverviewPanel();
+        recents.reset();
+    }
+
+    /**
+     * Recents logic that triggers when launcher state changes or launcher activity stops/resumes.
+     *
+     * @param launcher the launcher activity
+     */
+    public static void onLauncherStateOrResumeChanged(Launcher launcher) {
+        LauncherState state = launcher.getStateManager().getState();
+        if (state == NORMAL) {
+            launcher.<RecentsView>getOverviewPanel().setSwipeDownShouldLaunchApp(false);
+        }
+    }
+
+    private static final class LauncherTaskViewController extends
+            TaskViewTouchController<Launcher> {
+
+        LauncherTaskViewController(Launcher activity) {
+            super(activity);
+        }
+
+        @Override
+        protected boolean isRecentsInteractive() {
+            return mActivity.isInState(OVERVIEW);
+        }
+
+        @Override
+        protected void onUserControlledAnimationCreated(AnimatorPlaybackController animController) {
+            mActivity.getStateManager().setCurrentUserControlledAnimation(animController);
+        }
+    }
+}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
index 0ef67c4..3aa6482 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
@@ -16,10 +16,8 @@
 
 package com.android.launcher3.uioverrides;
 
-import static android.view.View.VISIBLE;
 import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
 import static com.android.launcher3.AbstractFloatingView.TYPE_HIDE_BACK_BUTTON;
-import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
 import static com.android.launcher3.LauncherState.ALL_APPS;
 import static com.android.launcher3.LauncherState.NORMAL;
 import static com.android.launcher3.LauncherState.OVERVIEW;
@@ -41,7 +39,6 @@
 import com.android.launcher3.LauncherStateManager;
 import com.android.launcher3.LauncherStateManager.StateHandler;
 import com.android.launcher3.Utilities;
-import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.util.TouchController;
 import com.android.launcher3.util.UiThreadHelper;
@@ -49,7 +46,6 @@
 import com.android.quickstep.OverviewInteractionState;
 import com.android.quickstep.RecentsModel;
 import com.android.quickstep.util.RemoteFadeOutAnimationListener;
-import com.android.quickstep.views.RecentsView;
 import com.android.systemui.shared.system.ActivityCompat;
 import com.android.systemui.shared.system.WindowManagerWrapper;
 
@@ -83,7 +79,11 @@
                 && !launcher.getDeviceProfile().isVerticalBarLayout()) {
             list.add(new StatusBarTouchController(launcher));
         }
-        list.add(new LauncherTaskViewController(launcher));
+        TouchController taskSwipeController =
+                RecentsUiFactory.createTaskSwipeController(launcher);
+        if (taskSwipeController != null) {
+            list.add(taskSwipeController);
+        }
         return list.toArray(new TouchController[list.size()]);
     }
 
@@ -93,7 +93,8 @@
 
     public static StateHandler[] getStateHandler(Launcher launcher) {
         return new StateHandler[] {launcher.getAllAppsController(), launcher.getWorkspace(),
-                new RecentsViewStateController(launcher), new BackButtonAlphaHandler(launcher)};
+                RecentsUiFactory.createRecentsViewStateController(launcher),
+                new BackButtonAlphaHandler(launcher)};
     }
 
     /**
@@ -113,8 +114,7 @@
     }
 
     public static void resetOverview(Launcher launcher) {
-        RecentsView recents = launcher.getOverviewPanel();
-        recents.reset();
+        RecentsUiFactory.resetRecents(launcher);
     }
 
     public static void onCreate(Launcher launcher) {
@@ -186,9 +186,7 @@
                     visible ? 1 : 0, profile.hotseatBarSizePx);
         }
 
-        if (state == NORMAL) {
-            launcher.<RecentsView>getOverviewPanel().setSwipeDownShouldLaunchApp(false);
-        }
+        RecentsUiFactory.onLauncherStateOrResumeChanged(launcher);
     }
 
     public static void onTrimMemory(Context context, int level) {
@@ -242,26 +240,6 @@
     }
 
     public static void prepareToShowOverview(Launcher launcher) {
-        RecentsView overview = launcher.getOverviewPanel();
-        if (overview.getVisibility() != VISIBLE || overview.getContentAlpha() == 0) {
-            SCALE_PROPERTY.set(overview, 1.33f);
-        }
-    }
-
-    private static class LauncherTaskViewController extends TaskViewTouchController<Launcher> {
-
-        public LauncherTaskViewController(Launcher activity) {
-            super(activity);
-        }
-
-        @Override
-        protected boolean isRecentsInteractive() {
-            return mActivity.isInState(OVERVIEW);
-        }
-
-        @Override
-        protected void onUserControlledAnimationCreated(AnimatorPlaybackController animController) {
-            mActivity.getStateManager().setCurrentUserControlledAnimation(animController);
-        }
+        RecentsUiFactory.prepareToShowRecents(launcher);
     }
 }