1 /* <lambda>null2 * 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 com.android.app.animation.Interpolators.EMPHASIZED_DECELERATE 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryUdfpsInteractor 22 import com.android.systemui.keyguard.domain.interactor.FromGoneTransitionInteractor.Companion.TO_AOD_DURATION 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.GONE 26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 27 import com.android.systemui.keyguard.ui.StateToValue 28 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 29 import com.android.systemui.scene.shared.model.Scenes 30 import javax.inject.Inject 31 import kotlin.time.Duration.Companion.milliseconds 32 import kotlinx.coroutines.ExperimentalCoroutinesApi 33 import kotlinx.coroutines.flow.Flow 34 import kotlinx.coroutines.flow.emptyFlow 35 import kotlinx.coroutines.flow.flatMapLatest 36 37 /** Breaks down GONE->AOD transition into discrete steps for corresponding views to consume. */ 38 @ExperimentalCoroutinesApi 39 @SysUISingleton 40 class GoneToAodTransitionViewModel 41 @Inject 42 constructor( 43 deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor, 44 animationFlow: KeyguardTransitionAnimationFlow, 45 ) : DeviceEntryIconTransition { 46 47 private val transitionAnimation = 48 animationFlow 49 .setup( 50 duration = TO_AOD_DURATION, 51 edge = Edge.create(from = Scenes.Gone, to = AOD), 52 ) 53 .setupWithoutSceneContainer( 54 edge = Edge.create(from = GONE, to = AOD), 55 ) 56 57 /** y-translation from the top of the screen for AOD */ 58 fun enterFromTopTranslationY(translatePx: Int): Flow<StateToValue> { 59 return transitionAnimation.sharedFlowWithState( 60 startTime = 600.milliseconds, 61 duration = 500.milliseconds, 62 onStep = { translatePx + it * -translatePx }, 63 onFinish = { 0f }, 64 interpolator = EMPHASIZED_DECELERATE, 65 ) 66 } 67 68 val notificationAlpha: Flow<Float> = 69 transitionAnimation.sharedFlow( 70 duration = 200.milliseconds, 71 onStep = { 1f - it }, 72 // Needs to be 1f in order for HUNs to appear on AOD 73 onFinish = { 1f }, 74 ) 75 76 /** alpha animation upon entering AOD */ 77 val enterFromTopAnimationAlpha: Flow<Float> = 78 transitionAnimation.sharedFlow( 79 startTime = 700.milliseconds, 80 duration = 400.milliseconds, 81 onStep = { it }, 82 onFinish = { 1f }, 83 ) 84 val deviceEntryBackgroundViewAlpha: Flow<Float> = 85 transitionAnimation.immediatelyTransitionTo(0f) 86 override val deviceEntryParentViewAlpha: Flow<Float> = 87 deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { udfpsEnrolled -> 88 if (udfpsEnrolled) { 89 // fade in at the end of the transition to give time for FP to start running 90 // and avoid a flicker of the unlocked icon 91 transitionAnimation.sharedFlow( 92 startTime = 1100.milliseconds, 93 duration = 200.milliseconds, 94 onStep = { it }, 95 onFinish = { 1f }, 96 ) 97 } else { 98 emptyFlow() 99 } 100 } 101 } 102