Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb93885

Browse filesBrowse files
authored
Merge branch 'fcitx5-android:master' into master
2 parents 3341765 + a4d4eb8 commit cb93885
Copy full SHA for cb93885

File tree

Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed

‎app/src/main/java/org/fcitx/fcitx5/android/input/status/StatusAreaEntryUi.kt

Copy file name to clipboardExpand all lines: app/src/main/java/org/fcitx/fcitx5/android/input/status/StatusAreaEntryUi.kt
+16-5Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import android.content.Context
44
import android.graphics.Typeface
55
import android.graphics.drawable.ShapeDrawable
66
import android.graphics.drawable.shapes.OvalShape
7+
import android.icu.text.BreakIterator
78
import android.os.Build
89
import android.util.TypedValue
910
import android.view.View
1011
import android.view.ViewGroup
1112
import android.widget.ImageView
1213
import org.fcitx.fcitx5.android.data.theme.Theme
14+
import org.fcitx.fcitx5.android.input.AutoScaleTextView
1315
import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView
1416
import splitties.dimensions.dp
1517
import splitties.resources.drawable
@@ -27,6 +29,7 @@ import splitties.views.dsl.core.imageView
2729
import splitties.views.dsl.core.lParams
2830
import splitties.views.dsl.core.matchParent
2931
import splitties.views.dsl.core.textView
32+
import splitties.views.dsl.core.view
3033
import splitties.views.dsl.core.wrapContent
3134
import splitties.views.gravityCenter
3235
import splitties.views.imageDrawable
@@ -43,8 +46,7 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
4346
scaleType = ImageView.ScaleType.CENTER_INSIDE
4447
}
4548

46-
val textIcon = textView {
47-
gravity = gravityCenter
49+
val textIcon = view(::AutoScaleTextView) {
4850
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20f)
4951
// keep original typeface, apply textStyle only
5052
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -53,7 +55,6 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
5355
} else {
5456
setTypeface(typeface, Typeface.BOLD)
5557
}
56-
text
5758
}
5859

5960
val label = textView {
@@ -72,7 +73,7 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
7273
add(icon, lParams {
7374
centerOn(bkg)
7475
})
75-
add(textIcon, lParams {
76+
add(textIcon, lParams(wrapContent, wrapContent) {
7677
centerOn(bkg)
7778
})
7879
add(label, lParams(wrapContent, wrapContent) {
@@ -99,11 +100,21 @@ class StatusAreaEntryUi(override val ctx: Context, private val theme: Theme) : U
99100
} else {
100101
icon.visibility = View.GONE
101102
textIcon.visibility = View.VISIBLE
102-
textIcon.text = entry.label.substring(0, 1)
103+
textIcon.text = getFirstCharacter(entry.label)
103104
textIcon.setTextColor(contentColor)
104105
}
105106
bkgDrawable.paint.color =
106107
if (entry.active) theme.genericActiveBackgroundColor else theme.keyBackgroundColor
107108
label.text = entry.label
108109
}
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+
}
109120
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.