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

Commit 2608720c authored by William Xiao's avatar William Xiao
Browse files

Fade keyguard when entering glanceable hub

Temporary transition for teamfood purposes, full animation to come
later.

Also requires NSSL and keyguard bottom area refactor flags to take
effect:
adb shell device_config override systemui com.android.systemui.keyguard_shade_migration_nssl true
adb shell device_config override systemui com.android.systemui.keyguard_bottom_area_refactor true

Bug: 315205222
Test: atest KeyguardRootViewModelTest
Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Change-Id: I44ae8865cbf3e970cdd7750659ebae62f1130f13
parent c60396c0
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -203,4 +203,38 @@ class KeyguardRootViewModelTest : SysuiTestCase() {

            assertThat(isVisible?.isAnimating).isEqualTo(false)
        }

    @Test
    fun alpha_glanceableHubOpen_isZero() =
        testScope.runTest {
            val alpha by collectLastValue(underTest.alpha)

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GLANCEABLE_HUB,
                testScope,
            )

            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    fun alpha_glanceableHubClosed_isOne() =
        testScope.runTest {
            val alpha by collectLastValue(underTest.alpha)

            // Transition to the glanceable hub and back.
            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GLANCEABLE_HUB,
                testScope,
            )
            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.LOCKSCREEN,
                testScope,
            )

            assertThat(alpha).isEqualTo(1.0f)
        }
}
+1 −0
Original line number Diff line number Diff line
@@ -425,5 +425,6 @@ constructor(
        val TO_AOD_DURATION = 500.milliseconds
        val TO_PRIMARY_BOUNCER_DURATION = DEFAULT_DURATION
        val TO_GONE_DURATION = DEFAULT_DURATION
        val TO_GLANCEABLE_HUB_DURATION = DEFAULT_DURATION
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.domain.interactor.FromLockscreenTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow

/**
 * Breaks down GLANCEABLE_HUB->LOCKSCREEN transition into discrete steps for corresponding views to
 * consume.
 */
@ExperimentalCoroutinesApi
@SysUISingleton
class GlanceableHubToLockscreenTransitionViewModel
@Inject
constructor(
    animationFlow: KeyguardTransitionAnimationFlow,
) {
    private val transitionAnimation =
        animationFlow.setup(
            duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION,
            from = KeyguardState.GLANCEABLE_HUB,
            to = KeyguardState.LOCKSCREEN,
        )

    // TODO(b/315205222): implement full animation spec instead of just a simple fade.
    val keyguardAlpha: Flow<Float> =
        transitionAnimation.sharedFlow(
            duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION,
            onStep = { it },
            onFinish = { 1f },
            onCancel = { 0f },
            name = "GLANCEABLE_HUB->LOCKSCREEN: keyguardAlpha",
        )
}
+10 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
@@ -58,6 +59,8 @@ constructor(
    keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val notificationsKeyguardInteractor: NotificationsKeyguardInteractor,
    aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel,
    lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel,
    glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel,
    screenOffAnimationController: ScreenOffAnimationController,
    private val aodBurnInViewModel: AodBurnInViewModel,
    aodAlphaViewModel: AodAlphaViewModel,
@@ -78,7 +81,13 @@ constructor(
        keyguardInteractor.notificationContainerBounds

    /** An observable for the alpha level for the entire keyguard root view. */
    val alpha: Flow<Float> = aodAlphaViewModel.alpha
    val alpha: Flow<Float> =
        merge(
                aodAlphaViewModel.alpha,
                lockscreenToGlanceableHubTransitionViewModel.keyguardAlpha,
                glanceableHubToLockscreenTransitionViewModel.keyguardAlpha,
            )
            .distinctUntilChanged()

    /** Specific alpha value for elements visible during [KeyguardState.LOCKSCREEN] */
    val lockscreenStateAlpha: Flow<Float> = aodToLockscreenTransitionViewModel.lockscreenAlpha
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.domain.interactor.FromLockscreenTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow

/**
 * Breaks down LOCKSCREEN->GLANCEABLE_HUB transition into discrete steps for corresponding views to
 * consume.
 */
@ExperimentalCoroutinesApi
@SysUISingleton
class LockscreenToGlanceableHubTransitionViewModel
@Inject
constructor(
    animationFlow: KeyguardTransitionAnimationFlow,
) {
    private val transitionAnimation =
        animationFlow.setup(
            duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION,
            from = KeyguardState.LOCKSCREEN,
            to = KeyguardState.GLANCEABLE_HUB,
        )

    // TODO(b/315205222): implement full animation spec instead of just a simple fade.
    val keyguardAlpha: Flow<Float> =
        transitionAnimation.sharedFlow(
            duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION,
            onStep = { 1f - it },
            onFinish = { 0f },
            onCancel = { 1f },
            name = "LOCKSCREEN->GLANCEABLE_HUB: keyguardAlpha",
        )
}
Loading