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 com.android.systemui.doze.util.BurnInHelperWrapper 21 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor 22 import kotlinx.coroutines.ExperimentalCoroutinesApi 23 import kotlinx.coroutines.flow.Flow 24 import kotlinx.coroutines.flow.distinctUntilChanged 25 import kotlinx.coroutines.flow.map 26 import javax.inject.Inject 27 28 class KeyguardAmbientIndicationViewModel 29 @Inject 30 constructor( 31 private val keyguardInteractor: KeyguardInteractor, 32 private val burnInHelperWrapper: BurnInHelperWrapper, 33 ) { 34 35 /** An observable for the x-offset by which the indication area should be translated. */ 36 val indicationAreaTranslationX: Flow<Float> = 37 keyguardInteractor.clockPosition.map { it.x.toFloat() }.distinctUntilChanged() 38 39 /** Returns an observable for the y-offset by which the indication area should be translated. */ 40 fun indicationAreaTranslationY(defaultBurnInOffset: Int): Flow<Float> { 41 return keyguardInteractor.dozeAmount 42 .map { dozeAmount -> 43 dozeAmount * 44 (burnInHelperWrapper.burnInOffset( 45 /* amplitude = */ defaultBurnInOffset * 2, 46 /* xAxis= */ false, 47 ) - defaultBurnInOffset) 48 } 49 .distinctUntilChanged() 50 } 51 }