Make thumbnail header animation match multi window thumbnail animation.

Change-Id: Ib21c7c6300d58f08132aadae3aa68439793936d2
diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java
index a2307f9..dfdb29c 100644
--- a/services/core/java/com/android/server/wm/AppTransition.java
+++ b/services/core/java/com/android/server/wm/AppTransition.java
@@ -651,15 +651,15 @@
      * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
      * when a thumbnail is specified with the activity options.
      */
-    Animation createThumbnailAspectScaleAnimationLocked(int appWidth, int appHeight,
-            int deviceWidth) {
+    Animation createThumbnailAspectScaleAnimationLocked(Rect appRect) {
         Animation a;
         final int thumbWidthI = mNextAppTransitionThumbnail.getWidth();
         final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
         final int thumbHeightI = mNextAppTransitionThumbnail.getHeight();
         final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
+        final int appWidth = appRect.width();
 
-        float scaleW = deviceWidth / thumbWidth;
+        float scaleW = appWidth / thumbWidth;
         float unscaledHeight = thumbHeight * scaleW;
         float unscaledStartY = mNextAppTransitionStartY - (unscaledHeight - thumbHeight) / 2f;
         if (mNextAppTransitionScaleUp) {
@@ -672,8 +672,10 @@
             Animation alpha = new AlphaAnimation(1, 0);
             alpha.setInterpolator(mThumbnailFadeOutInterpolator);
             alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
-            Animation translate = new TranslateAnimation(0, 0, 0, -unscaledStartY +
-                    mNextAppTransitionInsets.top);
+            final float toX = appRect.left + appRect.width() / 2 -
+                    (mNextAppTransitionStartX + thumbWidth / 2);
+            final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
+            Animation translate = new TranslateAnimation(0, toX, 0, toY);
             translate.setInterpolator(mTouchResponseInterpolator);
             translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
 
@@ -706,7 +708,7 @@
             a = set;
 
         }
-        return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, 0,
+        return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
                 mTouchResponseInterpolator);
     }
 
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 5ec2137..ec61a1d 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -9539,13 +9539,17 @@
                     // Get the thumbnail animation
                     Animation anim;
                     if (mAppTransition.isNextThumbnailTransitionAspectScaled()) {
+                        // If this is a multi-window scenario, we use the windows frame as
+                        // destination of the thumbnail header animation. If this is a full screen
+                        // window scenario, we use the whole display as the target.
+                        WindowState win = topOpeningApp.findMainWindow();
+                        Rect appRect = win != null ? win.getContentFrameLw() :
+                                new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
                         // For the new aspect-scaled transition, we want it to always show
                         // above the animating opening/closing window, and we want to
                         // synchronize its thumbnail surface with the surface for the
                         // open/close animation (only on the way down)
-                        anim = mAppTransition.createThumbnailAspectScaleAnimationLocked(
-                                displayInfo.appWidth, displayInfo.appHeight,
-                                displayInfo.logicalWidth);
+                        anim = mAppTransition.createThumbnailAspectScaleAnimationLocked(appRect);
                         openingAppAnimator.thumbnailForceAboveLayer = Math.max(topOpeningLayer,
                                 topClosingLayer);
                         openingAppAnimator.deferThumbnailDestruction =