@@ -4,12 +4,14 @@ import android.content.Context
4
4
import android.graphics.Typeface
5
5
import android.graphics.drawable.ShapeDrawable
6
6
import android.graphics.drawable.shapes.OvalShape
7
+ import android.icu.text.BreakIterator
7
8
import android.os.Build
8
9
import android.util.TypedValue
9
10
import android.view.View
10
11
import android.view.ViewGroup
11
12
import android.widget.ImageView
12
13
import org.fcitx.fcitx5.android.data.theme.Theme
14
+ import org.fcitx.fcitx5.android.input.AutoScaleTextView
13
15
import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView
14
16
import splitties.dimensions.dp
15
17
import splitties.resources.drawable
@@ -27,6 +29,7 @@ import splitties.views.dsl.core.imageView
27
29
import splitties.views.dsl.core.lParams
28
30
import splitties.views.dsl.core.matchParent
29
31
import splitties.views.dsl.core.textView
32
+ import splitties.views.dsl.core.view
30
33
import splitties.views.dsl.core.wrapContent
31
34
import splitties.views.gravityCenter
32
35
import splitties.views.imageDrawable
@@ -43,8 +46,7 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
43
46
scaleType = ImageView .ScaleType .CENTER_INSIDE
44
47
}
45
48
46
- val textIcon = textView {
47
- gravity = gravityCenter
49
+ val textIcon = view(::AutoScaleTextView ) {
48
50
setTextSize(TypedValue .COMPLEX_UNIT_DIP , 20f )
49
51
// keep original typeface, apply textStyle only
50
52
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
@@ -53,7 +55,6 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
53
55
} else {
54
56
setTypeface(typeface, Typeface .BOLD )
55
57
}
56
- text
57
58
}
58
59
59
60
val label = textView {
@@ -72,7 +73,7 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
72
73
add(icon, lParams {
73
74
centerOn(bkg)
74
75
})
75
- add(textIcon, lParams {
76
+ add(textIcon, lParams(wrapContent, wrapContent) {
76
77
centerOn(bkg)
77
78
})
78
79
add(label, lParams(wrapContent, wrapContent) {
@@ -99,11 +100,21 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
99
100
} else {
100
101
icon.visibility = View .GONE
101
102
textIcon.visibility = View .VISIBLE
102
- textIcon.text = entry.label.substring( 0 , 1 )
103
+ textIcon.text = getFirstCharacter( entry.label)
103
104
textIcon.setTextColor(contentColor)
104
105
}
105
106
bkgDrawable.paint.color =
106
107
if (entry.active) theme.genericActiveBackgroundColor else theme.keyBackgroundColor
107
108
label.text = entry.label
108
109
}
110
+
111
+ private fun getFirstCharacter (s : String ): String {
112
+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
113
+ val iterator = BreakIterator .getCharacterInstance()
114
+ iterator.setText(s)
115
+ s.substring(iterator.first(), iterator.next())
116
+ } else {
117
+ s.substring(0 , s.offsetByCodePoints(0 , 1 ))
118
+ }
119
+ }
109
120
}
0 commit comments