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.domain.interactor.FromLockscreenTransitionInteractor 25 import com.android.systemui.keyguard.shared.model.Edge 26 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB 27 import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN 28 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 29 import com.android.systemui.keyguard.ui.StateToValue 30 import com.android.systemui.keyguard.ui.transitions.GlanceableHubTransition 31 import com.android.systemui.res.R 32 import com.android.systemui.scene.shared.model.Scenes 33 import com.android.systemui.shade.ShadeDisplayAware 34 import javax.inject.Inject 35 import kotlin.time.Duration.Companion.milliseconds 36 import kotlinx.coroutines.flow.Flow 37 import kotlinx.coroutines.flow.filterNotNull 38 import kotlinx.coroutines.flow.flatMapLatest 39 import kotlinx.coroutines.flow.map 40 41 /** 42 * Breaks down LOCKSCREEN->GLANCEABLE_HUB transition into discrete steps for corresponding views to 43 * consume. 44 */ 45 @SysUISingleton 46 class LockscreenToGlanceableHubTransitionViewModel 47 @Inject 48 constructor( 49 @ShadeDisplayAware configurationInteractor: ConfigurationInteractor, 50 animationFlow: KeyguardTransitionAnimationFlow, 51 private val blurFactory: GlanceableHubBlurComponent.Factory, 52 ) : GlanceableHubTransition { 53 54 private val transitionAnimation = 55 animationFlow 56 .setup( 57 duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION, 58 edge = Edge.create(from = LOCKSCREEN, to = Scenes.Communal), 59 ) 60 .setupWithoutSceneContainer(edge = Edge.create(from = LOCKSCREEN, to = GLANCEABLE_HUB)) 61 62 override val windowBlurRadius: Flow<Float> = 63 blurFactory.create(transitionAnimation).getBlurProvider().enterBlurRadius 64 65 val keyguardAlpha: Flow<Float> = 66 transitionAnimation.sharedFlow( 67 duration = 167.milliseconds, 68 onStep = { 1f - it }, 69 onFinish = { 0f }, 70 onCancel = { 1f }, 71 name = "LOCKSCREEN->GLANCEABLE_HUB: keyguardAlpha", 72 ) 73 74 // Show UMO as long as keyguard is not visible. 75 val showUmo: Flow<Boolean> = keyguardAlpha.map { alpha -> alpha == 0f } 76 77 val keyguardTranslationX: Flow<StateToValue> = 78 configurationInteractor 79 .directionalDimensionPixelSize( 80 LayoutDirection.LTR, 81 R.dimen.lockscreen_to_hub_transition_lockscreen_translation_x, 82 ) 83 .flatMapLatest { translatePx: Int -> 84 transitionAnimation.sharedFlowWithState( 85 duration = FromLockscreenTransitionInteractor.TO_GLANCEABLE_HUB_DURATION, 86 onStep = { value -> value * translatePx }, 87 // Move notifications back to their original position since they can be 88 // accessed from the shade, and also keyguard elements in case the animation 89 // is cancelled. 90 onFinish = { 0f }, 91 onCancel = { 0f }, 92 interpolator = EMPHASIZED, 93 name = "LOCKSCREEN->GLANCEABLE_HUB: keyguardTranslationX", 94 ) 95 } 96 97 val notificationAlpha: Flow<Float> = keyguardAlpha 98 99 val shortcutsAlpha: Flow<Float> = keyguardAlpha 100 101 val statusBarAlpha: Flow<Float> = keyguardAlpha 102 103 val notificationTranslationX: Flow<Float> = 104 keyguardTranslationX.map { it.value }.filterNotNull() 105 } 106