Skip to content

Commit

Permalink
feat: improve candidate window display
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Dec 29, 2024
1 parent adbf06c commit aeb960d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import splitties.dimensions.dp
import splitties.views.backgroundColor
import splitties.views.dsl.core.Ui
import splitties.views.dsl.core.textView
import splitties.views.horizontalPadding
import splitties.views.padding

class LabeledCandidateItemUi(
override val ctx: Context,
Expand Down Expand Up @@ -57,7 +57,7 @@ class LabeledCandidateItemUi(

override val root =
textView {
horizontalPadding = dp(theme.generalStyle.candidatePadding)
padding = dp(theme.generalStyle.candidatePadding)
}

fun update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PagedCandidatesUi(
is UiHolder.Pagination -> {
holder.ui.update(menu)
holder.ui.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
width = if (isHorizontal) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT
alignSelf = if (isHorizontal) AlignItems.CENTER else AlignItems.STRETCH
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
package com.osfans.trime.ime.composition

import android.annotation.SuppressLint
import android.content.Context
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import com.osfans.trime.R
import com.osfans.trime.core.RimeProto
import com.osfans.trime.daemon.RimeSession
import com.osfans.trime.daemon.launchOnReady
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.ime.candidates.popup.PagedCandidatesUi
import com.osfans.trime.ime.core.TrimeInputMethodService
import splitties.dimensions.dp
import splitties.views.dsl.constraintlayout.below
import splitties.views.dsl.constraintlayout.bottomOfParent
import splitties.views.dsl.constraintlayout.centerHorizontally
import splitties.views.dsl.constraintlayout.lParams
import splitties.views.dsl.constraintlayout.matchConstraints
import splitties.views.dsl.constraintlayout.startOfParent
import splitties.views.dsl.constraintlayout.topOfParent
import splitties.views.dsl.core.add
Expand Down Expand Up @@ -74,8 +75,17 @@ class CandidatesView(
}

init {
minWidth = dp(theme.generalStyle.layout.minWidth)
verticalPadding = dp(theme.generalStyle.layout.marginX)
horizontalPadding = dp(theme.generalStyle.layout.marginY)
background =
ColorManager.getDrawable(
ctx,
"candidate_background",
theme.generalStyle.candidateBorder,
"candidate_border_color",
theme.generalStyle.candidateBorderRound,
)
add(
preeditUi.root,
lParams(wrapContent, wrapContent) {
Expand All @@ -85,9 +95,10 @@ class CandidatesView(
)
add(
candidatesUi.root,
lParams(wrapContent, wrapContent) {
lParams(matchConstraints, wrapContent) {
matchConstraintMinWidth = wrapContent
below(preeditUi.root)
startOfParent()
centerHorizontally()
bottomOfParent()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.osfans.trime.ime.composition

import android.graphics.RectF
import android.os.Build
import android.view.Gravity
import android.view.View
import android.view.View.MeasureSpec
Expand All @@ -16,10 +15,10 @@ import androidx.core.graphics.component1
import androidx.core.graphics.component2
import androidx.core.graphics.component3
import androidx.core.graphics.component4
import androidx.core.widget.PopupWindowCompat
import com.osfans.trime.core.RimeMessage
import com.osfans.trime.daemon.RimeSession
import com.osfans.trime.data.prefs.AppPrefs
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.ime.core.BaseMessageHandler
import com.osfans.trime.ime.core.TrimeInputMethodService
Expand All @@ -42,21 +41,10 @@ class ComposingPopupWindow(
private val window =
PopupWindow(root).apply {
isClippingEnabled = false
inputMethodMode = PopupWindow.INPUT_METHOD_NOT_NEEDED
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
windowLayoutType =
WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG
}
setBackgroundDrawable(
ColorManager.getDrawable(
service,
"text_back_color",
theme.generalStyle.layout.border,
"border_color",
theme.generalStyle.layout.roundCorner,
theme.generalStyle.layout.alpha
.toInt(),
),
inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
PopupWindowCompat.setWindowLayoutType(
this,
WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG,
)
width = WindowManager.LayoutParams.WRAP_CONTENT
height = WindowManager.LayoutParams.WRAP_CONTENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
attribute: EditorInfo,
restarting: Boolean,
) {
Timber.d("onStartInputView: restarting=%s", restarting)
Timber.d("onStartInputView: restarting=$restarting")
if (!restarting) {
currentInputConnection?.monitorCursorAnchor()
}
postRimeJob {
updateRimeOption(this)
InputFeedbackManager.loadSoundEffects(this@TrimeInputMethodService)
Expand All @@ -440,10 +443,6 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
ContextCompat.getMainExecutor(this@TrimeInputMethodService).execute {
if (inputDeviceManager.evaluateOnStartInputView(attribute, this@TrimeInputMethodService)) {
inputView?.startInput(attribute, restarting)
} else {
if (!restarting) {
currentInputConnection?.monitorCursorAnchor()
}
}
}
when (attribute.inputType and InputType.TYPE_MASK_VARIATION) {
Expand Down

0 comments on commit aeb960d

Please sign in to comment.