Skip to content

Commit

Permalink
refactor: create main keyboard view without binding
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Jul 23, 2024
1 parent ef78335 commit f580213
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 45 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ class InputView(
}
}
}
keyboardWindow.oldMainInputView.mainKeyboardView.updateEnterLabelOnEditorInfo(info)
if (!restarting) {
windowManager.attachWindow(KeyboardWindow)
}
keyboardWindow.mainKeyboardView.updateEnterLabelOnEditorInfo(info)
}

private fun handleRimeNotification(it: RimeNotification<*>) {
Expand Down Expand Up @@ -333,7 +333,7 @@ class InputView(
fun updateComposing(ic: InputConnection?) {
val candidateView = quickBar.oldCandidateBar.candidates
val compositionView = composition.composition.compositionView
val mainKeyboardView = keyboardWindow.oldMainInputView.mainKeyboardView
val mainKeyboardView = keyboardWindow.mainKeyboardView
if (composition.isPopupWindowEnabled) {
val offset = Rime.inputContext?.let { compositionView.update(it) } ?: 0
candidateView.setText(offset)
Expand Down Expand Up @@ -379,7 +379,7 @@ class InputView(

fun finishInput() {
showingDialog?.dismiss()
keyboardWindow.oldMainInputView.mainKeyboardView.finishInput()
keyboardWindow.mainKeyboardView.finishInput()
}

override fun onDetachedFromWindow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
* 重置鍵盤、候選條、狀態欄等 !!注意,如果其中調用Rime.setOption,切換方案會卡住 */
fun recreateInputView() {
inputView = InputView(this, rime)
mainKeyboardView = inputView!!.keyboardWindow.oldMainInputView.mainKeyboardView
mainKeyboardView = inputView!!.keyboardWindow.mainKeyboardView

loadConfig()
KeyboardSwitcher.newOrReset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class KeyboardView
private val mDistances = IntArray(MAX_NEARBY_KEYS)

// For multi-tap
private var mLastSentIndex = 0
private var mLastTapTime: Long = 0
private var mLastSentIndex = -1
private var mLastTapTime: Long = -1

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

init {
resetMultiTap()
initGestureDetector()
handleEnterLabel()
invalidateAllKeys()
Expand Down Expand Up @@ -1152,7 +1151,7 @@ class KeyboardView

private fun openPopupIfRequired(me: MotionEvent): Boolean {
// Check if we have a popup layout specified first.
if (mCurrentKey < 0 || mCurrentKey >= mKeys!!.size) {
if (mCurrentKey !in mKeys!!.indices) {
return false
}
showPreview(NOT_A_KEY)
Expand Down
29 changes: 17 additions & 12 deletions app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,54 @@
package com.osfans.trime.ime.keyboard

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import com.osfans.trime.core.RimeNotification.OptionNotification
import com.osfans.trime.databinding.MainInputLayoutBinding
import com.osfans.trime.ime.broadcast.InputBroadcastReceiver
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.dependency.InputScope
import com.osfans.trime.ime.window.BoardWindow
import com.osfans.trime.ime.window.ResidentWindow
import me.tatarka.inject.annotations.Inject
import splitties.views.dsl.core.add
import splitties.views.dsl.core.frameLayout
import splitties.views.dsl.core.lParams
import splitties.views.dsl.core.matchParent

@InputScope
@Inject
class KeyboardWindow(
context: Context,
private val context: Context,
private val service: TrimeInputMethodService,
) : BoardWindow.NoBarBoardWindow(), ResidentWindow, InputBroadcastReceiver {
val oldMainInputView by lazy {
MainInputLayoutBinding.inflate(LayoutInflater.from(context))
}
val mainKeyboardView by lazy { KeyboardView(context) }

private lateinit var keyboardView: FrameLayout

companion object : ResidentWindow.Key

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

override fun onCreateView(): View {
return oldMainInputView.root
keyboardView = context.frameLayout()
keyboardView.apply { add(mainKeyboardView, lParams(matchParent, matchParent)) }
return keyboardView
}

override fun onRimeOptionUpdated(value: OptionNotification.Value) {
when (value.option) {
"_hide_key_hint" -> oldMainInputView.mainKeyboardView.showKeyHint = !value.value
"_hide_key_symbol" -> oldMainInputView.mainKeyboardView.showKeySymbol = !value.value
"_hide_key_hint" -> mainKeyboardView.showKeyHint = !value.value
"_hide_key_symbol" -> mainKeyboardView.showKeySymbol = !value.value
}
oldMainInputView.mainKeyboardView.invalidateAllKeys()
mainKeyboardView.invalidateAllKeys()
}

override fun onAttached() {
oldMainInputView.mainKeyboardView.onKeyboardActionListener = service.textInputManager
mainKeyboardView.onKeyboardActionListener = service.textInputManager
}

override fun onDetached() {
oldMainInputView.mainKeyboardView.onKeyboardActionListener = null
mainKeyboardView.onKeyboardActionListener = null
}
}
25 changes: 0 additions & 25 deletions app/src/main/res/layout/main_input_layout.xml

This file was deleted.

0 comments on commit f580213

Please sign in to comment.