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.FromAodTransitionInteractor 22 import com.android.systemui.keyguard.shared.model.Edge 23 import com.android.systemui.keyguard.shared.model.KeyguardState.AOD 24 import com.android.systemui.keyguard.shared.model.KeyguardState.GONE 25 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 26 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 27 import com.android.systemui.scene.shared.model.Scenes 28 import javax.inject.Inject 29 import kotlin.time.Duration.Companion.milliseconds 30 import kotlinx.coroutines.flow.Flow 31 32 /** Breaks down AOD->GONE transition into discrete steps for corresponding views to consume. */ 33 @SysUISingleton 34 class AodToGoneTransitionViewModel 35 @Inject 36 constructor( 37 animationFlow: KeyguardTransitionAnimationFlow, 38 ) : DeviceEntryIconTransition { 39 40 private val transitionAnimation = 41 animationFlow 42 .setup( 43 duration = FromAodTransitionInteractor.TO_GONE_DURATION, 44 edge = Edge.create(from = AOD, to = Scenes.Gone), 45 ) 46 .setupWithoutSceneContainer( 47 edge = Edge.create(from = AOD, to = GONE), 48 ) 49 50 /** 51 * AOD -> GONE should fade out the lockscreen contents. This transition plays both during wake 52 * and unlock, and also during insecure camera launch (which is GONE -> AOD (canceled) -> GONE). 53 */ lockscreenAlphanull54 fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> { 55 var startAlpha = 1f 56 return transitionAnimation.sharedFlow( 57 duration = 200.milliseconds, 58 onStart = { startAlpha = viewState.alpha() }, 59 onStep = { MathUtils.lerp(startAlpha, 0f, it) }, 60 onFinish = { 0f }, 61 ) 62 } 63 notificationAlphanull64 fun notificationAlpha(viewState: ViewStateAccessor): Flow<Float> { 65 var startAlpha = 1f 66 return transitionAnimation.sharedFlow( 67 duration = 200.milliseconds, 68 onStart = { startAlpha = viewState.alpha() }, 69 onStep = { startAlpha }, 70 onFinish = { 1f }, 71 ) 72 } 73 74 override val deviceEntryParentViewAlpha = transitionAnimation.immediatelyTransitionTo(0f) 75 } 76