Fix text drawable icon scaling
This commit is contained in:
parent
0711d02dbf
commit
11df4376a1
@ -7,7 +7,8 @@ import android.graphics.drawable.Drawable
|
||||
class TextDrawable(
|
||||
val text: String,
|
||||
val color: Int = Color.WHITE,
|
||||
fontSize: Float = 13f,
|
||||
val height: Int? = null,
|
||||
val fontSize: Float = 13f,
|
||||
typeface: Typeface = Typeface.DEFAULT
|
||||
): Drawable() {
|
||||
|
||||
@ -25,6 +26,8 @@ class TextDrawable(
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
val bounds = bounds
|
||||
if (height != null) paint.textSize = fontSize * bounds.height().toFloat() / height.toFloat()
|
||||
else paint.textSize = fontSize
|
||||
paint.getTextBounds(text, 0, text.length, rect)
|
||||
canvas.drawText(text, bounds.exactCenterX(), bounds.exactCenterY() + rect.height() / 2f, paint)
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import android.graphics.Typeface
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.provider.CalendarContract
|
||||
import android.text.format.DateFormat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.graphics.blue
|
||||
@ -18,6 +19,7 @@ import de.mm20.launcher2.graphics.TextDrawable
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class CalendarEvent(
|
||||
override val label: String,
|
||||
@ -37,27 +39,15 @@ class CalendarEvent(
|
||||
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): LauncherIcon {
|
||||
val df = SimpleDateFormat("d")
|
||||
val day = df.format(startTime)
|
||||
df.applyPattern("MMM")
|
||||
val month = df.format(startTime)
|
||||
val fgLayers = arrayOf(
|
||||
TextDrawable(
|
||||
day,
|
||||
color = Color.WHITE,
|
||||
fontSize = 20 * context.dp,
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
),
|
||||
TextDrawable(
|
||||
month,
|
||||
color = Color.WHITE,
|
||||
fontSize = 13 * context.dp,
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
)
|
||||
val df = SimpleDateFormat("dd")
|
||||
val s = (48 * context.dp).toInt()
|
||||
val foreground = TextDrawable(
|
||||
df.format(startTime),
|
||||
color = Color.WHITE,
|
||||
fontSize = 24 * context.dp,
|
||||
typeface = Typeface.DEFAULT_BOLD,
|
||||
height = s
|
||||
)
|
||||
val foreground = LayerDrawable(fgLayers)
|
||||
foreground.setLayerInset(0, 0, 0, 0, (13 * context.dp).toInt())
|
||||
foreground.setLayerInset(1, 0, (20 * context.dp).toInt(), 0, 0)
|
||||
val background = ColorDrawable(getDisplayColor(context, color))
|
||||
return LauncherIcon(
|
||||
foreground = foreground,
|
||||
|
||||
@ -15,6 +15,7 @@ import de.mm20.launcher2.contacts.R
|
||||
import de.mm20.launcher2.graphics.TextDrawable
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.asBitmap
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.ktx.sp
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -51,6 +52,7 @@ class Contact(
|
||||
iconText,
|
||||
Color.WHITE,
|
||||
fontSize = 20 * context.sp,
|
||||
height = (48 * context.dp).toInt(),
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
),
|
||||
background = ColorDrawable(ContextCompat.getColor(context, R.color.blue))
|
||||
|
||||
@ -12,6 +12,7 @@ import coil.imageLoader
|
||||
import coil.request.ImageRequest
|
||||
import de.mm20.launcher2.graphics.TextDrawable
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.ktx.sp
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
@ -56,7 +57,8 @@ class Website(
|
||||
TextDrawable(
|
||||
label[0].toString(),
|
||||
typeface = Typeface.DEFAULT_BOLD,
|
||||
fontSize = 40 * context.sp
|
||||
fontSize = 40 * context.sp,
|
||||
height = (48 * context.dp).toInt()
|
||||
)
|
||||
} else context.getDrawable(R.drawable.ic_website)!!
|
||||
return LauncherIcon(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user