From a401e9dbf4f76a44c60e8ef6ca043f168b222866 Mon Sep 17 00:00:00 2001 From: Adula Date: Fri, 24 Jul 2026 14:41:10 +0200 Subject: [PATCH] Fix accessibility: Open keyboard on TalkBack double-tap Overrides performClick and onFocusChanged to ensure the keyboard is shown when blind users double tap EditText fields using screen readers like TalkBack. --- .../view/misc/EditTextWithWatcher.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/philkes/notallyx/presentation/view/misc/EditTextWithWatcher.kt b/app/src/main/java/com/philkes/notallyx/presentation/view/misc/EditTextWithWatcher.kt index d872e2f5..8591b76a 100644 --- a/app/src/main/java/com/philkes/notallyx/presentation/view/misc/EditTextWithWatcher.kt +++ b/app/src/main/java/com/philkes/notallyx/presentation/view/misc/EditTextWithWatcher.kt @@ -1,7 +1,6 @@ package com.philkes.notallyx.presentation.view.misc import android.content.Context -import android.os.Build import android.text.Editable import android.text.TextWatcher import android.text.method.KeyListener @@ -17,6 +16,8 @@ open class EditTextWithWatcher(context: Context, attrs: AttributeSet) : private var onSelectionChange: ((selStart: Int, selEnd: Int) -> Unit)? = null private var keyListenerInstance: KeyListener? = null + private var isEditableMode = true + override fun onSelectionChanged(selStart: Int, selEnd: Int) { super.onSelectionChanged(selStart, selEnd) onSelectionChange?.invoke(selStart, selEnd) @@ -35,6 +36,7 @@ open class EditTextWithWatcher(context: Context, attrs: AttributeSet) : } fun setCanEdit(value: Boolean) { + isEditableMode = value if (!value) { clearFocus() } @@ -44,19 +46,26 @@ open class EditTextWithWatcher(context: Context, attrs: AttributeSet) : isFocusable = value isFocusableInTouchMode = value setTextIsSelectable(true) + } + + override fun onFocusChanged( + focused: Boolean, + direction: Int, + previouslyFocusedRect: android.graphics.Rect?, + ) { + super.onFocusChanged(focused, direction, previouslyFocusedRect) + if (focused && isEditableMode) { + context.showKeyboard(this) + } + } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) { - setOnClickListener { - if (value) { - context.showKeyboard(this) - } - } - setOnFocusChangeListener { v, hasFocus -> - if (hasFocus && value) { - context.showKeyboard(this) - } - } + override fun performClick(): Boolean { + val result = super.performClick() + if (isEditableMode) { + context.showKeyboard(this) + return true } + return result } @Deprecated(