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 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 GlanceableHubToDreamingTransitionViewModel 42 @Inject 43 constructor( 44 animationFlow: KeyguardTransitionAnimationFlow, 45 @ShadeDisplayAware configurationInteractor: ConfigurationInteractor, 46 private val blurFactory: GlanceableHubBlurComponent.Factory, 47 ) : DeviceEntryIconTransition, GlanceableHubTransition { 48 49 private val transitionAnimation = 50 animationFlow 51 .setup( 52 duration = FROM_GLANCEABLE_HUB_DURATION, 53 edge = Edge.create(from = Scenes.Communal, to = DREAMING), 54 ) 55 .setupWithoutSceneContainer(edge = Edge.create(from = GLANCEABLE_HUB, to = DREAMING)) 56 57 val dreamOverlayAlpha: Flow<Float> = 58 transitionAnimation.sharedFlow( 59 duration = 167.milliseconds, 60 startTime = 167.milliseconds, 61 onStep = { it }, 62 name = "GLANCEABLE_HUB->DREAMING: dreamOverlayAlpha", 63 ) 64 65 val dreamOverlayTranslationX: Flow<Float> = 66 configurationInteractor 67 .directionalDimensionPixelSize( 68 LayoutDirection.LTR, 69 R.dimen.hub_to_dreaming_transition_dream_overlay_translation_x, 70 ) 71 .flatMapLatest { translatePx: Int -> 72 transitionAnimation.sharedFlow( 73 duration = FROM_GLANCEABLE_HUB_DURATION, 74 onStep = { value -> -translatePx + value * translatePx }, 75 interpolator = Interpolators.EMPHASIZED, 76 onCancel = { -translatePx.toFloat() }, 77 name = "GLANCEABLE_HUB->LOCKSCREEN: dreamOverlayTranslationX", 78 ) 79 } 80 81 // Show UMO until transition finishes. 82 val showUmo: Flow<Boolean> = 83 transitionAnimation 84 .sharedFlow( 85 duration = FROM_GLANCEABLE_HUB_DURATION, 86 onStep = { it }, 87 onCancel = { 0f }, 88 onFinish = { 1f }, 89 ) 90 .map { step -> step != 1f } 91 92 override val deviceEntryParentViewAlpha: Flow<Float> = 93 transitionAnimation.sharedFlow( 94 duration = 167.milliseconds, 95 onStep = { 1 - it }, 96 onCancel = { 0f }, 97 onFinish = { 0f }, 98 ) 99 100 override val windowBlurRadius: Flow<Float> = 101 blurFactory.create(transitionAnimation).getBlurProvider().exitBlurRadius 102 103 private companion object { 104 val FROM_GLANCEABLE_HUB_DURATION = 1.seconds 105 } 106 } 107