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 40c7555497..d2a5ef856f 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 @@ -292,27 +292,25 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } private fun showCompositionView() { - if (Rime.compositionText.isEmpty()) { + if (Rime.isComposing) { + mCompositionPopupWindow?.updateCompositionView() + } else { mCompositionPopupWindow?.hideCompositionView() - return } - mCompositionPopupWindow?.updateCompositionView() } /** Must be called on the UI thread * * 重置鍵盤、候選條、狀態欄等 !!注意,如果其中調用Rime.setOption,切換方案會卡住 */ fun recreateInputView() { - mCompositionPopupWindow?.finishInput() + mCompositionPopupWindow?.hideCompositionView() inputView = InputView(this, rime) mainKeyboardView = inputView!!.keyboardWindow.oldMainInputView.mainKeyboardView // 初始化候选栏 mCandidate = inputView!!.quickBar.oldCandidateBar.candidates mCompositionPopupWindow = - CompositionPopupWindow(this, ThemeManager.activeTheme).apply { - anchorView = inputView?.quickBar?.view - }.apply { hideCompositionView() } + CompositionPopupWindow(this, ThemeManager.activeTheme, inputView!!.quickBar.view) loadConfig() KeyboardSwitcher.newOrReset() @@ -328,11 +326,11 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { mIntentReceiver = null InputFeedbackManager.destroy() inputView = null + mCompositionPopupWindow = null for (listener in eventListeners) { listener.onDestroy() } eventListeners.clear() - mCompositionPopupWindow?.finishInput() ColorManager.removeOnChangedListener(onColorChangeListener) super.onDestroy() RimeDaemon.destroySession(javaClass.name) @@ -546,21 +544,20 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { } override fun onFinishInputView(finishingInput: Boolean) { - super.onFinishInputView(finishingInput) + Timber.d("onFinishInputView: finishingInput=$finishingInput") rime.runIfReady { if (normalTextEditor) { DraftHelper.onInputEventChanged() } try { performEscape() - mCompositionPopupWindow!!.hideCompositionView() } catch (e: Exception) { Timber.e(e, "Failed to show the PopupWindow.") } } InputFeedbackManager.finishInput() inputView?.finishInput() - Timber.d("OnFinishInputView") + mCompositionPopupWindow?.hideCompositionView() } fun bindKeyboardToInputView() { diff --git a/app/src/main/java/com/osfans/trime/ime/text/CompositionPopupWindow.kt b/app/src/main/java/com/osfans/trime/ime/text/CompositionPopupWindow.kt index 4eecd0b395..d35586ae2f 100644 --- a/app/src/main/java/com/osfans/trime/ime/text/CompositionPopupWindow.kt +++ b/app/src/main/java/com/osfans/trime/ime/text/CompositionPopupWindow.kt @@ -31,11 +31,12 @@ import timber.log.Timber class CompositionPopupWindow( private val ctx: Context, private val theme: Theme, + private val anchorView: View, ) { // 顯示懸浮窗口 val isPopupWindowEnabled = AppPrefs.defaultInstance().keyboard.popupWindowEnabled && - theme.generalStyle.window != null + theme.generalStyle.window.isNotEmpty() val composition = CompositionRootBinding.inflate(LayoutInflater.from(ctx)).apply { @@ -82,14 +83,11 @@ class CompositionPopupWindow( private val mPopupRectF = RectF() private val mPopupHandler = Handler(Looper.getMainLooper()) - var anchorView: View? = null private val mPopupTimer = Runnable { - if (!isPopupWindowEnabled) return@Runnable - anchorView?.let { anchor -> - if (anchor.windowToken == null) return@Runnable - + if (!isPopupWindowEnabled || anchorView.windowToken == null) return@Runnable + anchorView.let { anchor -> var x = 0 var y = 0 val candidateLocation = IntArray(2) @@ -146,7 +144,7 @@ class CompositionPopupWindow( } y -= BarUtils.getStatusBarHeight() if (!mPopupWindow.isShowing) { - mPopupWindow.showAtLocation(anchorView, Gravity.START or Gravity.TOP, x, y) + mPopupWindow.showAtLocation(anchor, Gravity.START or Gravity.TOP, x, y) } else { /* must use the width and height of popup window itself here directly, * otherwise the width and height cannot be updated! */ @@ -221,9 +219,4 @@ class CompositionPopupWindow( cursorAnchorInfo.matrix.mapRect(mPopupRectF) } } - - fun finishInput() { - hideCompositionView() - anchorView = null - } }