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 18 package com.android.systemui.keyguard.ui.viewmodel 19 20 import android.graphics.Color 21 import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor 22 import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER 23 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager 24 import javax.inject.Inject 25 import kotlinx.coroutines.ExperimentalCoroutinesApi 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.distinctUntilChanged 28 import kotlinx.coroutines.flow.flowOf 29 import kotlinx.coroutines.flow.map 30 31 @ExperimentalCoroutinesApi 32 class AlternateBouncerViewModel 33 @Inject 34 constructor( 35 private val statusBarKeyguardViewManager: StatusBarKeyguardViewManager, 36 keyguardTransitionInteractor: KeyguardTransitionInteractor, 37 ) { 38 // When we're fully transitioned to the AlternateBouncer, the alpha of the scrim should be: 39 private val alternateBouncerScrimAlpha = .66f 40 41 /** Progress to a fully transitioned alternate bouncer. 1f represents fully transitioned. */ 42 val transitionToAlternateBouncerProgress = 43 keyguardTransitionInteractor.transitionValue(ALTERNATE_BOUNCER) 44 45 val forcePluginOpen: Flow<Boolean> = <lambda>null46 transitionToAlternateBouncerProgress.map { it > 0f }.distinctUntilChanged() 47 48 /** An observable for the scrim alpha. */ <lambda>null49 val scrimAlpha = transitionToAlternateBouncerProgress.map { it * alternateBouncerScrimAlpha } 50 51 /** An observable for the scrim color. Change color for easier debugging. */ 52 val scrimColor: Flow<Int> = flowOf(Color.BLACK) 53 54 val registerForDismissGestures: Flow<Boolean> = <lambda>null55 transitionToAlternateBouncerProgress.map { it == 1f }.distinctUntilChanged() 56 showPrimaryBouncernull57 fun showPrimaryBouncer() { 58 statusBarKeyguardViewManager.showPrimaryBouncer(/* scrimmed */ true) 59 } 60 hideAlternateBouncernull61 fun hideAlternateBouncer() { 62 statusBarKeyguardViewManager.hideAlternateBouncer(false) 63 } 64 } 65