diff --git a/app/src/main/java/com/osfans/trime/ime/composition/CompositionPopupWindow.kt b/app/src/main/java/com/osfans/trime/ime/composition/CompositionPopupWindow.kt index bf36f6b6da..ab95e732c2 100644 --- a/app/src/main/java/com/osfans/trime/ime/composition/CompositionPopupWindow.kt +++ b/app/src/main/java/com/osfans/trime/ime/composition/CompositionPopupWindow.kt @@ -85,7 +85,11 @@ class CompositionPopupWindow( theme.generalStyle.layout.alpha, ), ) - elevation = ctx.dp(theme.generalStyle.layout.elevation.toFloat()) + elevation = + ctx.dp( + theme.generalStyle.layout.elevation + .toFloat(), + ) } var isCursorUpdated = false // 光標是否移動 @@ -170,11 +174,12 @@ class CompositionPopupWindow( } } - fun isWinFixed(): Boolean { - return Build.VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP || - popupWindowPos !== PopupPosition.LEFT && popupWindowPos !== PopupPosition.RIGHT && - popupWindowPos !== PopupPosition.LEFT_UP && popupWindowPos !== PopupPosition.RIGHT_UP - } + fun isWinFixed(): Boolean = + Build.VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP || + popupWindowPos !== PopupPosition.LEFT && + popupWindowPos !== PopupPosition.RIGHT && + popupWindowPos !== PopupPosition.LEFT_UP && + popupWindowPos !== PopupPosition.RIGHT_UP private fun updatePopupWindow( offsetX: Int, @@ -195,7 +200,7 @@ class CompositionPopupWindow( } } - private fun hideCompositionView() { + fun hideCompositionView() { mPopupWindow.dismiss() mPopupHandler.removeCallbacks(mPopupTimer) } diff --git a/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt b/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt index 0460d460e7..43d6030cfd 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt +++ b/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt @@ -319,6 +319,8 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { * * 重置鍵盤、候選條、狀態欄等 !!注意,如果其中調用Rime.setOption,切換方案會卡住 */ fun recreateInputView() { + // 创建 inputView 之前隐藏上一个 inputView 的 compositionView + inputView?.composition?.hideCompositionView() inputView = InputView(this, rime) mainKeyboardView = inputView!!.keyboardWindow.oldMainInputView.mainKeyboardView @@ -429,6 +431,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } override fun onCreateInputView(): View { + Timber.d("onCreateInputView") postRimeJob(Dispatchers.Main) { recreateInputView() } @@ -438,7 +441,8 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { override fun setInputView(view: View) { val inputArea = - window.window!!.decorView + window.window!! + .decorView .findViewById(android.R.id.inputArea) inputArea.updateLayoutParams { height = ViewGroup.LayoutParams.MATCH_PARENT @@ -541,7 +545,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } else if (attribute.packageName == BuildConfig.APPLICATION_ID || prefs .clipboard - .draftExcludeApp.trim().split('\n') + .draftExcludeApp + .trim() + .split('\n') .contains(attribute.packageName) ) { normalTextEditor = false @@ -1170,13 +1176,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } } - fun addEventListener(listener: EventListener): Boolean { - return eventListeners.add(listener) - } + fun addEventListener(listener: EventListener): Boolean = eventListeners.add(listener) - fun removeEventListener(listener: EventListener): Boolean { - return eventListeners.remove(listener) - } + fun removeEventListener(listener: EventListener): Boolean = eventListeners.remove(listener) interface EventListener { fun onCreate() {} @@ -1197,13 +1199,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { var self: TrimeInputMethodService? = null @JvmStatic - fun getService(): TrimeInputMethodService { - return self ?: throw IllegalStateException("Trime not initialized") - } + fun getService(): TrimeInputMethodService = self ?: throw IllegalStateException("Trime not initialized") - fun getServiceOrNull(): TrimeInputMethodService? { - return self - } + fun getServiceOrNull(): TrimeInputMethodService? = self private val syncBackgroundHandler = Handler(