1 /*
<lambda>null2  * Copyright (C) 2024 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.wallpaper.testing
18 
19 import android.app.UiModeManager.ContrastChangeListener
20 import com.android.wallpaper.system.UiModeManagerWrapper
21 import java.util.concurrent.Executor
22 import javax.inject.Inject
23 import javax.inject.Singleton
24 
25 @Singleton
26 class FakeUiModeManager @Inject constructor() : UiModeManagerWrapper {
27     val listeners = mutableListOf<ContrastChangeListener>()
28     private var contrast: Float? = 0.0f
29     private var isNightModeActivated: Boolean = false
30 
31     override fun addContrastChangeListener(executor: Executor, listener: ContrastChangeListener) {
32         listeners.add(listener)
33     }
34 
35     override fun removeContrastChangeListener(listener: ContrastChangeListener) {
36         listeners.remove(listener)
37     }
38 
39     override fun getContrast(): Float? {
40         return contrast
41     }
42 
43     fun setContrast(contrast: Float?) {
44         this.contrast = contrast
45         contrast?.let { v -> listeners.forEach { it.onContrastChanged(v) } }
46     }
47 
48     override fun getIsNightModeActivated(): Boolean {
49         return isNightModeActivated
50     }
51 
52     override fun setNightModeActivated(isActive: Boolean) {
53         isNightModeActivated = isActive
54     }
55 }
56