Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8140ea9f authored by Evan Laird's avatar Evan Laird
Browse files

Don't use Drawable's `level`, use our own

Test: visual
Fixes: 129014647
Change-Id: I8b43a48f8e59eb789cb7f096ea5cf3f289c2d572
parent c4a1f889
Loading
Loading
Loading
Loading
+9 −7
Original line number Original line Diff line number Diff line
@@ -83,6 +83,8 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
    // Dual tone implies that battery level is a clipped overlay over top of the whole shape
    // Dual tone implies that battery level is a clipped overlay over top of the whole shape
    private var dualTone = false
    private var dualTone = false


    private var batteryLevel = 0

    private val invalidateRunnable: () -> Unit = {
    private val invalidateRunnable: () -> Unit = {
        invalidateSelf()
        invalidateSelf()
    }
    }
@@ -176,9 +178,9 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
        unifiedPath.reset()
        unifiedPath.reset()
        levelPath.reset()
        levelPath.reset()
        levelRect.set(fillRect)
        levelRect.set(fillRect)
        val fillFraction = level / 100f
        val fillFraction = batteryLevel / 100f
        val fillTop =
        val fillTop =
                if (level >= 95)
                if (batteryLevel >= 95)
                    fillRect.top
                    fillRect.top
                else
                else
                    fillRect.top + (fillRect.height() * (1 - fillFraction))
                    fillRect.top + (fillRect.height() * (1 - fillFraction))
@@ -222,7 +224,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
            fillPaint.color = levelColor
            fillPaint.color = levelColor


            // Show colorError below this level
            // Show colorError below this level
            if (level <= Companion.CRITICAL_LEVEL && !charging) {
            if (batteryLevel <= Companion.CRITICAL_LEVEL && !charging) {
                c.save()
                c.save()
                c.clipPath(scaledFill)
                c.clipPath(scaledFill)
                c.drawPath(levelPath, fillPaint)
                c.drawPath(levelPath, fillPaint)
@@ -308,13 +310,13 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
     */
     */
    public open fun setBatteryLevel(l: Int) {
    public open fun setBatteryLevel(l: Int) {
        invertFillIcon = if (l >= 67) true else if (l <= 33) false else invertFillIcon
        invertFillIcon = if (l >= 67) true else if (l <= 33) false else invertFillIcon
        level = l
        batteryLevel = l
        levelColor = batteryColorForLevel(level)
        levelColor = batteryColorForLevel(batteryLevel)
        invalidateSelf()
        invalidateSelf()
    }
    }


    public fun getBatteryLevel(): Int {
    public fun getBatteryLevel(): Int {
        return level
        return batteryLevel
    }
    }


    override fun onBoundsChange(bounds: Rect?) {
    override fun onBoundsChange(bounds: Rect?) {
@@ -341,7 +343,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
        dualToneBackgroundFill.color = bgColor
        dualToneBackgroundFill.color = bgColor


        // Also update the level color, since fillColor may have changed
        // Also update the level color, since fillColor may have changed
        levelColor = batteryColorForLevel(level)
        levelColor = batteryColorForLevel(batteryLevel)


        invalidateSelf()
        invalidateSelf()
    }
    }