mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-13 20:48:52 -06:00
Improvement - do not allocate Paint() in onDraw for Checkmark/Number Button View
This commit is contained in:
@@ -135,6 +135,7 @@ class CheckmarkButtonView(
|
||||
private val bgColor = sres.getColor(R.attr.cardBgColor)
|
||||
private val lowContrastColor = sres.getColor(R.attr.contrast40)
|
||||
private val mediumContrastColor = sres.getColor(R.attr.contrast60)
|
||||
private val pNotesIndicator = Paint()
|
||||
|
||||
private val paint = TextPaint().apply {
|
||||
typeface = getFontAwesome()
|
||||
@@ -192,7 +193,13 @@ class CheckmarkButtonView(
|
||||
canvas.drawText(label, rect.centerX(), rect.centerY(), paint)
|
||||
}
|
||||
|
||||
drawNotesIndicator(canvas, color, em, notes)
|
||||
drawNotesIndicator(
|
||||
pNotesIndicator = pNotesIndicator,
|
||||
canvas = canvas,
|
||||
color = color,
|
||||
size = em,
|
||||
notes = notes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ class NumberButtonView(
|
||||
private val lowContrast: Int
|
||||
private val mediumContrast: Int
|
||||
|
||||
private val pNotesIndicator = Paint()
|
||||
|
||||
private val paint = TextPaint().apply {
|
||||
typeface = getFontAwesome()
|
||||
isAntiAlias = true
|
||||
@@ -234,7 +236,13 @@ class NumberButtonView(
|
||||
canvas.drawText(trimmedUnits, rect.centerX(), rect.centerY(), pUnit)
|
||||
}
|
||||
|
||||
drawNotesIndicator(canvas, color, em, notes)
|
||||
drawNotesIndicator(
|
||||
pNotesIndicator = pNotesIndicator,
|
||||
canvas = canvas,
|
||||
color = color,
|
||||
size = em,
|
||||
notes = notes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,14 +210,19 @@ fun View.sp(value: Float) = InterfaceUtils.spToPixels(context, value)
|
||||
fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value)
|
||||
fun View.str(id: Int) = resources.getString(id)
|
||||
|
||||
fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, notes: String) {
|
||||
val pNotesIndicator = Paint()
|
||||
fun View.drawNotesIndicator(
|
||||
pNotesIndicator: Paint,
|
||||
canvas: Canvas,
|
||||
color: Int,
|
||||
size: Float,
|
||||
notes: String,
|
||||
) {
|
||||
if (notes.isBlank()) return
|
||||
|
||||
pNotesIndicator.color = color
|
||||
if (notes.isNotBlank()) {
|
||||
val cy = 0.8f * size
|
||||
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
||||
}
|
||||
}
|
||||
|
||||
val View.sres: StyledResources
|
||||
get() = StyledResources(context)
|
||||
|
||||
Reference in New Issue
Block a user