1 /*
2  * Copyright (C) 2022 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 package com.android.systemui.unfold.util
17 
18 import com.android.systemui.unfold.updates.FOLD_UPDATE_FINISH_FULL_OPEN
19 import com.android.systemui.unfold.updates.FOLD_UPDATE_FINISH_HALF_OPEN
20 import com.android.systemui.unfold.updates.FoldStateProvider
21 import com.android.systemui.unfold.updates.FoldStateProvider.FoldUpdate
22 import com.android.systemui.unfold.updates.FoldStateProvider.FoldUpdatesListener
23 
24 class TestFoldStateProvider : FoldStateProvider {
25 
26     private val listeners: MutableList<FoldUpdatesListener> = arrayListOf()
27     val hasListeners: Boolean
28         get() = listeners.isNotEmpty()
29 
30     override fun start() {
31     }
32 
33     override fun stop() {
34         listeners.clear()
35     }
36 
37     private var _isFinishedOpening: Boolean = false
38 
39     override val isFinishedOpening: Boolean
40         get() = _isFinishedOpening
41 
42     override fun addCallback(listener: FoldUpdatesListener) {
43         listeners += listener
44     }
45 
46     override fun removeCallback(listener: FoldUpdatesListener) {
47         listeners -= listener
48     }
49 
50     fun sendFoldUpdate(@FoldUpdate update: Int) {
51         if (update == FOLD_UPDATE_FINISH_FULL_OPEN || update == FOLD_UPDATE_FINISH_HALF_OPEN) {
52             _isFinishedOpening = true
53         }
54         listeners.forEach { it.onFoldUpdate(update) }
55     }
56 
57     fun sendHingeAngleUpdate(angle: Float) {
58         listeners.forEach { it.onHingeAngleUpdate(angle) }
59     }
60 
61     fun sendUnfoldedScreenAvailable() {
62         listeners.forEach { it.onUnfoldedScreenAvailable() }
63     }
64 }
65