diff --git a/app/src/main/java/com/osfans/trime/ime/composition/PreeditModule.kt b/app/src/main/java/com/osfans/trime/ime/composition/PreeditModule.kt index 3155f5f4cf..6d09e14aa8 100644 --- a/app/src/main/java/com/osfans/trime/ime/composition/PreeditModule.kt +++ b/app/src/main/java/com/osfans/trime/ime/composition/PreeditModule.kt @@ -69,8 +69,8 @@ class PreeditModule( override fun onInputContextUpdate(ctx: RimeProto.Context) { ui.update(ctx.composition) if (ctx.composition.length > 0) { - window.showAtLocation(bar.view, Gravity.START or Gravity.TOP, 0, 0) val (x, y) = intArrayOf(0, 0).also { bar.view.getLocationInWindow(it) } + window.showAtLocation(bar.view, Gravity.START or Gravity.TOP, x, y) ui.root.post { window.update(x, y - ui.root.height, -1, -1) } diff --git a/app/src/main/java/com/osfans/trime/ime/composition/PreeditUi.kt b/app/src/main/java/com/osfans/trime/ime/composition/PreeditUi.kt index ff4812a2bb..7cf2983c28 100644 --- a/app/src/main/java/com/osfans/trime/ime/composition/PreeditUi.kt +++ b/app/src/main/java/com/osfans/trime/ime/composition/PreeditUi.kt @@ -10,6 +10,7 @@ import android.text.Spanned import android.text.style.BackgroundColorSpan import android.text.style.ForegroundColorSpan import android.view.MotionEvent +import android.view.View import android.widget.LinearLayout import android.widget.TextView import androidx.core.text.buildSpannedString @@ -62,6 +63,18 @@ open class PreeditUi( } } + private fun updateTextView( + str: CharSequence, + visible: Boolean, + ) = preedit.run { + if (visible) { + text = str + if (visibility == View.GONE) visibility = View.VISIBLE + } else if (visibility != View.GONE) { + visibility = View.GONE + } + } + fun update(inputComposition: RimeProto.Context.Composition) { val string = inputComposition.toSpannedString() val cursorPos = inputComposition.cursorPos @@ -75,6 +88,6 @@ open class PreeditUi( append(string, cursorPos, string.length) } } - if (hasPreedit) preedit.text = stringWithCursor + updateTextView(stringWithCursor, hasPreedit) } }