Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5c9cb5a authored by Luca Zuccarini's avatar Luca Zuccarini
Browse files

Clean up the animation of surfaces behind Keyguard on unlock.

This does a few things:
1. Unifies the behavior before and after the Keyguard root view is
   gone (before some values were different) to match the unflagged
   behavior. An exception to this is the amount of the translation,
   which is controlled outside of this applier.
2. Clean up some magic numbers.
3. Move the translation inside the matrix. Before, `setTranslate()`
   was overridden by the following `setMatrix`().
4. Ensure that the translation percentage is calculated correctly, so
   that the scale is also correct for the whole duration.

Fix: 438430688
Flag: com.android.systemui.keyguard_wm_state_refactor
Flag: com.android.systemui.scene_container
Test: manual (see video in the bug)
Change-Id: I25414b5e59865a8000400df93cc5c63a35f74a7a
parent 495fe9a4
Loading
Loading
Loading
Loading
+34 −32
Original line number Original line Diff line number Diff line
@@ -37,10 +37,24 @@ import com.android.systemui.keyguard.TAG
import com.android.systemui.keyguard.domain.interactor.KeyguardSurfaceBehindInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardSurfaceBehindInteractor
import com.android.systemui.keyguard.shared.model.KeyguardSurfaceBehindModel
import com.android.systemui.keyguard.shared.model.KeyguardSurfaceBehindModel
import com.android.wm.shell.shared.animation.Interpolators
import com.android.wm.shell.shared.animation.Interpolators
import java.lang.Math.clamp
import java.util.concurrent.Executor
import java.util.concurrent.Executor
import javax.inject.Inject
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.max


/**
 * Starting scale factor for the app/launcher surface behind the keyguard, when it's animating in
 * during keyguard exit.
 */
private const val START_SCALE_FACTOR = 0.95f

/**
 * Y coordinate of the pivot point for the scale effect on the surface behind the keyguard. This is
 * expressed as percentage of the surface's height, so 0.66f means the surface will scale up from
 * the point at (width / 2, height * 0.66).
 */
private const val SCALE_PIVOT_Y = 0.66f

/** Damping ratio to use for animations resulting from touch gesture fling animation. */
/** Damping ratio to use for animations resulting from touch gesture fling animation. */
private const val TOUCH_FLING_DAMPING_RATIO = 0.992f
private const val TOUCH_FLING_DAMPING_RATIO = 0.992f


@@ -219,12 +233,19 @@ constructor(
                }
                }


                val translationX = target.screenSpaceBounds.left.toFloat()
                val translationX = target.screenSpaceBounds.left.toFloat()
                val translationY =
                val baseTranslationY =
                    if (translateYSpring.isRunning) {
                    if (translateYSpring.isRunning) {
                        target.screenSpaceBounds.top.toFloat() + animatedTranslationY.value
                        animatedTranslationY.value
                    } else {
                    } else {
                        target.screenSpaceBounds.top.toFloat() + viewParams.translationY
                        viewParams.translationY
                    }
                    }
                val translationY = target.screenSpaceBounds.top.toFloat() + baseTranslationY

                var percentTranslated =
                    clamp(1f - (baseTranslationY / animatingFromTranslationY), 0f, 1f)
                if (!percentTranslated.isFinite()) percentTranslated = 1f
                val scaleFactor =
                    START_SCALE_FACTOR + ((1f - START_SCALE_FACTOR) * percentTranslated)


                val alpha =
                val alpha =
                    if (alphaAnimator.isRunning) {
                    if (alphaAnimator.isRunning) {
@@ -233,47 +254,28 @@ constructor(
                        viewParams.alpha
                        viewParams.alpha
                    }
                    }


                matrix.setScale(
                    scaleFactor,
                    scaleFactor,
                    target.screenSpaceBounds.width() / 2f,
                    target.screenSpaceBounds.height() * SCALE_PIVOT_Y,
                )
                matrix.postTranslate(translationX, translationY)

                if (
                if (
                    keyguardViewController.viewRootImpl.view?.visibility != View.VISIBLE &&
                    keyguardViewController.viewRootImpl.view?.visibility != View.VISIBLE &&
                        target.leash.isValid
                        target.leash.isValid
                ) {
                ) {
                    with(SurfaceControl.Transaction()) {
                    with(SurfaceControl.Transaction()) {
                        setMatrix(
                        setMatrix(target.leash, matrix, tmpFloat)
                            target.leash,
                            matrix.apply {
                                setTranslate(translationX, translationY)
                                var percentTranslated =
                                    1f - (animatedTranslationY.value / animatingFromTranslationY)
                                if (!percentTranslated.isFinite()) percentTranslated = 1f
                                setScale(
                                    95f + (5f * percentTranslated),
                                    95f + (5f * percentTranslated),
                                    surfaceBehind!!.screenSpaceBounds.width() / 2f,
                                    surfaceBehind!!.screenSpaceBounds.height() * .75f,
                                )
                            },
                            tmpFloat,
                        )
                        setAlpha(target.leash, alpha)
                        setAlpha(target.leash, alpha)
                        setCornerRadius(target.leash, roundedCornerRadius)
                        setCornerRadius(target.leash, roundedCornerRadius)
                        apply()
                        apply()
                    }
                    }
                } else {
                } else {
                    var percentTranslated = 1f - (translationY / animatingFromTranslationY)
                    if (!percentTranslated.isFinite()) percentTranslated = 1f
                    surfaceTransactionApplier.scheduleApply(
                    surfaceTransactionApplier.scheduleApply(
                        SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(target.leash)
                        SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(target.leash)
                            .withMatrix(
                            .withMatrix(matrix)
                                matrix.apply {
                                    setScale(
                                        .93f + (.07f * percentTranslated),
                                        .93f + (.07f * percentTranslated),
                                        surfaceBehind!!.screenSpaceBounds.width() / 2f,
                                        surfaceBehind!!.screenSpaceBounds.height() * .66f,
                                    )
                                    postTranslate(translationX, translationY)
                                }
                            )
                            .withAlpha(alpha)
                            .withAlpha(alpha)
                            .withCornerRadius(roundedCornerRadius)
                            .withCornerRadius(roundedCornerRadius)
                            .build()
                            .build()