Replace TextDrawable with an implementation that supports tint
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package de.mm20.launcher2.graphics
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
class TextDrawable(
|
||||
val text: String,
|
||||
val color: Int = Color.WHITE,
|
||||
fontSize: Float = 13f,
|
||||
typeface: Typeface = Typeface.DEFAULT
|
||||
): Drawable() {
|
||||
|
||||
private val paint = Paint()
|
||||
private val rect = Rect()
|
||||
|
||||
init {
|
||||
paint.textAlign = Paint.Align.CENTER
|
||||
paint.textSize = fontSize
|
||||
paint.color = color
|
||||
paint.isAntiAlias = true
|
||||
paint.typeface = typeface
|
||||
paint.style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
val bounds = bounds
|
||||
paint.getTextBounds(text, 0, text.length, rect)
|
||||
canvas.drawText(text, bounds.exactCenterX(), bounds.exactCenterY() + rect.height() / 2f, paint)
|
||||
}
|
||||
|
||||
override fun setAlpha(alpha: Int) {
|
||||
paint.alpha = alpha
|
||||
}
|
||||
|
||||
override fun setColorFilter(colorFilter: ColorFilter?) {
|
||||
paint.colorFilter = colorFilter
|
||||
}
|
||||
|
||||
override fun getOpacity(): Int {
|
||||
return PixelFormat.TRANSLUCENT
|
||||
}
|
||||
|
||||
override fun setTintList(tint: ColorStateList?) {
|
||||
paint.color = tint?.defaultColor ?: color
|
||||
}
|
||||
}
|
||||
@@ -77,14 +77,6 @@ val OpenSourceLicenses = arrayOf(
|
||||
copyrightNote = "Copyright (c) 2009-2021 Jonathan Hedley <https://jsoup.org/>",
|
||||
url = "https://jsoup.org/"
|
||||
),
|
||||
OpenSourceLibrary(
|
||||
name = "TextDrawable",
|
||||
description = "A light-weight library providing images with letter/text like the Gmail app",
|
||||
licenseName = R.string.mit_license_name,
|
||||
licenseText = R.raw.license_mit,
|
||||
copyrightNote = "Copyright (c) 2014 Amulya Khare",
|
||||
url = "https://github.com/amulyakhare/TextDrawable"
|
||||
),
|
||||
OpenSourceLibrary(
|
||||
name = "Glide",
|
||||
description = "A fast and efficient open source media management and image loading framework for Android",
|
||||
|
||||
Reference in New Issue
Block a user