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

Commit b89ffbda authored by Jean-Pierre Rasquin's avatar Jean-Pierre Rasquin Committed by Nick Reuter
Browse files

BatteryMeterDrawable: add dotted circle style

Updated to Kotlin by Christian Oder <myself5@carbonrom.org>

Change-Id: I20e14cd53c1419bcee1d90d701abded8f2afb4b8
parent f0964915
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class CircleBatteryDrawable(private val context: Context, frameColor: Int) : Dra
    private val padding = Rect()
    private val frame = RectF()
    private val boltFrame = RectF()
    private val pathEffect = DashPathEffect(floatArrayOf(3f,2f),0f)

    private var chargeColor: Int
    private var iconTint = Color.WHITE
@@ -81,6 +82,12 @@ class CircleBatteryDrawable(private val context: Context, frameColor: Int) : Dra
            postInvalidate()
        }

    var usePathEffect = false
        set(value) {
            field = value
            postInvalidate()
        }

    // an approximation of View.postInvalidate()
    private fun postInvalidate() {
        unscheduleSelf { invalidateSelf() }
@@ -158,6 +165,13 @@ class CircleBatteryDrawable(private val context: Context, frameColor: Int) : Dra
        framePaint.style = Paint.Style.STROKE
        batteryPaint.strokeWidth = strokeWidth
        batteryPaint.style = Paint.Style.STROKE
        if (usePathEffect) {
            batteryPaint.pathEffect = pathEffect
            powerSavePaint.pathEffect = pathEffect
        } else {
            batteryPaint.pathEffect = null
            powerSavePaint.pathEffect = null
        }
        powerSavePaint.strokeWidth = strokeWidth
        frame[
                strokeWidth / 2.0f + padding.left, strokeWidth / 2.0f,
+6 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
    protected static final int BATTERY_STYLE_PORTRAIT = 0;
    protected static final int BATTERY_STYLE_CIRCLE = 1;
    protected static final int BATTERY_STYLE_TEXT = 2;
    protected static final int BATTERY_STYLE_DOTTED_CIRCLE = 3;

    @Retention(SOURCE)
    @IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF, MODE_ESTIMATE})
@@ -685,7 +686,9 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
        float iconScaleFactor = typedValue.getFloat();

        int batteryHeight = res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_height);
        int batteryWidth = getBatteryStyle() == BATTERY_STYLE_CIRCLE ?
        int batteryWidth =
                (getBatteryStyle() == BATTERY_STYLE_CIRCLE
                        || getBatteryStyle() == BATTERY_STYLE_DOTTED_CIRCLE) ?
                res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_circle_width) :
                res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_width);
        float mainBatteryHeight = batteryHeight * iconScaleFactor;
@@ -730,6 +733,8 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
                mBatteryIconView.setVisibility(View.VISIBLE);
                break;
            case BATTERY_STYLE_CIRCLE:
            case BATTERY_STYLE_DOTTED_CIRCLE:
                mCircleDrawable.setUsePathEffect(getBatteryStyle() == BATTERY_STYLE_DOTTED_CIRCLE);
                mBatteryIconView.setImageDrawable(mCircleDrawable);
                mBatteryIconView.setVisibility(View.VISIBLE);
                break;