• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 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.dagger.SysUISingleton
20 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryUdfpsInteractor
21 import com.android.systemui.keyguard.domain.interactor.FromPrimaryBouncerTransitionInteractor
22 import com.android.systemui.keyguard.shared.model.Edge
23 import com.android.systemui.keyguard.shared.model.KeyguardState.AOD
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.DeviceEntryIconTransition
28 import com.android.systemui.keyguard.ui.transitions.PrimaryBouncerTransition
29 import com.android.systemui.scene.shared.model.Overlays
30 import javax.inject.Inject
31 import kotlin.time.Duration.Companion.milliseconds
32 import kotlinx.coroutines.flow.Flow
33 import kotlinx.coroutines.flow.emptyFlow
34 import kotlinx.coroutines.flow.flatMapLatest
35 
36 /**
37  * Breaks down PRIMARY BOUNCER->AOD transition into discrete steps for corresponding views to
38  * consume.
39  */
40 @SysUISingleton
41 class PrimaryBouncerToAodTransitionViewModel
42 @Inject
43 constructor(
44     private val blurConfig: BlurConfig,
45     deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor,
46     animationFlow: KeyguardTransitionAnimationFlow,
47 ) : DeviceEntryIconTransition, PrimaryBouncerTransition {
48     private val transitionAnimation =
49         animationFlow
50             .setup(
51                 duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION,
52                 edge = Edge.create(from = Overlays.Bouncer, to = AOD),
53             )
54             .setupWithoutSceneContainer(edge = Edge.create(from = PRIMARY_BOUNCER, to = AOD))
55 
56     val deviceEntryBackgroundViewAlpha: Flow<Float> =
57         transitionAnimation.immediatelyTransitionTo(0f)
58 
59     val lockscreenAlpha: Flow<Float> =
60         transitionAnimation.sharedFlow(
61             duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION,
62             onStep = { it },
63         )
64 
65     override val deviceEntryParentViewAlpha: Flow<Float> =
66         deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest {
67             isUdfpsEnrolledAndEnabled ->
68             if (isUdfpsEnrolledAndEnabled) {
69                 transitionAnimation.sharedFlow(
70                     duration = 300.milliseconds,
71                     onStep = { it },
72                     onCancel = { 1f },
73                     onFinish = { 1f },
74                 )
75             } else {
76                 emptyFlow()
77             }
78         }
79 
80     override val windowBlurRadius: Flow<Float> =
81         transitionAnimation.sharedFlow(
82             duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION,
83             onStep = { step ->
84                 transitionProgressToBlurRadius(
85                     starBlurRadius = blurConfig.maxBlurRadiusPx,
86                     endBlurRadius = blurConfig.minBlurRadiusPx,
87                     transitionProgress = step,
88                 )
89             },
90             onFinish = { blurConfig.minBlurRadiusPx },
91         )
92 
93     override val notificationBlurRadius: Flow<Float> =
94         transitionAnimation.immediatelyTransitionTo(0.0f)
95 }
96