• 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.app.animation.Interpolators.EMPHASIZED_ACCELERATE
20 import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.keyguard.domain.interactor.FromLockscreenTransitionInteractor.Companion.TO_OCCLUDED_DURATION
23 import com.android.systemui.keyguard.shared.model.Edge
24 import com.android.systemui.keyguard.shared.model.KeyguardState
25 import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
27 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition
28 import com.android.systemui.res.R
29 import com.android.systemui.shade.ShadeDisplayAware
30 import javax.inject.Inject
31 import kotlin.time.Duration.Companion.milliseconds
32 import kotlinx.coroutines.flow.Flow
33 import kotlinx.coroutines.flow.flatMapLatest
34 
35 /**
36  * Breaks down LOCKSCREEN->OCCLUDED transition into discrete steps for corresponding views to
37  * consume.
38  */
39 @SysUISingleton
40 class LockscreenToOccludedTransitionViewModel
41 @Inject
42 constructor(
43     shadeDependentFlows: ShadeDependentFlows,
44     @ShadeDisplayAware configurationInteractor: ConfigurationInteractor,
45     animationFlow: KeyguardTransitionAnimationFlow,
46 ) : DeviceEntryIconTransition {
47 
48     private val transitionAnimation =
49         animationFlow.setup(
50             duration = TO_OCCLUDED_DURATION,
51             edge = Edge.create(from = KeyguardState.LOCKSCREEN, to = OCCLUDED),
52         )
53 
54     /** Lockscreen views alpha */
55     val lockscreenAlpha: Flow<Float> =
56         shadeDependentFlows.transitionFlow(
57             flowWhenShadeIsNotExpanded =
58                 transitionAnimation.sharedFlow(
59                     duration = 250.milliseconds,
60                     onStep = { 1f - it },
61                     name = "LOCKSCREEN->OCCLUDED: lockscreenAlpha",
62                 ),
63             flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f),
64         )
65 
66     val shortcutsAlpha: Flow<Float> =
67         shadeDependentFlows.transitionFlow(
68             flowWhenShadeIsNotExpanded =
69                 transitionAnimation.sharedFlow(
70                     duration = 250.milliseconds,
71                     onStep = { 1f - it },
72                     onFinish = { 0f },
73                     onCancel = { 1f },
74                 ),
75             flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f),
76         )
77 
78     /** Lockscreen views y-translation */
79     val lockscreenTranslationY: Flow<Float> =
80         configurationInteractor
81             .dimensionPixelSize(R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y)
82             .flatMapLatest { translatePx ->
83                 transitionAnimation.sharedFlow(
84                     duration = TO_OCCLUDED_DURATION,
85                     onStep = { value -> value * translatePx },
86                     // Reset on cancel or finish
87                     onFinish = { 0f },
88                     onCancel = { 0f },
89                     interpolator = EMPHASIZED_ACCELERATE,
90                 )
91             }
92 
93     override val deviceEntryParentViewAlpha: Flow<Float> =
94         shadeDependentFlows.transitionFlow(
95             flowWhenShadeIsNotExpanded =
96                 transitionAnimation.sharedFlow(
97                     duration = 250.milliseconds,
98                     onStep = { 1f - it },
99                     onCancel = { 0f },
100                 ),
101             flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f),
102         )
103 }
104