mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Ensure RingView.diameter is never zero
In rare cases, it seems either that `onDraw` is called before `onMeasure` or that `onMeasure` is called with a view that has zero height/width. This causes `reallocateCache` to produce an IllegalArgumentException. This patch ensures that diameter is never zero. Fixes #904
This commit is contained in:
@@ -41,6 +41,7 @@ import org.isoron.uhabits.utils.InterfaceUtils.getFontAwesome
|
||||
import org.isoron.uhabits.utils.InterfaceUtils.spToPixels
|
||||
import org.isoron.uhabits.utils.PaletteUtils.getAndroidTestColor
|
||||
import org.isoron.uhabits.utils.StyledResources
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
@@ -48,7 +49,7 @@ class RingView : View {
|
||||
private var color: Int
|
||||
private var precision: Float
|
||||
private var percentage: Float
|
||||
private var diameter = 0
|
||||
private var diameter = 1
|
||||
private var thickness: Float
|
||||
private var rect: RectF? = null
|
||||
private var pRing: TextPaint? = null
|
||||
@@ -169,7 +170,7 @@ class RingView : View {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||
diameter = min(height, width)
|
||||
diameter = max(1, min(height, width))
|
||||
pRing!!.textSize = textSize
|
||||
em = pRing!!.measureText("M")
|
||||
setMeasuredDimension(diameter, diameter)
|
||||
|
||||
Reference in New Issue
Block a user