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.FromAlternateBouncerTransitionInteractor.Companion.TO_GONE_DURATION 22 import com.android.systemui.keyguard.shared.model.Edge 23 import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER 24 import com.android.systemui.keyguard.shared.model.KeyguardState.GONE 25 import com.android.systemui.keyguard.shared.model.ScrimAlpha 26 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 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.flow.Flow 33 34 /** 35 * Breaks down ALTERNATE_BOUNCER->GONE transition into discrete steps for corresponding views to 36 * consume. 37 */ 38 @SysUISingleton 39 class AlternateBouncerToGoneTransitionViewModel 40 @Inject 41 constructor( 42 bouncerToGoneFlows: BouncerToGoneFlows, 43 animationFlow: KeyguardTransitionAnimationFlow, 44 private val statusBarStateController: SysuiStatusBarStateController, 45 ) : DeviceEntryIconTransition { 46 private val transitionAnimation = 47 animationFlow 48 .setup( 49 duration = TO_GONE_DURATION, 50 edge = Edge.create(from = ALTERNATE_BOUNCER, to = Scenes.Gone), 51 ) 52 .setupWithoutSceneContainer( 53 edge = Edge.create(from = ALTERNATE_BOUNCER, to = GONE), 54 ) 55 lockscreenAlphanull56 fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> { 57 var startAlpha = 1f 58 return transitionAnimation.sharedFlow( 59 duration = 200.milliseconds, 60 onStart = { startAlpha = viewState.alpha() }, 61 onStep = { MathUtils.lerp(startAlpha, 0f, it) }, 62 onFinish = { 0f }, 63 onCancel = { startAlpha }, 64 ) 65 } 66 notificationAlphanull67 fun notificationAlpha(viewState: ViewStateAccessor): Flow<Float> { 68 var startAlpha = 1f 69 var leaveShadeOpen = false 70 71 return transitionAnimation.sharedFlow( 72 duration = 200.milliseconds, 73 onStart = { 74 leaveShadeOpen = statusBarStateController.leaveOpenOnKeyguardHide() 75 startAlpha = viewState.alpha() 76 }, 77 onStep = { 78 if (leaveShadeOpen) { 79 1f 80 } else { 81 MathUtils.lerp(startAlpha, 0f, it) 82 } 83 }, 84 onFinish = { 1f }, 85 ) 86 } 87 88 /** See [BouncerToGoneFlows#showAllNotifications] */ 89 val showAllNotifications: Flow<Boolean> = 90 bouncerToGoneFlows.showAllNotifications(TO_GONE_DURATION, ALTERNATE_BOUNCER) 91 92 /** Scrim alpha values */ 93 val scrimAlpha: Flow<ScrimAlpha> = 94 bouncerToGoneFlows.scrimAlpha(TO_GONE_DURATION, ALTERNATE_BOUNCER) 95 96 override val deviceEntryParentViewAlpha: Flow<Float> = 97 transitionAnimation.immediatelyTransitionTo(0f) 98 } 99