Refactor icons
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package de.mm20.launcher2.ktx
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorFilter
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.annotation.Px
|
||||
@@ -13,4 +15,11 @@ fun Drawable.toBitmapOrNull(
|
||||
): Bitmap? {
|
||||
if (this is BitmapDrawable && bitmap == null) return null
|
||||
return toBitmap(width, height, config)
|
||||
}
|
||||
|
||||
fun Drawable.drawWithColorFilter(canvas: Canvas, colorFilter: ColorFilter?) {
|
||||
val cf = this.colorFilter
|
||||
this.colorFilter = colorFilter
|
||||
this.draw(canvas)
|
||||
this.colorFilter = cf
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.mm20.launcher2.ktx
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
|
||||
fun LayerDrawable.getDrawableOrNull(index: Int): Drawable? {
|
||||
return try {
|
||||
this.getDrawable(index)
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user