Added contentDescriptions for the keys and a new string resource

This commit is contained in:
merkost 2023-06-07 14:04:05 +10:00
parent 9901cfbc10
commit 52836b8e5f
4 changed files with 39 additions and 2 deletions

View File

@ -222,6 +222,41 @@ class MyKeyboard {
a.recycle()
}
/**
* Content description for talkback functional
*/
fun getContentDescription(context: Context): CharSequence {
return when (code) {
KEYCODE_SHIFT -> {
context.getString(R.string.keycode_shift)
}
KEYCODE_MODE_CHANGE -> {
context.getString(R.string.keycode_mode_change)
}
KEYCODE_ENTER -> {
context.getString(R.string.keycode_enter)
}
KEYCODE_DELETE -> {
context.getString(R.string.keycode_delete)
}
KEYCODE_SPACE -> {
context.getString(R.string.keycode_space)
}
KEYCODE_EMOJI -> {
context.getString(R.string.emojis)
}
else -> {
label
}
}
}
/** Create an empty key with no attributes. */
init {
height = parent.defaultHeight

View File

@ -147,7 +147,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
override fun onPopulateNodeForVirtualView(virtualViewId: Int, node: AccessibilityNodeInfoCompat) {
node.className = MyKeyboardView::class.simpleName
val key = mKeyboard?.mKeys?.get(virtualViewId)
node.contentDescription = key?.label ?: "keyboard key"
node.contentDescription = key?.getContentDescription(context)
val bounds = updateBoundsForInterval(virtualViewId)
node.setBoundsInParent(bounds)
}

View File

@ -26,6 +26,7 @@
<string name="keycode_mode_change">Изменить тип клавиатуры</string>
<string name="keycode_shift">Shift</string>
<string name="keycode_enter">Enter</string>
<string name="keycode_space">Пробел</string>
<!-- Settings -->
<string name="show_clipboard_content">Показывать содержимое буфера обмена при наличии</string>
<string name="show_popup">Показывать ввод по нажатию</string>
@ -40,4 +41,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -26,6 +26,7 @@
<string name="keycode_mode_change">Change keyboard type</string>
<string name="keycode_shift">Shift</string>
<string name="keycode_enter">Enter</string>
<string name="keycode_space">Space</string>
<!-- Settings -->
<string name="show_clipboard_content">Show clipboard content if available</string>
<string name="show_popup">Show a popup on keypress</string>