|
5 | 5 | package com.osfans.trime.ime.popup |
6 | 6 |
|
7 | 7 | import android.content.Context |
| 8 | +import android.graphics.PorterDuff |
| 9 | +import android.graphics.PorterDuffColorFilter |
8 | 10 | import android.graphics.Rect |
9 | 11 | import android.graphics.drawable.GradientDrawable |
10 | 12 | import android.view.ViewOutlineProvider |
| 13 | +import androidx.appcompat.widget.AppCompatImageView |
| 14 | +import androidx.core.view.isVisible |
| 15 | +import com.mikepenz.iconics.IconicsDrawable |
| 16 | +import com.mikepenz.iconics.utils.sizeDp |
11 | 17 | import com.osfans.trime.data.theme.ColorManager |
12 | 18 | import com.osfans.trime.data.theme.FontManager |
13 | 19 | import com.osfans.trime.data.theme.KeyActionManager |
14 | 20 | import com.osfans.trime.data.theme.Theme |
15 | 21 | import com.osfans.trime.ime.core.AutoScaleTextView |
16 | 22 | import com.osfans.trime.ime.keyboard.KeyboardSwitcher |
| 23 | +import com.osfans.trime.ime.keyboard.isIconFont |
| 24 | +import com.osfans.trime.ime.keyboard.toIconName |
17 | 25 | import splitties.dimensions.dp |
18 | 26 | import splitties.views.dsl.core.Ui |
19 | 27 | import splitties.views.dsl.core.add |
@@ -62,20 +70,44 @@ class PopupKeyboardUi( |
62 | 70 | class PopupKeyUi(override val ctx: Context, val theme: Theme, val text: String) : Ui { |
63 | 71 |
|
64 | 72 | val textView = view(::AutoScaleTextView) { |
65 | | - text = this@PopupKeyUi.text |
66 | 73 | scaleMode = AutoScaleTextView.Mode.Proportional |
67 | 74 | textSize = theme.generalStyle.popupTextSize |
68 | 75 | setTextColor(ColorManager.getColor("popup_text_color")) |
69 | 76 | typeface = FontManager.getTypeface("POPUP_FONT") |
70 | 77 | } |
71 | 78 |
|
| 79 | + val imageView = view(::AppCompatImageView) {} |
| 80 | + |
72 | 81 | override val root = frameLayout { |
73 | 82 | add( |
74 | 83 | textView, |
75 | 84 | lParams { |
76 | 85 | gravity = gravityCenter |
77 | 86 | }, |
78 | 87 | ) |
| 88 | + add( |
| 89 | + imageView, |
| 90 | + lParams { |
| 91 | + gravity = gravityCenter |
| 92 | + }, |
| 93 | + ) |
| 94 | + } |
| 95 | + |
| 96 | + init { |
| 97 | + if (text.isIconFont) { |
| 98 | + imageView.setImageDrawable( |
| 99 | + IconicsDrawable(ctx, text.toIconName()).apply { |
| 100 | + sizeDp = theme.generalStyle.popupTextSize.toInt() |
| 101 | + colorFilter = PorterDuffColorFilter(ColorManager.getColor("popup_text_color"), PorterDuff.Mode.SRC_IN) |
| 102 | + }, |
| 103 | + ) |
| 104 | + imageView.isVisible = true |
| 105 | + textView.isVisible = false |
| 106 | + } else { |
| 107 | + textView.text = text |
| 108 | + textView.isVisible = true |
| 109 | + imageView.isVisible = false |
| 110 | + } |
79 | 111 | } |
80 | 112 | } |
81 | 113 |
|
@@ -163,10 +195,13 @@ class PopupKeyboardUi( |
163 | 195 | if (label.length == 1 && label[0].code < 128) { |
164 | 196 | label |
165 | 197 | } else { |
166 | | - KeyActionManager |
167 | | - .getAction(label) |
168 | | - .getLabel(KeyboardSwitcher.currentKeyboard) |
169 | | - .let { if (it.isNotEmpty()) String(Character.toChars(it.codePointAt(0))) else "" } |
| 198 | + KeyActionManager.getAction(label).getLabel(KeyboardSwitcher.currentKeyboard).let { |
| 199 | + when { |
| 200 | + it.isIconFont -> it |
| 201 | + it.isNotEmpty() -> String(Character.toChars(it.codePointAt(0))) |
| 202 | + else -> "" |
| 203 | + } |
| 204 | + } |
170 | 205 | } |
171 | 206 |
|
172 | 207 | PopupKeyUi(ctx, theme, displayLabel) |
@@ -205,14 +240,18 @@ class PopupKeyboardUi( |
205 | 240 | private fun markFocus(index: Int) { |
206 | 241 | keyUis.getOrNull(index)?.apply { |
207 | 242 | root.background = focusBackground |
208 | | - textView.setTextColor(ColorManager.getColor("hilited_popup_text_color")) |
| 243 | + val color = ColorManager.getColor("hilited_popup_text_color") |
| 244 | + textView.setTextColor(color) |
| 245 | + imageView.drawable?.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN) |
209 | 246 | } |
210 | 247 | } |
211 | 248 |
|
212 | 249 | private fun markInactive(index: Int) { |
213 | 250 | keyUis.getOrNull(index)?.apply { |
214 | 251 | root.background = null |
215 | | - textView.setTextColor(ColorManager.getColor("popup_text_color")) |
| 252 | + val color = ColorManager.getColor("popup_text_color") |
| 253 | + textView.setTextColor(color) |
| 254 | + imageView.drawable?.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN) |
216 | 255 | } |
217 | 256 | } |
218 | 257 |
|
|
0 commit comments