Skip to content

Commit

Permalink
fix: handle html hex code input
Browse files Browse the repository at this point in the history
Additional fix for #1061
  • Loading branch information
goofyz committed Dec 31, 2023
1 parent 895d305 commit 1a10a79
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/src/main/java/com/osfans/trime/data/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,24 @@ class Theme private constructor(isDarkMode: Boolean) {
): Drawable? {
if (key == null) return null
val o = theme.currentColors[key]
var color = o
if (o is String) {
val bitmap = bitmapDrawable(o)
if (bitmap != null) {
if (!alphaKey.isNullOrEmpty() && theme.style.getObject(alphaKey) != null) {
bitmap.alpha = MathUtils.clamp(theme.style.getInt(alphaKey), 0, 255)
if (isImageString(o)) {
val bitmap = bitmapDrawable(o)
if (bitmap != null) {
if (!alphaKey.isNullOrEmpty() && theme.style.getObject(alphaKey) != null) {
bitmap.alpha = MathUtils.clamp(theme.style.getInt(alphaKey), 0, 255)
}
return bitmap
}
return bitmap
} else {
// it is html hex color string (e.g. #ff0000)
color = ColorUtils.parseColor(o)
}
} else if (o is Int) {
val gradient = GradientDrawable().apply { setColor(o) }
}

if (color is Int) {
val gradient = GradientDrawable().apply { setColor(color) }
if (roundCornerKey.isNotEmpty()) {
gradient.cornerRadius = theme.style.getFloat(roundCornerKey)
}
Expand Down

0 comments on commit 1a10a79

Please sign in to comment.