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

Commit 9eb4610d authored by Evan Laird's avatar Evan Laird
Browse files

Update battery saver colors to make them more obvious

Use colorError for the plus symbol (when in status bar) and always draw
the fill as colorError when below 15%

Test: turn on systemUI demo mode
      adb shell am broadcast -a "com.android.systemui.demo" -e command battery -e plugged false
      adb shell am broadcast -a "com.android.systemui.demo" -e command battery -e powersave true
      # verify that the plus sign is red
      adb shell am broadcast -a "com.android.systemui.demo" -e command battery -e level 15
      # verify that the fill color is red and the plus stays red

Change-Id: I9898c3d56372bad822aeff021a470958ed3908a6
Fixes: 71873178
parent e84c506f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="?android:attr/colorError" />
</selector>
+14 −11
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public class BatteryMeterDrawableBase extends Drawable {
    private int mLevel = -1;
    private boolean mCharging;
    private boolean mPowerSaveEnabled;
    private boolean mPowerSaveAsColorError = true;
    private boolean mShowPercent;

    private static final boolean SINGLE_DIGIT_PERCENT = false;
@@ -150,7 +151,8 @@ public class BatteryMeterDrawableBase extends Drawable {
        mBoltPaint.setColor(Utils.getDefaultColor(mContext, R.color.batterymeter_bolt_color));
        mBoltPoints = loadPoints(res, R.array.batterymeter_bolt_points);

        mPlusPaint = new Paint(mBoltPaint);
        mPlusPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPlusPaint.setColor(Utils.getDefaultColor(mContext, R.color.batterymeter_plus_color));
        mPlusPoints = loadPoints(res, R.array.batterymeter_plus_points);

        mIntrinsicWidth = context.getResources().getDimensionPixelSize(R.dimen.battery_width);
@@ -195,6 +197,10 @@ public class BatteryMeterDrawableBase extends Drawable {
        postInvalidate();
    }

    protected void setPowerSaveAsColorError(boolean asError) {
        mPowerSaveAsColorError = asError;
    }

    // an approximation of View.postInvalidate()
    protected void postInvalidate() {
        unscheduleSelf(this::invalidateSelf);
@@ -254,10 +260,6 @@ public class BatteryMeterDrawableBase extends Drawable {
    }

    private int getColorForLevel(int percent) {
        // If we are in power save mode, always use the normal color.
        if (mPowerSaveEnabled) {
            return mIconTint;
        }
        int thresh, color = 0;
        for (int i = 0; i < mColors.length; i += 2) {
            thresh = mColors[i];
@@ -279,7 +281,6 @@ public class BatteryMeterDrawableBase extends Drawable {
        mIconTint = fillColor;
        mFramePaint.setColor(backgroundColor);
        mBoltPaint.setColor(fillColor);
        mPlusPaint.setColor(fillColor);
        mChargeColor = fillColor;
        invalidateSelf();
    }
@@ -392,14 +393,16 @@ public class BatteryMeterDrawableBase extends Drawable {
                        mPlusFrame.top + mPlusPoints[1] * mPlusFrame.height());
            }

            float boltPct = (mPlusFrame.bottom - levelTop) / (mPlusFrame.bottom - mPlusFrame.top);
            boltPct = Math.min(Math.max(boltPct, 0), 1);
            if (boltPct <= BOLT_LEVEL_THRESHOLD) {
                // draw the bolt if opaque
            float fillPct = (mPlusFrame.bottom - levelTop) / (mPlusFrame.bottom - mPlusFrame.top);
            fillPct = Math.min(Math.max(fillPct, 0), 1);
            if (fillPct <= BOLT_LEVEL_THRESHOLD) {
                // draw the plus if opaque
                c.drawPath(mPlusPath, mPlusPaint);
            } else {
                // otherwise cut the bolt out of the overall shape
                mShapePath.op(mPlusPath, Path.Op.DIFFERENCE);
                if (mPowerSaveAsColorError) {
                    c.drawPath(mPlusPath, mPlusPaint);
                }
            }
        }

+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ public class BatterySaverTile extends QSTileImpl<BooleanState> implements
            super.setBatteryLevel(MAX_BATTERY);
            setPowerSave(true);
            setCharging(false);
            setPowerSaveAsColorError(false);
        }

        @Override