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() 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. */ /** Create an empty key with no attributes. */
init { init {
height = parent.defaultHeight height = parent.defaultHeight

View File

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

View File

@ -26,6 +26,7 @@
<string name="keycode_mode_change">Изменить тип клавиатуры</string> <string name="keycode_mode_change">Изменить тип клавиатуры</string>
<string name="keycode_shift">Shift</string> <string name="keycode_shift">Shift</string>
<string name="keycode_enter">Enter</string> <string name="keycode_enter">Enter</string>
<string name="keycode_space">Пробел</string>
<!-- Settings --> <!-- Settings -->
<string name="show_clipboard_content">Показывать содержимое буфера обмена при наличии</string> <string name="show_clipboard_content">Показывать содержимое буфера обмена при наличии</string>
<string name="show_popup">Показывать ввод по нажатию</string> <string name="show_popup">Показывать ввод по нажатию</string>

View File

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