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

Commit 2b28d8a2 authored by Matt Pietal's avatar Matt Pietal
Browse files

Ensure translationX gets reset

On foldables devices, when folded, an animation moves content
by translationX. If this is canceled, such as quick power
button pushes, the next transition needs to resume the animation
to make sure it gets reset to 0.

Fixes: 361064064
Test: atest AodBurnInViewModelTest
Flag: com.android.systemui.migrate_clocks_to_blueprint
Change-Id: Ib464245cef2cb9a784b96ef11a814b74ef2bd3d5
parent d2f98086
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -128,6 +128,53 @@ class AodBurnInViewModelTest : SysuiTestCase() {
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    fun translationX_aodToLockscreen() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(translationX = { -100f }))
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationX).isEqualTo(0)

            // Trigger a change to the burn-in model
            burnInFlow.value = BurnInModel(translationX = 20, translationY = 30, scale = 0.5f)

            // Set to not dozing (on lockscreen)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 0f,
                    transitionState = TransitionState.STARTED,
                ),
                validateStep = false,
            )
            // Set to not dozing (on lockscreen)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 0f,
                    transitionState = TransitionState.RUNNING,
                ),
                validateStep = false,
            )
            assertThat(movement?.translationX).isEqualTo(-100)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 1f,
                    transitionState = TransitionState.FINISHED,
                ),
                validateStep = false,
            )

            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(1f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    fun translationAndScale_whenFullyDozing() =
        testScope.runTest {
+4 −1
Original line number Diff line number Diff line
@@ -413,7 +413,10 @@ object KeyguardRootViewBinder {

        if (MigrateClocksToBlueprint.isEnabled) {
            burnInParams.update { current ->
                current.copy(translationY = { childViews[burnInLayerId]?.translationY })
                current.copy(
                    translationX = { childViews[burnInLayerId]?.translationX },
                    translationY = { childViews[burnInLayerId]?.translationY },
                )
            }
        }

+16 −6
Original line number Diff line number Diff line
@@ -113,6 +113,9 @@ constructor(
                            occludedToLockscreenTransitionViewModel.lockscreenTranslationY.onStart {
                                emit(0f)
                            },
                            aodToLockscreenTransitionViewModel
                                .translationX(params.translationX)
                                .onStart { emit(StateToValue()) },
                            aodToLockscreenTransitionViewModel
                                .translationY(params.translationY)
                                .onStart { emit(StateToValue()) },
@@ -123,11 +126,12 @@ constructor(
                            val goneToAodTranslationX = flows[3] as StateToValue
                            val lockscreenToAodTranslationX = flows[4] as StateToValue
                            val occludedToLockscreen = flows[5] as Float
                            val aodToLockscreen = flows[6] as StateToValue
                            val aodToLockscreenTranslationX = flows[6] as StateToValue
                            val aodToLockscreenTranslationY = flows[7] as StateToValue

                            val translationY =
                                if (aodToLockscreen.transitionState.isTransitioning()) {
                                    aodToLockscreen.value ?: 0f
                                if (aodToLockscreenTranslationY.transitionState.isTransitioning()) {
                                    aodToLockscreenTranslationY.value ?: 0f
                                } else if (
                                    goneToAodTranslationY.transitionState.isTransitioning()
                                ) {
@@ -138,9 +142,13 @@ constructor(
                                        keyguardTranslationY
                                }
                            val translationX =
                                if (aodToLockscreenTranslationX.transitionState.isTransitioning()) {
                                    aodToLockscreenTranslationX.value ?: 0f
                                } else {
                                    burnInModel.translationX +
                                        (goneToAodTranslationX.value ?: 0f) +
                                        (lockscreenToAodTranslationX.value ?: 0f)
                                }
                            burnInModel.copy(
                                translationX = translationX.toInt(),
                                translationY = translationY.toInt(),
@@ -198,6 +206,8 @@ data class BurnInParameters(
    val minViewY: Int = Int.MAX_VALUE,
    /** The current y translation of the view */
    val translationY: () -> Float? = { null },
    /** The current x translation of the view */
    val translationX: () -> Float? = { null },
)

/**
+16 −5
Original line number Diff line number Diff line
@@ -39,10 +39,8 @@ import kotlinx.coroutines.flow.Flow
@SysUISingleton
class AodToLockscreenTransitionViewModel
@Inject
constructor(
    shadeInteractor: ShadeInteractor,
    animationFlow: KeyguardTransitionAnimationFlow,
) : DeviceEntryIconTransition {
constructor(shadeInteractor: ShadeInteractor, animationFlow: KeyguardTransitionAnimationFlow) :
    DeviceEntryIconTransition {

    private val transitionAnimation =
        animationFlow.setup(
@@ -54,7 +52,7 @@ constructor(

    /**
     * Begin the transition from wherever the y-translation value is currently. This helps ensure a
     * smooth transition if a transition in canceled.
     * smooth transition if the prior transition was canceled.
     */
    fun translationY(currentTranslationY: () -> Float?): Flow<StateToValue> {
        var startValue = 0f
@@ -65,6 +63,19 @@ constructor(
        )
    }

    /**
     * Begin the transition from wherever the x-translation value is currently. This helps ensure a
     * smooth transition if the prior transition was canceled.
     */
    fun translationX(currentTranslationX: () -> Float?): Flow<StateToValue> {
        var startValue = 0f
        return transitionAnimation.sharedFlowWithState(
            duration = 500.milliseconds,
            onStart = { startValue = currentTranslationX() ?: 0f },
            onStep = { MathUtils.lerp(startValue, 0f, FAST_OUT_SLOW_IN.getInterpolation(it)) },
        )
    }

    /** Ensure alpha is set to be visible */
    fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> {
        var startAlpha = 1f