@@ -4,6 +4,7 @@ import android.content.Context
44import android.graphics.*
55import android.graphics.drawable.BitmapDrawable
66import android.graphics.drawable.Drawable
7+ import android.graphics.drawable.VectorDrawable
78import android.support.annotation.ColorInt
89import android.support.annotation.ColorRes
910import android.support.annotation.DimenRes
@@ -35,6 +36,14 @@ class DrawableBadge private constructor(val context: Context,
3536 private var isShowBorder: Boolean? = null
3637 private var maximumCounter: Int? = null
3738
39+ private fun createBitmapFromVectorDrawable (vectorDrawable : VectorDrawable ): Bitmap {
40+ val bitmap = Bitmap .createBitmap(vectorDrawable.intrinsicWidth, vectorDrawable.intrinsicHeight, Bitmap .Config .ARGB_8888 )
41+ val canvas = Canvas (bitmap)
42+ vectorDrawable.setBounds(0 , 0 , canvas.width, canvas.height)
43+ vectorDrawable.draw(canvas)
44+ return bitmap
45+ }
46+
3847 fun drawableResId (@DrawableRes drawableRes : Int ) = apply {
3948 val res = context.resources
4049 bitmap = BitmapFactory .decodeResource(res, drawableRes)
@@ -44,13 +53,19 @@ class DrawableBadge private constructor(val context: Context,
4453 if (d is BitmapDrawable ) {
4554 bitmap = d.bitmap
4655 }
56+ if (d is VectorDrawable ) {
57+ bitmap = createBitmapFromVectorDrawable(d)
58+ }
4759 }
4860 }
4961
5062 fun drawable (drawable : Drawable ) = apply {
5163 if (drawable is BitmapDrawable ) {
5264 this .bitmap = drawable.bitmap
5365 }
66+ if (drawable is VectorDrawable ) {
67+ this .bitmap = createBitmapFromVectorDrawable(drawable)
68+ }
5469 }
5570
5671 fun bitmap (bitmap : Bitmap ) = apply { this .bitmap = bitmap }
0 commit comments