This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CarouselKeyEventDelegate : BaseKeyEventDelegate() { | |
init { | |
keyEventActionMap.let { | |
it.put( | |
createKey( | |
R.id.carousel_container, | |
KEYCODE_DPAD_DOWN | |
), | |
this::consumeDownKeyOnCarouselContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun onDownKeyPressed(currentFocus: View): Boolean = with(currentFocus) { | |
getNextElementPosition().let { nextElementPosition -> | |
if (isPositionInbound(nextElementPosition)) { | |
sendFocusToListItem(nextElementPosition) | |
} else { | |
rootView.findViewById<View>(R.id.carouselRV)?.sendAccessibilityFocus() | |
} | |
} | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extension function to set touch values for accessibility | |
*/ | |
fun List<View>.enableAccessibilityFocus() { | |
this.forEach { | |
it.setAccessibilityFocus() | |
} | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GeneralKeyEventDelegate : BaseKeyEventDelegate() { | |
init { | |
keyEventActionMap.let { | |
it.put( | |
createKey( | |
R.id.accessibility_state, | |
KEYCODE_DPAD_DOWN, | |
ACTION_DOWN | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val KEYCODE_CHANGE_ACCESSIBILITY_STATE = KeyEvent.KEYCODE_S | |
class KeyEventHandler @Inject constructor() { | |
/** | |
* Contains all possible accessibility actions available for the current Activity. | |
*/ | |
private var keyEventActionMap = SparseArrayCompat<KeyEventAction>() | |
fun addKeyEventDelegate(keyEventDelegateImpl: BaseKeyEventDelegate) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun dispatchKeyEvent(event: KeyEvent?): Boolean { | |
return event?.let { | |
currentFocus?.let { focusView -> | |
talkBackViewModel.dispatchKeyEvent(it, WeakReference(focusView)) | |
} | |
} ?: super.dispatchKeyEvent(event) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val DELAY_AFTER_TALK_BACK_GETS_STARTED = 400L | |
fun View.weakPostDelayed(delay: Long = DELAY_AFTER_TALK_BACK_GETS_STARTED, code: (View) -> Unit) { | |
postDelayed(WeakRunnable(this) { | |
code(it) | |
}, delay) | |
} | |
class WeakRunnable<T>(instance: T?, private val action: (T) -> Unit) : Runnable { | |
private val weakReference: WeakReference<T?> = WeakReference(instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* With this function we are observing a specific accessibility service started/stopped: TalkBack | |
*/ | |
private fun onTalkBackStateChanged(isOn: Boolean) { | |
if (isOn) { | |
accessibility_state.text = getString(R.string.accessibility_state_on) | |
accessibility_state.weakPostDelayed { sendFocusToTitle() } | |
} else { | |
accessibility_state.text = getString(R.string.accessibility_state_off) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Observe for any accessibility service state change. Use [AccessibilityManager] to list | |
* current accessibility service ON or send [AccessibilityEvent] like a speech out. | |
*/ | |
private fun listenForAccessibilityServiceStatus(context: Context) { | |
val accessibilityManager = | |
context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager | |
accessibilityManager.addAccessibilityStateChangeListener { enabled -> | |
// Do your stuff | |
} |
NewerOlder