Refactor icons

This commit is contained in:
MM20
2022-06-18 18:51:41 +02:00
parent 08e736f5d1
commit 6de89f3f79
54 changed files with 894 additions and 1489 deletions
@@ -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
}
}