From 893b2a54a8eadab667e6c6925b2a29a6d491edde Mon Sep 17 00:00:00 2001 From: nopdan Date: Thu, 4 Jul 2024 17:24:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BE=93=E5=85=A5=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8B=E5=88=87=E6=8D=A2=E6=B7=B1=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=82=AC=E6=B5=AE=E7=AA=97=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ime/composition/CompositionPopupWindow.kt | 19 ++++++++------ .../trime/ime/core/TrimeInputMethodService.kt | 25 ++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) 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(