Skip to content

Commit c25a6f1

Browse files
committed
fix: views cannot use nine patch drawable as their background
1 parent f5230f0 commit c25a6f1

File tree

7 files changed

+9
-13
lines changed

7 files changed

+9
-13
lines changed

app/src/main/java/com/osfans/trime/data/theme/ColorManager.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import android.graphics.BitmapFactory
1111
import android.graphics.Color
1212
import android.graphics.NinePatch
1313
import android.graphics.Rect
14-
import android.graphics.drawable.BitmapDrawable
1514
import android.graphics.drawable.Drawable
1615
import android.graphics.drawable.GradientDrawable
1716
import android.graphics.drawable.NinePatchDrawable
@@ -26,7 +25,6 @@ import com.osfans.trime.util.NinePatchBitmapFactory
2625
import com.osfans.trime.util.WeakHashSet
2726
import com.osfans.trime.util.isNightMode
2827
import timber.log.Timber
29-
import java.io.File
3028

3129
object ColorManager {
3230
private lateinit var theme: Theme
@@ -219,7 +217,7 @@ object ColorManager {
219217
val path = resolveImageFilePath(value)
220218
val bitmap =
221219
bitmapCache?.get(path)
222-
?: BitmapFactory.decodeStream(File(path).inputStream())?.also {
220+
?: BitmapFactory.decodeFile(path)?.also {
223221
bitmapCache?.put(path, it)
224222
} ?: return null
225223
if (path.endsWith(".9.png")) {
@@ -258,14 +256,13 @@ object ColorManager {
258256

259257
fun getDrawable(key: String): Drawable? = resolveDrawable(key)
260258

261-
fun getDrawable(
259+
fun getDecorDrawable(
262260
colorKey: String,
263261
borderColorKey: String? = null,
264262
borderPx: Int = 0,
265263
cornerRadius: Float = 0f,
266264
alpha: Int = 255,
267265
): Drawable? = when (val drawable = getDrawable(colorKey)) {
268-
is BitmapDrawable -> drawable.also { it.alpha = MathUtils.clamp(alpha, 0, 255) }
269266
is GradientDrawable ->
270267
drawable.also {
271268
it.cornerRadius = cornerRadius
@@ -278,7 +275,7 @@ object ColorManager {
278275
}
279276
}
280277
}
281-
else -> null
278+
else -> drawable?.also { it.alpha = MathUtils.clamp(alpha, 0, 255) }
282279
}
283280

284281
private val SUPPORTED_IMG_FORMATS = arrayOf(".png", ".webp", ".jpg", ".gif")

app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class QuickBar(
175175
View.VISIBLE
176176
}
177177
background =
178-
ColorManager.getDrawable(
178+
ColorManager.getDecorDrawable(
179179
"candidate_background",
180180
"candidate_border_color",
181181
dp(theme.generalStyle.candidateBorder),

app/src/main/java/com/osfans/trime/ime/candidates/unrolled/UnrolledCandidateLayout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class UnrolledCandidateLayout(
2929
init {
3030
id = R.id.unrolled_candidate_view
3131
background =
32-
ColorManager.getDrawable(
32+
ColorManager.getDecorDrawable(
3333
"candidate_background",
3434
"candidate_border_color",
3535
dp(theme.generalStyle.candidateBorder),

app/src/main/java/com/osfans/trime/ime/composition/CandidatesView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class CandidatesView(
208208
verticalPadding = dp(theme.generalStyle.layout.marginX)
209209
horizontalPadding = dp(theme.generalStyle.layout.marginY)
210210
background =
211-
ColorManager.getDrawable(
211+
ColorManager.getDecorDrawable(
212212
"text_back_color",
213213
"border_color",
214214
dp(theme.generalStyle.layout.border),

app/src/main/java/com/osfans/trime/ime/option/SwitchOptionEntryUi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SwitchOptionEntryUi(
4343
val bkg =
4444
frameLayout {
4545
background =
46-
ColorManager.getDrawable(
46+
ColorManager.getDecorDrawable(
4747
"key_back_color",
4848
"key_border_color",
4949
dp(theme.generalStyle.keyBorder),

app/src/main/java/com/osfans/trime/ime/symbol/DatabaseItemUi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DatabaseItemUi(
7676
isClickable = true
7777
minimumHeight = dp(30)
7878
background =
79-
ColorManager.getDrawable(
79+
ColorManager.getDecorDrawable(
8080
"key_back_color",
8181
"key_border_color",
8282
dp(theme.generalStyle.keyBorder),

app/src/main/java/com/osfans/trime/ime/symbol/LiquidItemUi.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import splitties.views.dsl.core.add
1919
import splitties.views.dsl.core.view
2020
import splitties.views.dsl.core.wrapContent
2121
import splitties.views.setPaddingDp
22-
import timber.log.Timber
2322

2423
class LiquidItemUi(
2524
override val ctx: Context,
@@ -36,7 +35,7 @@ class LiquidItemUi(
3635
}
3736

3837
override val root = constraintLayout {
39-
background = ColorManager.getDrawable(
38+
background = ColorManager.getDecorDrawable(
4039
"key_back_color",
4140
"key_border_color",
4241
dp(theme.generalStyle.keyBorder),

0 commit comments

Comments
 (0)