Merge "Allowing tracing to be enabled using command line on all build flavors" into ub-launcher3-qt-dev
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java
index dc58a4e..2c42fd6 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java
@@ -17,6 +17,7 @@
 
 import static com.android.launcher3.anim.Interpolators.LINEAR;
 import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
+import static com.android.quickstep.fallback.FallbackRecentsView.ZOOM_PROGRESS;
 import static com.android.quickstep.views.RecentsView.CONTENT_ALPHA;
 
 import android.animation.Animator;
@@ -33,6 +34,7 @@
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.quickstep.fallback.FallbackRecentsView;
 import com.android.quickstep.util.LayoutUtils;
 import com.android.quickstep.util.RemoteAnimationTargetSet;
 import com.android.quickstep.views.RecentsView;
@@ -120,11 +122,14 @@
             return (transitionLength) -> { };
         }
 
-        RecentsView rv = activity.getOverviewPanel();
+        FallbackRecentsView rv = activity.getOverviewPanel();
         rv.setContentAlpha(0);
         rv.getClearAllButton().setVisibilityAlpha(0);
         rv.setDisallowScrollToClearAll(true);
 
+        boolean fromState = !animateActivity;
+        rv.setInOverviewState(fromState);
+
         return new AnimationFactory() {
 
             boolean isAnimatingToRecents = false;
@@ -141,15 +146,28 @@
 
             @Override
             public void createActivityController(long transitionLength) {
-                if (!isAnimatingToRecents) {
-                    return;
+                AnimatorSet animatorSet = new AnimatorSet();
+                if (isAnimatingToRecents) {
+                    ObjectAnimator anim = ObjectAnimator.ofFloat(rv, CONTENT_ALPHA, 0, 1);
+                    anim.setDuration(transitionLength).setInterpolator(LINEAR);
+                    animatorSet.play(anim);
                 }
 
-                ObjectAnimator anim = ObjectAnimator.ofFloat(rv, CONTENT_ALPHA, 0, 1);
+                ObjectAnimator anim = ObjectAnimator.ofFloat(rv, ZOOM_PROGRESS, 1, 0);
                 anim.setDuration(transitionLength).setInterpolator(LINEAR);
-                AnimatorSet animatorSet = new AnimatorSet();
                 animatorSet.play(anim);
-                callback.accept(AnimatorPlaybackController.wrap(animatorSet, transitionLength));
+
+                AnimatorPlaybackController controller =
+                        AnimatorPlaybackController.wrap(animatorSet, transitionLength);
+
+                // Since we are changing the start position of the UI, reapply the state, at the end
+                controller.setEndAction(() -> {
+                    boolean endState = true;
+                    rv.setInOverviewState(controller.getInterpolatedProgress() > 0.5 ?
+                                    endState : fromState);
+                });
+
+                callback.accept(controller);
             }
         };
     }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java
index 5decc3e..32a9261 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java
@@ -125,7 +125,14 @@
             @Override
             public void onCreateAnimation(RemoteAnimationTargetCompat[] targetCompats,
                     AnimationResult result) {
-                result.setAnimation(composeRecentsLaunchAnimator(taskView, targetCompats));
+                AnimatorSet anim = composeRecentsLaunchAnimator(taskView, targetCompats);
+                anim.addListener(new AnimatorListenerAdapter() {
+                    @Override
+                    public void onAnimationEnd(Animator animation) {
+                        mFallbackRecentsView.resetViewUI();
+                    }
+                });
+                result.setAnimation(anim);
             }
         };
         return ActivityOptionsCompat.makeRemoteAnimation(new RemoteAnimationAdapterCompat(
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java
index a5aa1bf..c2876180 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java
@@ -15,19 +15,45 @@
  */
 package com.android.quickstep.fallback;
 
+import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
+
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.util.AttributeSet;
+import android.util.FloatProperty;
 import android.view.View;
 
 import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.LauncherState.ScaleAndTranslation;
+import com.android.launcher3.Utilities;
 import com.android.quickstep.RecentsActivity;
 import com.android.quickstep.util.LayoutUtils;
 import com.android.quickstep.views.RecentsView;
+import com.android.quickstep.views.TaskView;
 
 public class FallbackRecentsView extends RecentsView<RecentsActivity> {
 
+    public static final FloatProperty<FallbackRecentsView> ZOOM_PROGRESS =
+            new FloatProperty<FallbackRecentsView> ("zoomInProgress") {
+
+                @Override
+                public void setValue(FallbackRecentsView view, float value) {
+                    view.setZoomProgress(value);
+                }
+
+                @Override
+                public Float get(FallbackRecentsView view) {
+                    return view.mZoomInProgress;
+                }
+            };
+
+    private float mZoomInProgress = 0;
+    private boolean mInOverviewState = true;
+
+    private float mZoomScale = 1f;
+    private float mZoomTranslationY = 0f;
+
     public FallbackRecentsView(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
@@ -71,4 +97,46 @@
         // Just use the activity task size for multi-window as well.
         return false;
     }
+
+    public void resetViewUI() {
+        setZoomProgress(0);
+        resetTaskVisuals();
+    }
+
+    public void setInOverviewState(boolean inOverviewState) {
+        if (mInOverviewState != inOverviewState) {
+            mInOverviewState = inOverviewState;
+            if (mInOverviewState) {
+                resetTaskVisuals();
+            } else {
+                setZoomProgress(1);
+            }
+        }
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+
+        if (getTaskViewCount() == 0) {
+            mZoomScale = 1f;
+            mZoomTranslationY = 0f;
+        } else {
+            TaskView dummyTask = getTaskViewAt(0);
+            ScaleAndTranslation sat = getTempClipAnimationHelper()
+                    .updateForFullscreenOverview(dummyTask)
+                    .getScaleAndTranslation();
+            mZoomScale = sat.scale;
+            mZoomTranslationY = sat.translationY;
+        }
+
+        setZoomProgress(mZoomInProgress);
+    }
+
+    public void setZoomProgress(float progress) {
+        mZoomInProgress = progress;
+        SCALE_PROPERTY.set(this, Utilities.mapRange(mZoomInProgress, 1, mZoomScale));
+        TRANSLATION_Y.set(this, Utilities.mapRange(mZoomInProgress, 0, mZoomTranslationY));
+        FULLSCREEN_PROGRESS.set(this, mZoomInProgress);
+    }
 }