Merge "Fix a couple of issues with app close" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index 31c195d..a4bdd84 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -440,6 +440,10 @@
                     mAnimator.play(getClosingWindowAnimators(targets));
                     mAnimator.play(getLauncherResumeAnimation());
                     mAnimator.start();
+
+                    // Because t=0 has the app icon in its original spot, we can skip the
+                    // first frame and have the same movement one frame earlier.
+                    mAnimator.setCurrentPlayTime(REFRESH_RATE_MS);
                 });
             }
         };
@@ -452,7 +456,7 @@
         Matrix matrix = new Matrix();
         float height = mLauncher.getDeviceProfile().heightPx;
         float width = mLauncher.getDeviceProfile().widthPx;
-        float endX = Utilities.isRtl(mLauncher.getResources()) ? -width : width;
+        float endX = (Utilities.isRtl(mLauncher.getResources()) ? -width : width) * 1.16f;
 
         ValueAnimator closingAnimator = ValueAnimator.ofFloat(0, 1);
         closingAnimator.setDuration(CLOSING_TRANSITION_DURATION_MS);
@@ -467,27 +471,27 @@
 
                 float scale = getValue(1f, 0.8f, 0, 267, currentPlayTime,
                         Interpolators.AGGRESSIVE_EASE);
-                matrix.setScale(scale, scale);
 
                 float dX = getValue(0, endX, 0, 350, currentPlayTime,
                         Interpolators.AGGRESSIVE_EASE_IN_OUT);
-                float dY = (height - height * scale) / 2f;
 
                 TransactionCompat t = new TransactionCompat();
                 for (RemoteAnimationTargetCompat app : targets) {
                     if (app.mode == RemoteAnimationTargetCompat.MODE_CLOSING) {
-                        t.setAlpha(app.leash, 1f - percent);
-                        matrix.postTranslate(dX, dY);
+                        t.setAlpha(app.leash, getValue(1f, 0f, 0, 350, currentPlayTime,
+                                Interpolators.APP_CLOSE_ALPHA));
+                        matrix.setScale(scale, scale,
+                                app.sourceContainerBounds.centerX(),
+                                app.sourceContainerBounds.centerY());
+                        matrix.postTranslate(dX, 0);
                         matrix.postTranslate(app.position.x, app.position.y);
                         t.setMatrix(app.leash, matrix);
                     }
-                    // TODO: Layer should be set only once, but there is possibly a race condition
-                    // where WindowManager is also calling setLayer.
-                    int layer = app.mode == RemoteAnimationTargetCompat.MODE_CLOSING
-                            ? Integer.MAX_VALUE
-                            : app.prefixOrderIndex;
-                    t.setLayer(app.leash, layer);
                     if (isFirstFrame) {
+                        int layer = app.mode == RemoteAnimationTargetCompat.MODE_CLOSING
+                                ? Integer.MAX_VALUE
+                                : app.prefixOrderIndex;
+                        t.setLayer(app.leash, layer);
                         t.show(app.leash);
                     }
                 }
diff --git a/src/com/android/launcher3/anim/Interpolators.java b/src/com/android/launcher3/anim/Interpolators.java
index ee0dba6..2343654 100644
--- a/src/com/android/launcher3/anim/Interpolators.java
+++ b/src/com/android/launcher3/anim/Interpolators.java
@@ -46,6 +46,8 @@
     public static final Interpolator AGGRESSIVE_EASE = new PathInterpolator(0.2f, 0f, 0f, 1f);
     public static final Interpolator AGGRESSIVE_EASE_IN_OUT = new PathInterpolator(0.8f,0, 0.4f, 1);
 
+    public static final Interpolator APP_CLOSE_ALPHA = new PathInterpolator(0.9f, 0, 1f, 1f);
+
     public static final Interpolator OVERSHOOT_0 = new OvershootInterpolator(0);
 
     /**