@@ -16,6 +16,7 @@ import android.graphics.drawable.GradientDrawable
1616import android.graphics.drawable.NinePatchDrawable
1717import androidx.annotation.ColorInt
1818import androidx.collection.LruCache
19+ import androidx.core.graphics.drawable.toDrawable
1920import androidx.core.math.MathUtils
2021import com.osfans.trime.data.base.DataManager
2122import com.osfans.trime.data.theme.model.ColorScheme
@@ -247,13 +248,13 @@ object ColorManager {
247248 NinePatchBitmapFactory .createNinePatchDrawable(Resources .getSystem(), bitmap)
248249 }
249250 }
250- return BitmapDrawable (Resources .getSystem(), bitmap )
251+ return bitmap.toDrawable (Resources .getSystem())
251252 } else {
252253 val color =
253254 try {
254255 ColorUtils .parseColor(value)
255256 } catch (_: Exception ) {
256- return null
257+ Color . TRANSPARENT
257258 }
258259 return GradientDrawable ().apply { setColor(color) }
259260 }
@@ -271,15 +272,16 @@ object ColorManager {
271272 @ColorInt
272273 fun getColor (key : String ): Int = colorCache[key] ? : resolveColor(key)
273274
275+ fun getDrawable (key : String ): Drawable ? = drawableCache[key] ? : resolveDrawable(key)
276+
274277 fun getDrawable (
275278 colorKey : String ,
276279 borderColorKey : String? = null,
277280 borderPx : Int = 0,
278281 cornerRadius : Float = 0f,
279282 alpha : Int = 255,
280- ): Drawable ? {
281- val drawable = drawableCache[colorKey] ? : resolveDrawable(colorKey)
282- return when (drawable) {
283+ ): Drawable ? =
284+ when (val drawable = getDrawable(colorKey)) {
283285 is BitmapDrawable -> drawable.also { it.alpha = MathUtils .clamp(alpha, 0 , 255 ) }
284286 is GradientDrawable ->
285287 drawable.also {
@@ -295,7 +297,6 @@ object ColorManager {
295297 }
296298 else -> null
297299 }
298- }
299300
300301 private val SUPPORTED_IMG_FORMATS = arrayOf(" .png" , " .webp" , " .jpg" , " .gif" )
301302}
0 commit comments