Skip to content

Commit a19488f

Browse files
committed
fix[TouchController]: fix keyboard doesn't show in some cases
1 parent 78460b8 commit a19488f

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

FCL/src/main/java/com/mio/touchcontroller/TouchControllerInputView.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.mio.touchcontroller
33
import android.content.ClipData
44
import android.content.ClipboardManager
55
import android.content.Context
6-
import android.os.Build
76
import android.os.Bundle
87
import android.text.InputType
98
import android.text.TextUtils
@@ -13,7 +12,6 @@ import android.view.View
1312
import android.view.inputmethod.CompletionInfo
1413
import android.view.inputmethod.CorrectionInfo
1514
import android.view.inputmethod.CursorAnchorInfo
16-
import android.view.inputmethod.EditorBoundsInfo
1715
import android.view.inputmethod.EditorInfo
1816
import android.view.inputmethod.ExtractedText
1917
import android.view.inputmethod.ExtractedTextRequest
@@ -47,10 +45,6 @@ class TouchControllerInputView @JvmOverloads constructor(
4745
attrs: AttributeSet? = null,
4846
defStyleAttr: Int = 0,
4947
) : View(context, attrs, defStyleAttr) {
50-
init {
51-
isFocusableInTouchMode = true
52-
}
53-
5448
var client: LauncherProxyClient? = null
5549
set(value) {
5650
val prev = field
@@ -85,12 +79,11 @@ class TouchControllerInputView @JvmOverloads constructor(
8579
if (textInputState != null) {
8680
visibility = VISIBLE
8781
focusable = FOCUSABLE
88-
} else {
89-
visibility = GONE
90-
focusable = NOT_FOCUSABLE
9182
}
9283
when {
9384
prevState == null && textInputState != null -> {
85+
isFocusableInTouchMode = true
86+
clearFocus()
9487
requestFocus()
9588
inputMethodManager.showSoftInput(
9689
this@TouchControllerInputView,
@@ -100,7 +93,6 @@ class TouchControllerInputView @JvmOverloads constructor(
10093

10194
prevState != null && textInputState == null -> {
10295
clearFocus()
103-
inputConnection = null
10496
inputMethodManager.hideSoftInputFromWindow(
10597
windowToken,
10698
InputMethodManager.HIDE_IMPLICIT_ONLY
@@ -109,6 +101,9 @@ class TouchControllerInputView @JvmOverloads constructor(
109101
}
110102
if (textInputState != null) {
111103
inputConnection?.updateState(textInputState)
104+
} else {
105+
visibility = GONE
106+
focusable = NOT_FOCUSABLE
112107
}
113108
}
114109
}
@@ -128,9 +123,9 @@ class TouchControllerInputView @JvmOverloads constructor(
128123
val client = client ?: return null
129124
val state = inputState ?: return null
130125
outAttrs.apply {
131-
EditorInfoCompat.setInitialSurroundingText(this, state.text)
132126
initialSelStart = state.selection.start
133127
initialSelEnd = state.selection.end
128+
EditorInfoCompat.setInitialSurroundingText(this, state.text)
134129
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_NORMAL
135130
}
136131
return InputConnectionImpl(state) {

0 commit comments

Comments
 (0)