Skip to content

Commit db10498

Browse files
committed
refactor: tidy the stuffs of input method service
1 parent 318d65b commit db10498

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

app/src/main/java/com/osfans/trime/ime/lifecycle/LifecycleInputMethodService.kt renamed to app/src/main/java/com/osfans/trime/ime/core/LifecycleInputMethodService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.osfans.trime.ime.lifecycle
1+
package com.osfans.trime.ime.core
22

33
import android.inputmethodservice.InputMethodService
44
import androidx.annotation.CallSuper

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import com.osfans.trime.ime.keyboard.Key
5959
import com.osfans.trime.ime.keyboard.KeyboardSwitcher
6060
import com.osfans.trime.ime.keyboard.KeyboardView
6161
import com.osfans.trime.ime.keyboard.KeyboardWindow
62-
import com.osfans.trime.ime.lifecycle.LifecycleInputMethodService
6362
import com.osfans.trime.ime.symbol.TabManager
6463
import com.osfans.trime.ime.symbol.TabView
6564
import com.osfans.trime.ime.text.Candidate
@@ -472,7 +471,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
472471
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS,
473472
InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD,
474473
-> {
475-
Timber.i(
474+
Timber.d(
476475
"EditorInfo: private;" +
477476
" packageName=" +
478477
attribute.packageName +
@@ -493,7 +492,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
493492
}
494493

495494
else -> {
496-
Timber.i(
495+
Timber.d(
497496
"EditorInfo: normal;" +
498497
" packageName=" +
499498
attribute.packageName +
@@ -639,15 +638,15 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
639638
keyCode: Int,
640639
event: KeyEvent,
641640
): Boolean {
642-
Timber.i("\t<TrimeInput>\tonKeyDown()\tkeycode=%d, event=%s", keyCode, event.toString())
641+
Timber.d("\t<TrimeInput>\tonKeyDown()\tkeycode=%d, event=%s", keyCode, event.toString())
643642
return if (composeEvent(event) && onKeyEvent(event) && isWindowShown) true else super.onKeyDown(keyCode, event)
644643
}
645644

646645
override fun onKeyUp(
647646
keyCode: Int,
648647
event: KeyEvent,
649648
): Boolean {
650-
Timber.i("\t<TrimeInput>\tonKeyUp()\tkeycode=%d, event=%s", keyCode, event.toString())
649+
Timber.d("\t<TrimeInput>\tonKeyUp()\tkeycode=%d, event=%s", keyCode, event.toString())
651650
if (composeEvent(event) && textInputManager!!.needSendUpRimeKey) {
652651
textInputManager!!.onRelease(keyCode)
653652
if (isWindowShown) return true
@@ -662,7 +661,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
662661
* @return 是否成功處理
663662
*/
664663
private fun onKeyEvent(event: KeyEvent): Boolean {
665-
Timber.i("\t<TrimeInput>\tonKeyEvent()\tRealKeyboard event=%s", event.toString())
664+
Timber.d("\t<TrimeInput>\tonKeyEvent()\tRealKeyboard event=%s", event.toString())
666665
var keyCode = event.keyCode
667666
textInputManager!!.needSendUpRimeKey = Rime.isComposing
668667
if (!this.isComposing) {
@@ -698,11 +697,8 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
698697
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
699698
switchToPreviousInputMethod()
700699
} else {
701-
val window = window.window
702-
if (window != null) {
703-
inputMethodManager
704-
.switchToLastInputMethod(window.attributes.token)
705-
}
700+
@Suppress("DEPRECATION")
701+
inputMethodManager.switchToLastInputMethod(window.window!!.attributes.token)
706702
}
707703
} catch (e: Exception) {
708704
Timber.e(e, "Unable to switch to the previous IME.")
@@ -715,11 +711,8 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
715711
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
716712
switchToNextInputMethod(false)
717713
} else {
718-
val window = window.window
719-
if (window != null) {
720-
inputMethodManager
721-
.switchToNextInputMethod(window.attributes.token, false)
722-
}
714+
@Suppress("DEPRECATION")
715+
inputMethodManager.switchToNextInputMethod(window.window!!.attributes.token, false)
723716
}
724717
} catch (e: Exception) {
725718
Timber.e(e, "Unable to switch to the next IME.")
@@ -808,7 +801,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
808801
if (et.selectionEnd - et.selectionStart > 0) return ic.performContextMenuAction(android.R.id.cut)
809802
}
810803
}
811-
Timber.i("hookKeyboard cut fail")
804+
Timber.w("hookKeyboard cut fail")
812805
return false
813806
}
814807

@@ -822,7 +815,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
822815
if (et.selectionEnd - et.selectionStart > 0) return ic.performContextMenuAction(android.R.id.copy)
823816
}
824817
}
825-
Timber.i("hookKeyboard copy fail")
818+
Timber.w("hookKeyboard copy fail")
826819
return false
827820
}
828821

@@ -996,22 +989,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
996989
interface EventListener {
997990
fun onCreate() {}
998991

999-
fun onInitializeInputUi(inputView: InputView) {}
1000-
1001992
fun onDestroy() {}
1002993

1003994
fun onStartInputView(
1004995
instance: EditorInstance,
1005996
restarting: Boolean,
1006997
) {}
1007998

1008-
fun osFinishInputView(finishingInput: Boolean) {}
1009-
1010999
fun onWindowShown() {}
10111000

10121001
fun onWindowHidden() {}
1013-
1014-
fun onUpdateSelection() {}
10151002
}
10161003

10171004
companion object {

0 commit comments

Comments
 (0)