1 /* 2 * 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 android.util.MathUtils 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.keyguard.domain.interactor.FromLockscreenTransitionInteractor 22 import com.android.systemui.keyguard.shared.model.Edge 23 import com.android.systemui.keyguard.shared.model.KeyguardState.GONE 24 import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN 25 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow.FlowBuilder 27 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 28 import com.android.systemui.scene.shared.model.Scenes 29 import com.android.systemui.statusbar.SysuiStatusBarStateController 30 import javax.inject.Inject 31 import kotlin.time.Duration.Companion.milliseconds 32 import kotlinx.coroutines.ExperimentalCoroutinesApi 33 import kotlinx.coroutines.flow.Flow 34 35 /** 36 * Breaks down LOCKSCREEN->GONE transition into discrete steps for corresponding views to consume. 37 */ 38 @ExperimentalCoroutinesApi 39 @SysUISingleton 40 class LockscreenToGoneTransitionViewModel 41 @Inject 42 constructor( 43 animationFlow: KeyguardTransitionAnimationFlow, 44 private val statusBarStateController: SysuiStatusBarStateController, 45 ) : DeviceEntryIconTransition { 46 47 private val transitionAnimation: FlowBuilder = 48 animationFlow 49 .setup( 50 duration = FromLockscreenTransitionInteractor.TO_GONE_DURATION, 51 edge = Edge.create(from = LOCKSCREEN, to = Scenes.Gone), 52 ) 53 .setupWithoutSceneContainer( 54 edge = Edge.create(from = LOCKSCREEN, to = GONE), 55 ) 56 57 val shortcutsAlpha: Flow<Float> = 58 transitionAnimation.sharedFlow( 59 duration = 200.milliseconds, <lambda>null60 onStep = { 1 - it }, <lambda>null61 onFinish = { 0f }, <lambda>null62 onCancel = { 1f }, 63 ) 64 notificationAlphanull65 fun notificationAlpha(viewState: ViewStateAccessor): Flow<Float> { 66 var startAlpha = 1f 67 var leaveShadeOpen = false 68 69 return transitionAnimation.sharedFlow( 70 duration = 200.milliseconds, 71 onStart = { 72 leaveShadeOpen = statusBarStateController.leaveOpenOnKeyguardHide() 73 startAlpha = viewState.alpha() 74 }, 75 onStep = { 76 if (leaveShadeOpen) { 77 1f 78 } else { 79 MathUtils.lerp(startAlpha, 0f, it) 80 } 81 }, 82 ) 83 } 84 lockscreenAlphanull85 fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> { 86 var startAlpha = 1f 87 return transitionAnimation.sharedFlow( 88 duration = 200.milliseconds, 89 onStart = { startAlpha = viewState.alpha() }, 90 onStep = { MathUtils.lerp(startAlpha, 0f, it) }, 91 onFinish = { 0f }, 92 onCancel = { 1f }, 93 ) 94 } 95 96 override val deviceEntryParentViewAlpha: Flow<Float> = 97 transitionAnimation.immediatelyTransitionTo(0f) 98 } 99