• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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 android.util.LayoutDirection
20 import com.android.app.animation.Interpolators.EMPHASIZED
21 import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
22 import com.android.systemui.dagger.SysUISingleton
23 import com.android.systemui.keyguard.dagger.GlanceableHubBlurComponent
24 import com.android.systemui.keyguard.shared.model.Edge
25 import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
26 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB
27 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
28 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition
29 import com.android.systemui.keyguard.ui.transitions.GlanceableHubTransition
30 import com.android.systemui.res.R
31 import com.android.systemui.scene.shared.model.Scenes
32 import com.android.systemui.shade.ShadeDisplayAware
33 import javax.inject.Inject
34 import kotlin.time.Duration.Companion.milliseconds
35 import kotlin.time.Duration.Companion.seconds
36 import kotlinx.coroutines.flow.Flow
37 import kotlinx.coroutines.flow.flatMapLatest
38 import kotlinx.coroutines.flow.map
39 
40 @SysUISingleton
41 class DreamingToGlanceableHubTransitionViewModel
42 @Inject
43 constructor(
44     animationFlow: KeyguardTransitionAnimationFlow,
45     @ShadeDisplayAware configurationInteractor: ConfigurationInteractor,
46     private val blurFactory: GlanceableHubBlurComponent.Factory,
47 ) : DeviceEntryIconTransition, GlanceableHubTransition {
48     private val transitionAnimation =
49         animationFlow
50             .setup(
51                 duration = TO_GLANCEABLE_HUB_DURATION,
52                 edge = Edge.create(from = DREAMING, to = Scenes.Communal),
53             )
54             .setupWithoutSceneContainer(edge = Edge.create(from = DREAMING, to = GLANCEABLE_HUB))
55 
56     val dreamOverlayTranslationX: Flow<Float> =
57         configurationInteractor
58             .directionalDimensionPixelSize(
59                 LayoutDirection.LTR,
60                 R.dimen.dreaming_to_hub_transition_dream_overlay_translation_x,
61             )
62             .flatMapLatest { translatePx ->
63                 transitionAnimation.sharedFlow(
64                     duration = TO_GLANCEABLE_HUB_DURATION,
65                     onStep = { value -> value * translatePx },
66                     interpolator = EMPHASIZED,
67                     onCancel = { 0f },
68                     name = "DREAMING->GLANCEABLE_HUB: overlayTranslationX",
69                 )
70             }
71 
72     // Keep the dream visible while the hub swipes in over the dream.
73     val dreamAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(1f)
74 
75     val dreamOverlayAlpha: Flow<Float> =
76         transitionAnimation.sharedFlow(
77             duration = 167.milliseconds,
78             onStep = { 1f - it },
79             name = "DREAMING->GLANCEABLE_HUB: dreamOverlayAlpha",
80         )
81 
82     // Show UMO once the transition starts.
83     val showUmo: Flow<Boolean> =
84         transitionAnimation
85             .sharedFlow(
86                 duration = TO_GLANCEABLE_HUB_DURATION,
87                 onStep = { it },
88                 onCancel = { 0f },
89                 onFinish = { 1f },
90             )
91             .map { step -> step != 0f }
92 
93     override val deviceEntryParentViewAlpha: Flow<Float> =
94         transitionAnimation.sharedFlow(
95             startTime = 167.milliseconds,
96             duration = 167.milliseconds,
97             onStep = { it },
98             onCancel = { 1f },
99             onFinish = { 1f },
100         )
101 
102     private companion object {
103         val TO_GLANCEABLE_HUB_DURATION = 1.seconds
104     }
105 
106     override val windowBlurRadius: Flow<Float> =
107         blurFactory.create(transitionAnimation).getBlurProvider().enterBlurRadius
108 }
109