mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Avoid calling textPaint.getTextBounds repeatedly
This operation seems to be very expensive on some Samsung phones, which causes ANRs. Fixes #962
This commit is contained in:
@@ -36,6 +36,7 @@ class AndroidCanvas : Canvas {
|
||||
var innerDensity = 1.0
|
||||
var innerWidth = 0
|
||||
var innerHeight = 0
|
||||
var mHeight = 15
|
||||
|
||||
var paint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
@@ -64,11 +65,10 @@ class AndroidCanvas : Canvas {
|
||||
}
|
||||
|
||||
override fun drawText(text: String, x: Double, y: Double) {
|
||||
textPaint.getTextBounds(text, 0, text.length, textBounds)
|
||||
innerCanvas.drawText(
|
||||
text,
|
||||
x.toDp(),
|
||||
y.toDp() - textBounds.exactCenterY(),
|
||||
y.toDp() + 0.6f * mHeight,
|
||||
textPaint,
|
||||
)
|
||||
}
|
||||
@@ -126,10 +126,17 @@ class AndroidCanvas : Canvas {
|
||||
Font.BOLD -> Typeface.DEFAULT_BOLD
|
||||
Font.FONT_AWESOME -> getFontAwesome(context)
|
||||
}
|
||||
updateMHeight()
|
||||
}
|
||||
|
||||
override fun setFontSize(size: Double) {
|
||||
textPaint.textSize = size.toDp()
|
||||
updateMHeight()
|
||||
}
|
||||
|
||||
private fun updateMHeight() {
|
||||
textPaint.getTextBounds("m", 0, 1, textBounds)
|
||||
mHeight = textBounds.height()
|
||||
}
|
||||
|
||||
override fun setStrokeWidth(size: Double) {
|
||||
|
||||
@@ -65,7 +65,6 @@ open class HabitPickerDialog : Activity() {
|
||||
widgetUpdater = component.widgetUpdater
|
||||
widgetId = intent.extras?.getInt(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID) ?: 0
|
||||
|
||||
|
||||
val habitIds = ArrayList<Long>()
|
||||
val habitNames = ArrayList<String>()
|
||||
for (h in habitList) {
|
||||
|
||||
Reference in New Issue
Block a user