summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jordan Demeulenaere <jdemeulenaere@google.com> 2021-05-25 09:32:36 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-05-25 09:32:36 +0000
commit56fb52b010f72faab0bf8825c40d621f042d28f4 (patch)
tree9bbf4d1ab9018baadaba58047be3dc67aec3ed5f
parentca7c3b754ec9024bad52bcb17f599ca3679ef31b (diff)
parentac75608d54c7e291fe7774c24be82a3a519b74a0 (diff)
Merge "Tune launch animations." into sc-dev
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt66
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt13
2 files changed, 60 insertions, 19 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt
index dafcb0fb1525..2b8773783048 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt
@@ -9,6 +9,7 @@ import android.app.PendingIntent
import android.content.Context
import android.graphics.Matrix
import android.graphics.Rect
+import android.graphics.RectF
import android.os.Looper
import android.os.RemoteException
import android.util.Log
@@ -311,7 +312,10 @@ class ActivityLaunchAnimator(context: Context) {
private val transactionApplier = SyncRtSurfaceTransactionApplier(launchContainer)
private var animator: ValueAnimator? = null
+ private val matrix = Matrix()
+ private val invertMatrix = Matrix()
private var windowCrop = Rect()
+ private var windowCropF = RectF()
private var timedOut = false
private var cancelled = false
@@ -479,19 +483,52 @@ class ActivityLaunchAnimator(context: Context) {
}
private fun applyStateToWindow(window: RemoteAnimationTarget, state: State) {
- val m = Matrix()
- m.postTranslate(0f, (state.top - window.sourceContainerBounds.top).toFloat())
- windowCrop.set(state.left, 0, state.right, state.height)
+ val screenBounds = window.screenSpaceBounds
+ val centerX = (screenBounds.left + screenBounds.right) / 2f
+ val centerY = (screenBounds.top + screenBounds.bottom) / 2f
+ val width = screenBounds.right - screenBounds.left
+ val height = screenBounds.bottom - screenBounds.top
+
+ // Scale the window. We use the max of (widthRatio, heightRatio) so that there is no
+ // blank space on any side.
+ val widthRatio = state.width.toFloat() / width
+ val heightRatio = state.height.toFloat() / height
+ val scale = maxOf(widthRatio, heightRatio)
+ matrix.reset()
+ matrix.setScale(scale, scale, centerX, centerY)
+
+ // Align it to the top and center it in the x-axis.
+ val heightChange = height * scale - height
+ val translationX = state.centerX - centerX
+ val translationY = state.top - screenBounds.top + heightChange / 2f
+ matrix.postTranslate(translationX, translationY)
+
+ // Crop it. The matrix will also be applied to the crop, so we apply the inverse
+ // operation. Given that we only scale (by factor > 0) then translate, we can assume
+ // that the matrix is invertible.
+ val cropX = state.left.toFloat() - screenBounds.left
+ val cropY = state.top.toFloat() - screenBounds.top
+ windowCropF.set(cropX, cropY, cropX + state.width, cropY + state.height)
+ matrix.invert(invertMatrix)
+ invertMatrix.mapRect(windowCropF)
+ windowCrop.set(
+ windowCropF.left.roundToInt(),
+ windowCropF.top.roundToInt(),
+ windowCropF.right.roundToInt(),
+ windowCropF.bottom.roundToInt()
+ )
- val cornerRadius = minOf(state.topCornerRadius, state.bottomCornerRadius)
+ // The scale will also be applied to the corner radius, so we divide by the scale to
+ // keep the original radius.
+ val cornerRadius = minOf(state.topCornerRadius, state.bottomCornerRadius) / scale
val params = SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(window.leash)
- .withAlpha(1f)
- .withMatrix(m)
- .withWindowCrop(windowCrop)
- .withLayer(window.prefixOrderIndex)
- .withCornerRadius(cornerRadius)
- .withVisibility(true)
- .build()
+ .withAlpha(1f)
+ .withMatrix(matrix)
+ .withWindowCrop(windowCrop)
+ .withLayer(window.prefixOrderIndex)
+ .withCornerRadius(cornerRadius)
+ .withVisibility(true)
+ .build()
transactionApplier.scheduleApply(params)
}
@@ -506,12 +543,13 @@ class ActivityLaunchAnimator(context: Context) {
val params = SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(navigationBar.leash)
if (fadeInProgress > 0) {
- val m = Matrix()
- m.postTranslate(0f, (state.top - navigationBar.sourceContainerBounds.top).toFloat())
+ matrix.reset()
+ matrix.setTranslate(
+ 0f, (state.top - navigationBar.sourceContainerBounds.top).toFloat())
windowCrop.set(state.left, 0, state.right, state.height)
params
.withAlpha(NAV_FADE_IN_INTERPOLATOR.getInterpolation(fadeInProgress))
- .withMatrix(m)
+ .withMatrix(matrix)
.withWindowCrop(windowCrop)
.withVisibility(true)
} else {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt
index 0753d05dc888..f2ef5c38e9b9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt
@@ -139,11 +139,14 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() {
verify(controller).onLaunchAnimationStart(anyBoolean())
}
- private fun fakeWindow() = RemoteAnimationTarget(
- 0, RemoteAnimationTarget.MODE_OPENING, SurfaceControl(), false, Rect(), Rect(), 0,
- Point(), Rect(), Rect(), WindowConfiguration(), false, SurfaceControl(), Rect(),
- ActivityManager.RunningTaskInfo()
- )
+ private fun fakeWindow(): RemoteAnimationTarget {
+ val bounds = Rect(10 /* left */, 20 /* top */, 30 /* right */, 40 /* bottom */)
+ return RemoteAnimationTarget(
+ 0, RemoteAnimationTarget.MODE_OPENING, SurfaceControl(), false, Rect(), Rect(), 0,
+ Point(), Rect(), bounds, WindowConfiguration(), false, SurfaceControl(), Rect(),
+ ActivityManager.RunningTaskInfo()
+ )
+ }
}
/**