Split FallbackActivityControllerHelper for Go

This splits FallbackActivityControllerHelper for Go and non-Go depending
on the underlying recents implementation. We also introduce a
GoActivityControllerHelper implementation as a base class to share the
stubbed methods for the Go ActivityControlHelper implementations.

Bug: 114136250
Test: Manual test NexusLauncher, l3GoWithIconRecents
Change-Id: I8a061bb83a851dd1d9988af17194f3e4aed24bb0
diff --git a/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java b/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java
new file mode 100644
index 0000000..9a18b45
--- /dev/null
+++ b/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java
@@ -0,0 +1,123 @@
+/*
+ * 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.quickstep;
+
+import static com.android.launcher3.anim.Interpolators.LINEAR;
+import static com.android.quickstep.views.IconRecentsView.CONTENT_ALPHA;
+
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.content.ComponentName;
+import android.graphics.Rect;
+
+import androidx.annotation.Nullable;
+
+import com.android.launcher3.anim.AnimatorPlaybackController;
+import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
+import com.android.quickstep.util.RemoteAnimationTargetSet;
+import com.android.quickstep.views.IconRecentsView;
+import com.android.quickstep.views.RecentsView;
+
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+
+/**
+ * {@link ActivityControlHelper} for recents when the default launcher is different than the
+ * currently running one and apps should interact with the {@link RecentsActivity} as opposed
+ * to the in-launcher one.
+ */
+public final class FallbackActivityControllerHelper extends
+        GoActivityControlHelper<RecentsActivity> {
+
+    public FallbackActivityControllerHelper(ComponentName homeComponent) { }
+
+    @Override
+    public AnimationFactory prepareRecentsUI(RecentsActivity activity, boolean activityVisible,
+            boolean animateActivity, Consumer<AnimatorPlaybackController> callback) {
+        if (activityVisible) {
+            return (transitionLength) -> { };
+        }
+
+        IconRecentsView rv = activity.getOverviewPanel();
+        rv.setAlpha(0);
+
+        return new AnimationFactory() {
+
+            boolean isAnimatingToRecents = false;
+
+            @Override
+            public void onRemoteAnimationReceived(RemoteAnimationTargetSet targets) {
+                isAnimatingToRecents = targets != null && targets.isAnimatingHome();
+                if (!isAnimatingToRecents) {
+                    rv.setAlpha(1);
+                }
+                createActivityController(getSwipeUpDestinationAndLength(
+                        activity.getDeviceProfile(), activity, new Rect()));
+            }
+
+            @Override
+            public void createActivityController(long transitionLength) {
+                if (!isAnimatingToRecents) {
+                    return;
+                }
+
+                ObjectAnimator anim = ObjectAnimator.ofFloat(rv, CONTENT_ALPHA, 0, 1);
+                anim.setDuration(transitionLength).setInterpolator(LINEAR);
+                AnimatorSet animatorSet = new AnimatorSet();
+                animatorSet.play(anim);
+                callback.accept(AnimatorPlaybackController.wrap(animatorSet, transitionLength));
+            }
+        };
+    }
+
+    @Override
+    public ActivityInitListener createActivityInitListener(
+            BiPredicate<RecentsActivity, Boolean> onInitListener) {
+        return new RecentsActivityTracker(onInitListener);
+    }
+
+    @Nullable
+    @Override
+    public RecentsActivity getCreatedActivity() {
+        return RecentsActivityTracker.getCurrentActivity();
+    }
+
+    @Nullable
+    @Override
+    public RecentsView getVisibleRecentsView() {
+        RecentsActivity activity = getCreatedActivity();
+        if (activity != null && activity.hasWindowFocus()) {
+            return activity.getOverviewPanel();
+        }
+        return null;
+    }
+
+    @Override
+    public boolean switchToRecentsIfVisible(Runnable onCompleteCallback) {
+        return false;
+    }
+
+    @Override
+    public AlphaProperty getAlphaProperty(RecentsActivity activity) {
+        return activity.getDragLayer().getAlphaProperty(0);
+    }
+
+    @Override
+    public int getContainerType() {
+        return LauncherLogProto.ContainerType.SIDELOADED_LAUNCHER;
+    }
+}
diff --git a/go/quickstep/src/com/android/quickstep/GoActivityControlHelper.java b/go/quickstep/src/com/android/quickstep/GoActivityControlHelper.java
new file mode 100644
index 0000000..7078871
--- /dev/null
+++ b/go/quickstep/src/com/android/quickstep/GoActivityControlHelper.java
@@ -0,0 +1,59 @@
+package com.android.quickstep;
+
+import android.content.Context;
+import android.graphics.Rect;
+
+import com.android.launcher3.BaseDraggingActivity;
+import com.android.launcher3.DeviceProfile;
+import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
+
+/**
+ * Base activity control helper for Go that stubs out most of the functionality that is not needed
+ * for Go.
+ *
+ * @param <T> activity that contains the overview
+ */
+public abstract class GoActivityControlHelper<T extends BaseDraggingActivity> implements
+        ActivityControlHelper<T> {
+
+    @Override
+    public void onTransitionCancelled(T activity, boolean activityVisible) {
+        // Go transitions to overview are all atomic.
+    }
+
+    @Override
+    public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect) {
+        // TODO Implement outRect depending on where the task should animate to.
+        // Go does not support swipe up gesture.
+        return 0;
+    }
+
+    @Override
+    public void onSwipeUpComplete(T activity) {
+        // Go does not support swipe up gesture.
+    }
+
+    @Override
+    public HomeAnimationFactory prepareHomeUI(T activity) {
+        // Go does not support gestures from app to home.
+        return null;
+    }
+
+    @Override
+    public Rect getOverviewWindowBounds(Rect homeBounds, RemoteAnimationTargetCompat target) {
+        // Go does not support gestures to overview.
+        return null;
+    }
+
+    @Override
+    public boolean shouldMinimizeSplitScreen() {
+        // Go does not support split screen.
+        return true;
+    }
+
+    @Override
+    public boolean isInLiveTileMode() {
+        // Go does not support live tiles.
+        return false;
+    }
+}
diff --git a/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java b/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java
index 8f31e9f..76685f3 100644
--- a/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java
+++ b/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java
@@ -18,55 +18,23 @@
 
 import static com.android.launcher3.LauncherState.OVERVIEW;
 
