• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.keyguard.ui.viewmodel
18 
19 import com.android.systemui.Flags
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.keyguard.domain.interactor.FromOccludedTransitionInteractor
22 import com.android.systemui.keyguard.shared.model.Edge
23 import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
24 import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
25 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
26 import com.android.systemui.keyguard.ui.transitions.BlurConfig
27 import com.android.systemui.keyguard.ui.transitions.PrimaryBouncerTransition
28 import javax.inject.Inject
29 import kotlinx.coroutines.flow.Flow
30 import kotlinx.coroutines.flow.emptyFlow
31 
32 @SysUISingleton
33 class OccludedToPrimaryBouncerTransitionViewModel
34 @Inject
35 constructor(
36     shadeDependentFlows: ShadeDependentFlows,
37     blurConfig: BlurConfig,
38     animationFlow: KeyguardTransitionAnimationFlow,
39 ) : PrimaryBouncerTransition {
40     private val transitionAnimation =
41         animationFlow
42             .setup(
43                 duration = FromOccludedTransitionInteractor.TO_PRIMARY_BOUNCER_DURATION,
44                 edge = Edge.INVALID,
45             )
46             .setupWithoutSceneContainer(edge = Edge.create(OCCLUDED, PRIMARY_BOUNCER))
47 
48     /**
49      * Reasserts that lockscreen content should not be visible. It is possible the keyguard alpha is
50      * set to 1f if coming from an expanded shade that collapsed to launch an occluding activity.
51      */
52     val lockscreenAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f)
53 
54     override val windowBlurRadius: Flow<Float> =
55         shadeDependentFlows.transitionFlow(
56             flowWhenShadeIsExpanded =
57                 if (Flags.notificationShadeBlur()) {
58                     transitionAnimation.immediatelyTransitionTo(blurConfig.maxBlurRadiusPx)
59                 } else {
60                     transitionAnimation.immediatelyTransitionTo(blurConfig.minBlurRadiusPx)
61                 },
62             flowWhenShadeIsNotExpanded =
63                 transitionAnimation.immediatelyTransitionTo(blurConfig.maxBlurRadiusPx),
64         )
65 
66     override val notificationBlurRadius: Flow<Float> =
67         shadeDependentFlows.transitionFlow(
68             flowWhenShadeIsExpanded =
69                 transitionAnimation.immediatelyTransitionTo(blurConfig.maxBlurRadiusPx),
70             flowWhenShadeIsNotExpanded = emptyFlow(),
71         )
72 }
73