From de63d441d7daf0503bcc6d5fd3f4f7efe06e23d3 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 14 Mar 2016 14:56:56 +0100 Subject: [PATCH] Implement transition for docking task in recents #3 - Implement clipping for thumbnail. Bug: 27607141 Change-Id: Ic3ba0acf685341ad715fae1601fad5eba1a93e44 --- .../com/android/server/wm/AppTransition.java | 28 +++++++++++++++++-- .../android/server/wm/AppWindowAnimator.java | 1 + .../server/wm/WindowSurfacePlacer.java | 3 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java index a1befe9117410..8e28bbc447427 100644 --- a/services/core/java/com/android/server/wm/AppTransition.java +++ b/services/core/java/com/android/server/wm/AppTransition.java @@ -871,8 +871,8 @@ public class AppTransition implements Dump { * This animation runs for the thumbnail that gets cross faded with the enter/exit activity * when a thumbnail is specified with the pending animation override. */ - Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader, - final int taskId) { + Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets, + Bitmap thumbnailHeader, final int taskId) { Animation a; final int thumbWidthI = thumbnailHeader.getWidth(); final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; @@ -900,11 +900,35 @@ public class AppTransition implements Dump { translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR); translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION); + float thumbScale = thumbWidth / (appWidth - (contentInsets != null + ? contentInsets.left - contentInsets.right : 0)); + + mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI); + mTmpToClipRect.set(appRect); + + // Containing frame is in screen space, but we need the clip rect in the + // app space. + mTmpToClipRect.offsetTo(0, 0); + mTmpToClipRect.right = (int) (mTmpToClipRect.right * thumbScale); + mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom * thumbScale); + + if (contentInsets != null) { + mTmpToClipRect.inset((int) (-contentInsets.left * thumbScale), + (int) (-contentInsets.top * thumbScale), + (int) (-contentInsets.right * thumbScale), + (int) (-contentInsets.bottom * thumbScale)); + } + + Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect); + clipAnim.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR); + clipAnim.setDuration(THUMBNAIL_APP_TRANSITION_DURATION); + // This AnimationSet uses the Interpolators assigned above. AnimationSet set = new AnimationSet(false); set.addAnimation(scale); set.addAnimation(alpha); set.addAnimation(translate); + set.addAnimation(clipAnim); a = set; } else { // Animation down from the full screen to the thumbnail diff --git a/services/core/java/com/android/server/wm/AppWindowAnimator.java b/services/core/java/com/android/server/wm/AppWindowAnimator.java index 6225fc61afc27..fedeb30c7b34d 100644 --- a/services/core/java/com/android/server/wm/AppWindowAnimator.java +++ b/services/core/java/com/android/server/wm/AppWindowAnimator.java @@ -288,6 +288,7 @@ public class AppWindowAnimator { } thumbnail.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y], tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]); + thumbnail.setWindowCrop(thumbnailTransformation.getClipRect()); } /** diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java index e177f23374dc1..470b0b588c159 100644 --- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java +++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java @@ -1576,12 +1576,13 @@ class WindowSurfacePlacer { WindowState win = appToken.findMainWindow(); Rect appRect = win != null ? win.getContentFrameLw() : new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight); + Rect insets = win != null ? win.mContentInsets : null; // 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 = mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(appRect, - thumbnailHeader, taskId); + insets, thumbnailHeader, taskId); openingAppAnimator.thumbnailForceAboveLayer = Math.max(openingLayer, closingLayer); openingAppAnimator.deferThumbnailDestruction = !mService.mAppTransition.isNextThumbnailTransitionScaleUp();