Skip to content

Commit f580213

Browse files
committed
refactor: create main keyboard view without binding
1 parent ef78335 commit f580213

File tree

5 files changed

+24
-45
lines changed

5 files changed

+24
-45
lines changed

app/src/main/java/com/osfans/trime/ime/core/InputView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ class InputView(
299299
}
300300
}
301301
}
302-
keyboardWindow.oldMainInputView.mainKeyboardView.updateEnterLabelOnEditorInfo(info)
303302
if (!restarting) {
304303
windowManager.attachWindow(KeyboardWindow)
305304
}
305+
keyboardWindow.mainKeyboardView.updateEnterLabelOnEditorInfo(info)
306306
}
307307

308308
private fun handleRimeNotification(it: RimeNotification<*>) {
@@ -333,7 +333,7 @@ class InputView(
333333
fun updateComposing(ic: InputConnection?) {
334334
val candidateView = quickBar.oldCandidateBar.candidates
335335
val compositionView = composition.composition.compositionView
336-
val mainKeyboardView = keyboardWindow.oldMainInputView.mainKeyboardView
336+
val mainKeyboardView = keyboardWindow.mainKeyboardView
337337
if (composition.isPopupWindowEnabled) {
338338
val offset = Rime.inputContext?.let { compositionView.update(it) } ?: 0
339339
candidateView.setText(offset)
@@ -379,7 +379,7 @@ class InputView(
379379

380380
fun finishInput() {
381381
showingDialog?.dismiss()
382-
keyboardWindow.oldMainInputView.mainKeyboardView.finishInput()
382+
keyboardWindow.mainKeyboardView.finishInput()
383383
}
384384

385385
override fun onDetachedFromWindow() {

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
320320
* 重置鍵盤、候選條、狀態欄等 !!注意,如果其中調用Rime.setOption,切換方案會卡住 */
321321
fun recreateInputView() {
322322
inputView = InputView(this, rime)
323-
mainKeyboardView = inputView!!.keyboardWindow.oldMainInputView.mainKeyboardView
323+
mainKeyboardView = inputView!!.keyboardWindow.mainKeyboardView
324324

325325
loadConfig()
326326
KeyboardSwitcher.newOrReset()

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ class KeyboardView
254254
private val mDistances = IntArray(MAX_NEARBY_KEYS)
255255

256256
// For multi-tap
257-
private var mLastSentIndex = 0
258-
private var mLastTapTime: Long = 0
257+
private var mLastSentIndex = -1
258+
private var mLastTapTime: Long = -1
259259

260260
/** Whether the keyboard bitmap needs to be redrawn before it's blitted. */
261261
private var mDrawPending = false
@@ -364,7 +364,6 @@ class KeyboardView
364364
}
365365

366366
init {
367-
resetMultiTap()
368367
initGestureDetector()
369368
handleEnterLabel()
370369
invalidateAllKeys()
@@ -1152,7 +1151,7 @@ class KeyboardView
11521151

11531152
private fun openPopupIfRequired(me: MotionEvent): Boolean {
11541153
// Check if we have a popup layout specified first.
1155-
if (mCurrentKey < 0 || mCurrentKey >= mKeys!!.size) {
1154+
if (mCurrentKey !in mKeys!!.indices) {
11561155
return false
11571156
}
11581157
showPreview(NOT_A_KEY)

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardWindow.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,54 @@
55
package com.osfans.trime.ime.keyboard
66

77
import android.content.Context
8-
import android.view.LayoutInflater
98
import android.view.View
9+
import android.widget.FrameLayout
1010
import com.osfans.trime.core.RimeNotification.OptionNotification
11-
import com.osfans.trime.databinding.MainInputLayoutBinding
1211
import com.osfans.trime.ime.broadcast.InputBroadcastReceiver
1312
import com.osfans.trime.ime.core.TrimeInputMethodService
1413
import com.osfans.trime.ime.dependency.InputScope
1514
import com.osfans.trime.ime.window.BoardWindow
1615
import com.osfans.trime.ime.window.ResidentWindow
1716
import me.tatarka.inject.annotations.Inject
17+
import splitties.views.dsl.core.add
18+
import splitties.views.dsl.core.frameLayout
19+
import splitties.views.dsl.core.lParams
20+
import splitties.views.dsl.core.matchParent
1821

1922
@InputScope
2023
@Inject
2124
class KeyboardWindow(
22-
context: Context,
25+
private val context: Context,
2326
private val service: TrimeInputMethodService,
2427
) : BoardWindow.NoBarBoardWindow(), ResidentWindow, InputBroadcastReceiver {
25-
val oldMainInputView by lazy {
26-
MainInputLayoutBinding.inflate(LayoutInflater.from(context))
27-
}
28+
val mainKeyboardView by lazy { KeyboardView(context) }
29+
30+
private lateinit var keyboardView: FrameLayout
2831

2932
companion object : ResidentWindow.Key
3033

3134
override val key: ResidentWindow.Key
3235
get() = KeyboardWindow
3336

3437
override fun onCreateView(): View {
35-
return oldMainInputView.root
38+
keyboardView = context.frameLayout()
39+
keyboardView.apply { add(mainKeyboardView, lParams(matchParent, matchParent)) }
40+
return keyboardView
3641
}
3742

3843
override fun onRimeOptionUpdated(value: OptionNotification.Value) {
3944
when (value.option) {
40-
"_hide_key_hint" -> oldMainInputView.mainKeyboardView.showKeyHint = !value.value
41-
"_hide_key_symbol" -> oldMainInputView.mainKeyboardView.showKeySymbol = !value.value
45+
"_hide_key_hint" -> mainKeyboardView.showKeyHint = !value.value
46+
"_hide_key_symbol" -> mainKeyboardView.showKeySymbol = !value.value
4247
}
43-
oldMainInputView.mainKeyboardView.invalidateAllKeys()
48+
mainKeyboardView.invalidateAllKeys()
4449
}
4550

4651
override fun onAttached() {
47-
oldMainInputView.mainKeyboardView.onKeyboardActionListener = service.textInputManager
52+
mainKeyboardView.onKeyboardActionListener = service.textInputManager
4853
}
4954

5055
override fun onDetached() {
51-
oldMainInputView.mainKeyboardView.onKeyboardActionListener = null
56+
mainKeyboardView.onKeyboardActionListener = null
5257
}
5358
}

app/src/main/res/layout/main_input_layout.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)