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..d4f997910c 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 @@ -372,6 +372,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) postRimeJob { clearComposition() } + inputView?.composition?.hideCompositionView() ColorManager.onSystemNightModeChange(newConfig.isNightMode()) } @@ -429,6 +430,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } override fun onCreateInputView(): View { + Timber.d("onCreateInputView") postRimeJob(Dispatchers.Main) { recreateInputView() } @@ -438,7 +440,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 +544,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 +1175,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 +1198,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(