1 /* 2 * Copyright (C) 2025 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.MathUtils 20 import com.android.systemui.communal.ui.compose.TransitionDuration 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.keyguard.dagger.GlanceableHubBlurComponent 23 import com.android.systemui.keyguard.shared.model.Edge 24 import com.android.systemui.keyguard.shared.model.KeyguardState.AOD 25 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB 26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 27 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 28 import com.android.systemui.keyguard.ui.transitions.GlanceableHubTransition 29 import com.android.systemui.scene.shared.model.Scenes 30 import com.android.systemui.shared.Flags.ambientAod 31 import javax.inject.Inject 32 import kotlin.time.Duration.Companion.milliseconds 33 import kotlinx.coroutines.flow.Flow 34 35 @SysUISingleton 36 class AodToGlanceableHubTransitionViewModel 37 @Inject 38 constructor( 39 animationFlow: KeyguardTransitionAnimationFlow, 40 blurFactory: GlanceableHubBlurComponent.Factory, 41 ) : DeviceEntryIconTransition, GlanceableHubTransition { 42 private val transitionAnimation = 43 animationFlow 44 .setup( 45 duration = TransitionDuration.TO_GLANCEABLE_HUB_DURATION_MS.milliseconds, 46 edge = Edge.create(AOD, Scenes.Communal), 47 ) 48 .setupWithoutSceneContainer(edge = Edge.create(AOD, GLANCEABLE_HUB)) 49 50 override val deviceEntryParentViewAlpha: Flow<Float> = 51 transitionAnimation.immediatelyTransitionTo(1f) 52 53 /** Fade out the lockscreen during a transition to GLANCEABLE_HUB. */ lockscreenAlphanull54 fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> { 55 var currentAlpha = 0f 56 return transitionAnimation.sharedFlow( 57 duration = 250.milliseconds, 58 startTime = 59 if (ambientAod()) { 60 100.milliseconds // Wait for the light reveal to "hit" the LS elements. 61 } else { 62 0.milliseconds 63 }, 64 onStart = { 65 currentAlpha = 66 if (ambientAod()) { 67 viewState.alpha() 68 } else { 69 0f 70 } 71 }, 72 onStep = { MathUtils.lerp(currentAlpha, 0f, it) }, 73 ) 74 } 75 76 override val windowBlurRadius: Flow<Float> = 77 blurFactory.create(transitionAnimation).getBlurProvider().enterBlurRadius 78 } 79