-import android.content.Context;
-import android.graphics.Rect;
-
-import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherInitListener;
-import com.android.launcher3.LauncherState;
 import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
 import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
 import com.android.quickstep.views.IconRecentsView;
-import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
 
 import java.util.function.BiPredicate;
 import java.util.function.Consumer;
 
 /**
- * {@link ActivityControlHelper} for the in-launcher recents. As Go does not support most gestures
- * from app to overview/home, most of this class is stubbed out.
+ * {@link ActivityControlHelper} for the in-launcher recents.
  * TODO: Implement the app to overview animation functionality
  */
-public final class LauncherActivityControllerHelper implements ActivityControlHelper<Launcher>{
-
-    @Override
-    public void onTransitionCancelled(Launcher activity, boolean activityVisible) {
-        LauncherState startState = activity.getStateManager().getRestState();
-        activity.getStateManager().goToState(startState, activityVisible);
-    }
-
-    @Override
-    public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context,
-            Rect outRect) {
-        // TODO Implement outRect depending on where the task should animate to.
-        // Go does not support swipe up gesture.
-        return 0;
-    }
-
-    @Override
-    public void onSwipeUpComplete(Launcher activity) {
-        // Go does not support swipe up gesture.
-    }
-
-    @Override
-    public HomeAnimationFactory prepareHomeUI(Launcher activity) {
-        // Go does not support gestures from app to home.
-        return null;
-    }
+public final class LauncherActivityControllerHelper extends GoActivityControlHelper<Launcher> {
 
     @Override
     public AnimationFactory prepareRecentsUI(Launcher activity,
@@ -126,16 +94,6 @@
     }
 
     @Override
-    public Rect getOverviewWindowBounds(Rect homeBounds, RemoteAnimationTargetCompat target) {
-        return homeBounds;
-    }
-
-    @Override
-    public boolean shouldMinimizeSplitScreen() {
-        return true;
-    }
-
-    @Override
     public AlphaProperty getAlphaProperty(Launcher activity) {
         return activity.getDragLayer().getAlphaProperty(DragLayer.ALPHA_INDEX_SWIPE_UP);
     }
@@ -146,10 +104,4 @@
         return launcher != null ? launcher.getStateManager().getState().containerType
                 : LauncherLogProto.ContainerType.APP;
     }
-
-    @Override
-    public boolean isInLiveTileMode() {
-        // Go does not support live tiles.
-        return false;
-    }
 }
diff --git a/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java
similarity index 100%
rename from quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java
rename to quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java