From 9de91d3cba368cdb94ffc6475bd7ae5574597d37 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Fri, 9 Apr 2021 16:56:24 +0200 Subject: [PATCH] Scale the expanding view content towards the center. This CL scales the content of the view that is expanding during an animated activity launch. The content also now moves towards the center of the final window position. Bug: 184726377 Test: Manual Change-Id: Ibca1c4f5f56d99878d6c79dab033a2e7d7a4928b --- .../animation/ActivityLaunchAnimator.kt | 20 +++++++++++++++++++ .../GhostedViewLaunchAnimatorController.kt | 20 ++++++++++++++++--- 2 files changed, 37 insertions(+), 3 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 fc03a9ee9c5f5..da78a7c24d0fd 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt @@ -223,8 +223,13 @@ class ActivityLaunchAnimator(context: Context) { var backgroundAlpha: Float = 1f ) { private val startTop = top + private val startBottom = bottom private val startLeft = left private val startRight = right + private val startWidth = width + private val startHeight = height + val startCenterX = centerX + val startCenterY = centerY val width: Int get() = right - left @@ -235,11 +240,26 @@ class ActivityLaunchAnimator(context: Context) { open val topChange: Int get() = top - startTop + open val bottomChange: Int + get() = bottom - startBottom + val leftChange: Int get() = left - startLeft val rightChange: Int get() = right - startRight + + val widthRatio: Float + get() = width.toFloat() / startWidth + + val heightRatio: Float + get() = height.toFloat() / startHeight + + val centerX: Float + get() = left + width / 2f + + val centerY: Float + get() = top + height / 2f } @VisibleForTesting diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt index bbbe3dddcf8d4..01ec447e5685a 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt @@ -2,6 +2,7 @@ package com.android.systemui.animation import android.graphics.Canvas import android.graphics.ColorFilter +import android.graphics.Matrix import android.graphics.PixelFormat import android.graphics.PorterDuff import android.graphics.PorterDuffXfermode @@ -13,6 +14,7 @@ import android.view.GhostView import android.view.View import android.view.ViewGroup import android.widget.FrameLayout +import kotlin.math.min /** * A base implementation of [ActivityLaunchAnimator.Controller] which creates a [ghost][GhostView] @@ -34,7 +36,9 @@ open class GhostedViewLaunchAnimatorController( private val rootViewOverlay = rootView.overlay /** The ghost view that is drawn and animated instead of the ghosted view. */ - private var ghostView: View? = null + private var ghostView: GhostView? = null + private val initialGhostViewMatrixValues = FloatArray(9) { 0f } + private val ghostViewMatrix = Matrix() /** * The expanding background view that will be added to [rootView] (below [ghostView]) and @@ -125,6 +129,9 @@ open class GhostedViewLaunchAnimatorController( ghostView = GhostView.addGhost(ghostedView, rootView).apply { setLayerType(View.LAYER_TYPE_HARDWARE, null) } + + val matrix = ghostView?.animationMatrix ?: Matrix.IDENTITY_MATRIX + matrix.getValues(initialGhostViewMatrixValues) } override fun onLaunchAnimationProgress( @@ -133,10 +140,17 @@ open class GhostedViewLaunchAnimatorController( linearProgress: Float ) { val ghostView = this.ghostView!! - ghostView.translationX = (state.leftChange + state.rightChange) / 2.toFloat() - ghostView.translationY = state.topChange.toFloat() ghostView.alpha = state.contentAlpha + val scale = min(state.widthRatio, state.heightRatio) + ghostViewMatrix.setValues(initialGhostViewMatrixValues) + ghostViewMatrix.postScale(scale, scale, state.startCenterX, state.startCenterY) + ghostViewMatrix.postTranslate( + (state.leftChange + state.rightChange) / 2f, + (state.topChange + state.bottomChange) / 2f + ) + ghostView.animationMatrix = ghostViewMatrix + val backgroundView = this.backgroundView!! backgroundView.top = state.top backgroundView.bottom = state.bottom