Merge "Scale the expanding view content towards the center." into sc-dev

This commit is contained in:
Jordan Demeulenaere
2021-04-12 16:20:01 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 3 deletions

View File

@@ -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

View File

@@ -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