Updating launch transition for transparent activities

When a transparent activity is started from recents, animate the launcher
NORMAL state instead of animating the launcher UI separately

Change-Id: Ibfc9f7096f668e0129042b8a69ed5130029df797
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index 12ae85d..b97669b 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -17,6 +17,7 @@
 package com.android.launcher3;
 
 import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
+import static com.android.launcher3.LauncherState.NORMAL;
 import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
 import static com.android.systemui.shared.recents.utilities.Utilities.getNextFrameNumber;
 import static com.android.systemui.shared.recents.utilities.Utilities.getSurface;
@@ -48,6 +49,7 @@
 import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
 import com.android.launcher3.InsettableFrameLayout.LayoutParams;
 import com.android.launcher3.allapps.AllAppsTransitionController;
+import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.anim.PropertyListBuilder;
 import com.android.launcher3.dragndrop.DragLayer;
@@ -227,7 +229,7 @@
         // Resolve the opening task id
         int openingTaskId = -1;
         for (RemoteAnimationTargetCompat target : targets) {
-            if (target.mode == RemoteAnimationTargetCompat.MODE_OPENING) {
+            if (target.mode == MODE_OPENING) {
                 openingTaskId = target.taskId;
                 break;
             }
@@ -247,8 +249,36 @@
         }
 
         // Found a visible recents task that matches the opening app, lets launch the app from there
-        return new LauncherTransitionAnimator(getRecentsLauncherAnimator(recentsView, taskView),
-                getRecentsWindowAnimator(taskView, targets));
+        Animator launcherAnim;
+        AnimatorListenerAdapter windowAnimEndListener;
+        boolean launcherClosing = launcherIsATargetWithMode(targets, MODE_CLOSING);
+        if (launcherClosing) {
+            launcherAnim = getRecentsLauncherAnimator(recentsView, taskView);
+            windowAnimEndListener = new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    // Make sure recents gets fixed up by resetting task alphas and scales, etc.
+                    mLauncher.getStateManager().reapplyState();
+                }
+            };
+        } else {
+            AnimatorPlaybackController controller =
+                    mLauncher.getStateManager()
+                            .createAnimationToNewWorkspace(NORMAL, RECENTS_LAUNCH_DURATION);
+            controller.dispatchOnStart();
+            launcherAnim = controller.getAnimationPlayer().setDuration(RECENTS_LAUNCH_DURATION);
+            windowAnimEndListener = new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    mLauncher.getStateManager().goToState(NORMAL, false);
+                }
+            };
+        }
+
+        MutableBoolean skipLauncherChanges = new MutableBoolean(!launcherClosing);
+        Animator windowAnim = getRecentsWindowAnimator(taskView, skipLauncherChanges, targets);
+        windowAnim.addListener(windowAnimEndListener);
+        return new LauncherTransitionAnimator(launcherAnim, windowAnim, skipLauncherChanges);
     }
 
     /**
@@ -318,7 +348,7 @@
         launcherAnimator.play(allAppsSlideOut);
 
         Workspace workspace = mLauncher.getWorkspace();
-        float[] workspaceScaleAndTranslation = LauncherState.NORMAL
+        float[] workspaceScaleAndTranslation = NORMAL
                 .getWorkspaceScaleAndTranslation(mLauncher);
         Animator recenterWorkspace = LauncherAnimUtils.ofPropertyValuesHolder(
                 workspace, new PropertyListBuilder()
@@ -338,7 +368,7 @@
      * @return Animator that controls the window of the opening targets for the recents launch
      * animation.
      */
-    private ValueAnimator getRecentsWindowAnimator(TaskView v,
+    private ValueAnimator getRecentsWindowAnimator(TaskView v, MutableBoolean skipLauncherChanges,
             RemoteAnimationTargetCompat[] targets) {
         Rect taskViewBounds = new Rect();
         mDragLayer.getDescendantRectRelativeToSelf(v, taskViewBounds);
@@ -374,13 +404,15 @@
                 final float percent = animation.getAnimatedFraction();
                 TaskWindowBounds tw = recentsInterpolator.interpolate(percent);
 
-                v.setScaleX(tw.taskScale);
-                v.setScaleY(tw.taskScale);
-                v.setTranslationX(tw.taskX);
-                v.setTranslationY(tw.taskY);
-                // Defer fading out the view until after the app window gets faded in
-                v.setAlpha(getValue(1f, 0f, 75, 75,
-                        appAnimator.getDuration() * percent, Interpolators.LINEAR));
+                if (!skipLauncherChanges.value) {
+                    v.setScaleX(tw.taskScale);
+                    v.setScaleY(tw.taskScale);
+                    v.setTranslationX(tw.taskX);
+                    v.setTranslationY(tw.taskY);
+                    // Defer fading out the view until after the app window gets faded in
+                    v.setAlpha(getValue(1f, 0f, 75, 75,
+                            appAnimator.getDuration() * percent, Interpolators.LINEAR));
+                }
 
                 matrix.setScale(tw.winScale, tw.winScale);
                 matrix.postTranslate(tw.winX, tw.winY);
@@ -402,7 +434,10 @@
                         matrix.postTranslate(target.position.x, target.position.y);
                         t.setMatrix(target.leash, matrix);
                         t.setWindowCrop(target.leash, crop);
-                        t.deferTransactionUntil(target.leash, surface, getNextFrameNumber(surface));
+
+                        if (!skipLauncherChanges.value) {
+                            t.deferTransactionUntil(target.leash, surface, frameNumber);
+                        }
                     }
                     if (isFirstFrame) {
                         t.show(target.leash);
@@ -414,13 +449,6 @@
                 isFirstFrame = false;
             }
         });
-        appAnimator.addListener(new AnimatorListenerAdapter() {
-            @Override
-            public void onAnimationEnd(Animator animation) {
-                // Make sure recents gets fixed up by resetting task alphas and scales, etc.
-                mLauncher.getStateManager().reapplyState();
-            }
-        });
         return appAnimator;
     }
 
diff --git a/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java b/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java
index aec2869..ab9234b 100644
--- a/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java
+++ b/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java
@@ -27,11 +27,20 @@
  */
 public class LauncherTransitionAnimator {
 
+    private final MutableBoolean mLauncherAnimCancelState;
+
     private AnimatorSet mAnimatorSet;
     private Animator mLauncherAnimator;
     private Animator mWindowAnimator;
 
     LauncherTransitionAnimator(Animator launcherAnimator, Animator windowAnimator) {
+        this(launcherAnimator, windowAnimator, new MutableBoolean(false));
+    }
+
+
+    LauncherTransitionAnimator(Animator launcherAnimator, Animator windowAnimator,
+            MutableBoolean launcherAnimCancelState) {
+        mLauncherAnimCancelState = launcherAnimCancelState;
         if (launcherAnimator != null) {
             mLauncherAnimator = launcherAnimator;
         }
@@ -50,6 +59,7 @@
 
     public void cancel() {
         mAnimatorSet.cancel();
+        mLauncherAnimCancelState.value = true;
     }
 
     public boolean isRunning() {
@@ -58,6 +68,7 @@
 
     public void finishLauncherAnimation() {
         if (mLauncherAnimator != null) {
+            mLauncherAnimCancelState.value = true;
             mLauncherAnimator.end();
         }
     }
diff --git a/quickstep/src/com/android/launcher3/MutableBoolean.java b/quickstep/src/com/android/launcher3/MutableBoolean.java
new file mode 100644
index 0000000..7538217
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/MutableBoolean.java
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+public class MutableBoolean {
+    public boolean value;
+
+    public MutableBoolean(boolean value) {
+        this.value = value;
+    }
+}