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

Commit b8114bfb authored by Evan Laird's avatar Evan Laird Committed by Android (Google) Code Review
Browse files

Merge "[Battery] Update battery fill colors and fill clip" into main

parents ea55e55e 925ff714
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -95,8 +95,8 @@ sealed interface BatteryColors {
        // 22% alpha white
        override val bg: Int = Color.valueOf(1f, 1f, 1f, 0.22f).toArgb()

        // 18% alpha black
        override val fill = Color.valueOf(0f, 0f, 0f, 0.18f).toArgb()
        // GM Gray 600
        override val fill = Color.parseColor("#80868B")
        // GM Gray 700
        override val fillOnly = Color.parseColor("#5F6368")

@@ -115,8 +115,8 @@ sealed interface BatteryColors {
        // 18% alpha black
        override val bg: Int = Color.valueOf(0f, 0f, 0f, 0.18f).toArgb()

        // 22% alpha white
        override val fill = Color.valueOf(1f, 1f, 1f, 0.22f).toArgb()
        // GM Gray 700
        override val fill = Color.parseColor("#5F6368")
        // GM Gray 400
        override val fillOnly = Color.parseColor("#BDC1C6")

+9 −7
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import kotlin.math.roundToInt
/**
 * Draws a right-to-left fill inside of the given [framePath]. This fill is designed to exactly fill
 * the usable space inside of [framePath], given that the stroke width of the path is 1.5, and we
 * want an extra 0.25 (canvas units) of a gap between the fill and the stroke
 * want an extra 0.5 (canvas units) of a gap between the fill and the stroke
 */
class BatteryFillDrawable(private val framePath: Path) : Drawable() {
    private var hScale = 1f
@@ -61,7 +61,6 @@ class BatteryFillDrawable(private val framePath: Path) : Drawable() {
    private val clearPaint =
        Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
            p.style = Paint.Style.STROKE
            p.strokeWidth = 5f
            p.blendMode = BlendMode.CLEAR
        }

@@ -94,6 +93,9 @@ class BatteryFillDrawable(private val framePath: Path) : Drawable() {

        scaledLeftOffset = LeftFillOffset * hScale
        scaledRightInset = RightFillInset * hScale

        // Ensure 0.5dp space between the frame stroke and the fill
        clearPaint.strokeWidth = 2.5f * hScale
    }

    override fun draw(canvas: Canvas) {
@@ -155,15 +157,15 @@ class BatteryFillDrawable(private val framePath: Path) : Drawable() {
    override fun setAlpha(alpha: Int) {}

    companion object {
        // 3.75f =
        // 4f =
        //       2.75 (left-most edge of the frame path)
        //     + 0.75 (1/2 of the stroke width)
        //     + 0.25 (padding between stroke and fill edge)
        private const val LeftFillOffset = 3.75f
        //     + 0.5  (padding between stroke and fill edge)
        private const val LeftFillOffset = 4f

        // 1.75, calculated the same way, but from the right edge (without the battery cap), which
        // 2, calculated the same way, but from the right edge (without the battery cap), which
        // consumes 2 units of width.
        private const val RightFillInset = 1.75f
        private const val RightFillInset = 2f

        /** Scale this to the viewport so we fill correctly! */
        private val FillRect =