Merge "Tune launch animations." into sc-dev

This commit is contained in:
Jordan Demeulenaere
2021-05-25 09:32:36 +00:00
committed by Android (Google) Code Review
2 changed files with 60 additions and 19 deletions

View File

@@ -9,6 +9,7 @@ import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.graphics.Matrix import android.graphics.Matrix
import android.graphics.Rect import android.graphics.Rect
import android.graphics.RectF
import android.os.Looper import android.os.Looper
import android.os.RemoteException import android.os.RemoteException
import android.util.Log import android.util.Log
@@ -311,7 +312,10 @@ class ActivityLaunchAnimator(context: Context) {
private val transactionApplier = SyncRtSurfaceTransactionApplier(launchContainer) private val transactionApplier = SyncRtSurfaceTransactionApplier(launchContainer)
private var animator: ValueAnimator? = null private var animator: ValueAnimator? = null
private val matrix = Matrix()
private val invertMatrix = Matrix()
private var windowCrop = Rect() private var windowCrop = Rect()
private var windowCropF = RectF()
private var timedOut = false private var timedOut = false
private var cancelled = false private var cancelled = false
@@ -479,19 +483,52 @@ class ActivityLaunchAnimator(context: Context) {
} }
private fun applyStateToWindow(window: RemoteAnimationTarget, state: State) { private fun applyStateToWindow(window: RemoteAnimationTarget, state: State) {
val m = Matrix() val screenBounds = window.screenSpaceBounds
m.postTranslate(0f, (state.top - window.sourceContainerBounds.top).toFloat()) val centerX = (screenBounds.left + screenBounds.right) / 2f
windowCrop.set(state.left, 0, state.right, state.height) val centerY = (screenBounds.top + screenBounds.bottom) / 2f
val width = screenBounds.right - screenBounds.left
val height = screenBounds.bottom - screenBounds.top
val cornerRadius = minOf(state.topCornerRadius, state.bottomCornerRadius) // 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()
)
// 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) val params = SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(window.leash)
.withAlpha(1f) .withAlpha(1f)
.withMatrix(m) .withMatrix(matrix)
.withWindowCrop(windowCrop) .withWindowCrop(windowCrop)
.withLayer(window.prefixOrderIndex) .withLayer(window.prefixOrderIndex)
.withCornerRadius(cornerRadius) .withCornerRadius(cornerRadius)
.withVisibility(true) .withVisibility(true)
.build() .build()
transactionApplier.scheduleApply(params) transactionApplier.scheduleApply(params)
} }
@@ -506,12 +543,13 @@ class ActivityLaunchAnimator(context: Context) {
val params = SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(navigationBar.leash) val params = SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(navigationBar.leash)
if (fadeInProgress > 0) { if (fadeInProgress > 0) {
val m = Matrix() matrix.reset()
m.postTranslate(0f, (state.top - navigationBar.sourceContainerBounds.top).toFloat()) matrix.setTranslate(
0f, (state.top - navigationBar.sourceContainerBounds.top).toFloat())
windowCrop.set(state.left, 0, state.right, state.height) windowCrop.set(state.left, 0, state.right, state.height)
params params
.withAlpha(NAV_FADE_IN_INTERPOLATOR.getInterpolation(fadeInProgress)) .withAlpha(NAV_FADE_IN_INTERPOLATOR.getInterpolation(fadeInProgress))
.withMatrix(m) .withMatrix(matrix)
.withWindowCrop(windowCrop) .withWindowCrop(windowCrop)
.withVisibility(true) .withVisibility(true)
} else { } else {

View File

@@ -139,11 +139,14 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() {
verify(controller).onLaunchAnimationStart(anyBoolean()) verify(controller).onLaunchAnimationStart(anyBoolean())
} }
private fun fakeWindow() = RemoteAnimationTarget( private fun fakeWindow(): RemoteAnimationTarget {
0, RemoteAnimationTarget.MODE_OPENING, SurfaceControl(), false, Rect(), Rect(), 0, val bounds = Rect(10 /* left */, 20 /* top */, 30 /* right */, 40 /* bottom */)
Point(), Rect(), Rect(), WindowConfiguration(), false, SurfaceControl(), Rect(), return RemoteAnimationTarget(
ActivityManager.RunningTaskInfo() 0, RemoteAnimationTarget.MODE_OPENING, SurfaceControl(), false, Rect(), Rect(), 0,
) Point(), Rect(), bounds, WindowConfiguration(), false, SurfaceControl(), Rect(),
ActivityManager.RunningTaskInfo()
)
}
} }
/** /**