fix: set focusable before request focus

This commit is contained in:
mcfans 2023-11-02 00:37:21 +08:00
parent 47d57ddf70
commit 100967c57b

View File

@ -424,6 +424,9 @@ class InputService : AccessibilityService() {
node.refresh() node.refresh()
this.fakeEditTextForTextStateCalculation?.setSelection(0,0) this.fakeEditTextForTextStateCalculation?.setSelection(0,0)
this.fakeEditTextForTextStateCalculation?.setText(null) this.fakeEditTextForTextStateCalculation?.setText(null)
this.fakeEditTextForTextStateCalculation?.setFocusable(true)
this.fakeEditTextForTextStateCalculation?.setFocusableInTouchMode(true)
val text = node.getText() val text = node.getText()
var isShowingHint = false var isShowingHint = false
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= 26) {
@ -447,12 +450,14 @@ class InputService : AccessibilityService() {
var success = false var success = false
val focused = this.fakeEditTextForTextStateCalculation?.isFocused val previousFocusedState = this.fakeEditTextForTextStateCalculation?.isFocused
this.fakeEditTextForTextStateCalculation?.let { this.fakeEditTextForTextStateCalculation?.let {
it.requestFocus() it.requestFocus()
} }
Log.d(logTag, "existing text:$text textToCommit:$textToCommit textSelectionStart:$textSelectionStart textSelectionEnd:$textSelectionEnd $focused") val nowFocusedState = this.fakeEditTextForTextStateCalculation?.isFocused
Log.d(logTag, "existing text:$text textToCommit:$textToCommit textSelectionStart:$textSelectionStart textSelectionEnd:$textSelectionEnd previous focus: $previousFocusedState now focus: $nowFocusedState")
if (textToCommit != null) { if (textToCommit != null) {
var newText = "" var newText = ""