Revision control

Copy as Markdown

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.focus.architecture
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.annotation.UiThread
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.PRIVATE
import android.view.accessibility.AccessibilityManager
/**
* A model to hold state related to the Android framework.
*/
class FrameworkRepo {
private val _isVoiceViewEnabled = MutableLiveData<Boolean>()
val isVoiceViewEnabled: LiveData<Boolean> = _isVoiceViewEnabled
@VisibleForTesting(otherwise = PRIVATE) val touchExplorationStateChangeListener = TouchExplorationStateChangeListener()
fun init(accessibilityManager: AccessibilityManager) {
// We call the listener directly to set the initial state.
accessibilityManager.addTouchExplorationStateChangeListener(touchExplorationStateChangeListener)
touchExplorationStateChangeListener.onTouchExplorationStateChanged(accessibilityManager.isTouchExplorationEnabled)
}
@VisibleForTesting(otherwise = PRIVATE)
inner class TouchExplorationStateChangeListener : AccessibilityManager.TouchExplorationStateChangeListener {
@UiThread // for simplicity: listener should be called from UI thread anyway.
override fun onTouchExplorationStateChanged(isEnabled: Boolean) {
_isVoiceViewEnabled.value = isEnabled // Touch exploration state == VoiceView.
}
}
}