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
apply plugin: 'com.github.dcendents.android-maven' | |
apply plugin: 'com.jfrog.bintray' | |
// load properties | |
Properties properties = new Properties() | |
File localPropertiesFile = project.file("local.properties") | |
if(localPropertiesFile.exists()){ | |
properties.load(localPropertiesFile.newDataInputStream()) | |
} | |
else { |
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 TalkBackFacade @Inject constructor(private val contextWeakReference: WeakReference<Context>) { | |
fun isTalkBackEnabled() = Settings.Secure.getString( | |
contextWeakReference.get()?.contentResolver, | |
Settings.Secure.ACCESSIBILITY_ENABLED | |
)?.toInt()?.toBoolean() | |
?: false | |
fun enableTalkBack() = changeAccessibilityServicesState( | |
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
/** | |
* 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 | |
} |
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
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
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 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
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
/** | |
* Extension function to set touch values for accessibility | |
*/ | |
fun List<View>.enableAccessibilityFocus() { | |
this.forEach { | |
it.setAccessibilityFocus() | |
} | |
} | |
/** |
OlderNewer