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