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_ACCELERATE 20 import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.keyguard.domain.interactor.FromLockscreenTransitionInteractor.Companion.TO_OCCLUDED_DURATION 23 import com.android.systemui.keyguard.shared.model.Edge 24 import com.android.systemui.keyguard.shared.model.KeyguardState 25 import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED 26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 27 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 28 import com.android.systemui.res.R 29 import javax.inject.Inject 30 import kotlin.time.Duration.Companion.milliseconds 31 import kotlinx.coroutines.flow.Flow 32 import kotlinx.coroutines.flow.flatMapLatest 33 34 /** 35 * Breaks down LOCKSCREEN->OCCLUDED transition into discrete steps for corresponding views to 36 * consume. 37 */ 38 @SysUISingleton 39 class LockscreenToOccludedTransitionViewModel 40 @Inject 41 constructor( 42 shadeDependentFlows: ShadeDependentFlows, 43 configurationInteractor: ConfigurationInteractor, 44 animationFlow: KeyguardTransitionAnimationFlow, 45 ) : DeviceEntryIconTransition { 46 47 private val transitionAnimation = 48 animationFlow.setup( 49 duration = TO_OCCLUDED_DURATION, 50 edge = Edge.create(from = KeyguardState.LOCKSCREEN, to = OCCLUDED), 51 ) 52 53 /** Lockscreen views alpha */ 54 val lockscreenAlpha: Flow<Float> = 55 transitionAnimation.sharedFlow( 56 duration = 250.milliseconds, 57 onStep = { 1f - it }, 58 name = "LOCKSCREEN->OCCLUDED: lockscreenAlpha", 59 ) 60 61 val shortcutsAlpha: Flow<Float> = 62 transitionAnimation.sharedFlow( 63 duration = 250.milliseconds, 64 onStep = { 1 - it }, 65 onFinish = { 0f }, 66 onCancel = { 1f }, 67 ) 68 69 /** Lockscreen views y-translation */ 70 val lockscreenTranslationY: Flow<Float> = 71 configurationInteractor 72 .dimensionPixelSize(R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y) 73 .flatMapLatest { translatePx -> 74 transitionAnimation.sharedFlow( 75 duration = TO_OCCLUDED_DURATION, 76 onStep = { value -> value * translatePx }, 77 // Reset on cancel or finish 78 onFinish = { 0f }, 79 onCancel = { 0f }, 80 interpolator = EMPHASIZED_ACCELERATE, 81 ) 82 } 83 84 override val deviceEntryParentViewAlpha: Flow<Float> = 85 shadeDependentFlows.transitionFlow( 86 flowWhenShadeIsNotExpanded = lockscreenAlpha, 87 flowWhenShadeIsExpanded = transitionAnimation.immediatelyTransitionTo(0f), 88 ) 89 } 90