Merge "Merge "Update battery saver colors to make them more obvious" into pi-dev am: 3dc91c1426" into pi-dev-plus-aosp

This commit is contained in:
Android Build Merger (Role)
2018-03-10 00:29:47 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 11 deletions

View File

@@ -0,0 +1,18 @@
<?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>

View File

@@ -54,6 +54,7 @@ public class BatteryMeterDrawableBase extends Drawable {
private int mLevel = -1; private int mLevel = -1;
private boolean mCharging; private boolean mCharging;
private boolean mPowerSaveEnabled; private boolean mPowerSaveEnabled;
private boolean mPowerSaveAsColorError = true;
private boolean mShowPercent; private boolean mShowPercent;
private static final boolean SINGLE_DIGIT_PERCENT = false; 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)); mBoltPaint.setColor(Utils.getDefaultColor(mContext, R.color.batterymeter_bolt_color));
mBoltPoints = loadPoints(res, R.array.batterymeter_bolt_points); 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); mPlusPoints = loadPoints(res, R.array.batterymeter_plus_points);
mIntrinsicWidth = context.getResources().getDimensionPixelSize(R.dimen.battery_width); mIntrinsicWidth = context.getResources().getDimensionPixelSize(R.dimen.battery_width);
@@ -195,6 +197,10 @@ public class BatteryMeterDrawableBase extends Drawable {
postInvalidate(); postInvalidate();
} }
protected void setPowerSaveAsColorError(boolean asError) {
mPowerSaveAsColorError = asError;
}
// an approximation of View.postInvalidate() // an approximation of View.postInvalidate()
protected void postInvalidate() { protected void postInvalidate() {
unscheduleSelf(this::invalidateSelf); unscheduleSelf(this::invalidateSelf);
@@ -254,10 +260,6 @@ public class BatteryMeterDrawableBase extends Drawable {
} }
private int getColorForLevel(int percent) { 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; int thresh, color = 0;
for (int i = 0; i < mColors.length; i += 2) { for (int i = 0; i < mColors.length; i += 2) {
thresh = mColors[i]; thresh = mColors[i];
@@ -279,7 +281,6 @@ public class BatteryMeterDrawableBase extends Drawable {
mIconTint = fillColor; mIconTint = fillColor;
mFramePaint.setColor(backgroundColor); mFramePaint.setColor(backgroundColor);
mBoltPaint.setColor(fillColor); mBoltPaint.setColor(fillColor);
mPlusPaint.setColor(fillColor);
mChargeColor = fillColor; mChargeColor = fillColor;
invalidateSelf(); invalidateSelf();
} }
@@ -392,14 +393,16 @@ public class BatteryMeterDrawableBase extends Drawable {
mPlusFrame.top + mPlusPoints[1] * mPlusFrame.height()); mPlusFrame.top + mPlusPoints[1] * mPlusFrame.height());
} }
float boltPct = (mPlusFrame.bottom - levelTop) / (mPlusFrame.bottom - mPlusFrame.top); float fillPct = (mPlusFrame.bottom - levelTop) / (mPlusFrame.bottom - mPlusFrame.top);
boltPct = Math.min(Math.max(boltPct, 0), 1); fillPct = Math.min(Math.max(fillPct, 0), 1);
if (boltPct <= BOLT_LEVEL_THRESHOLD) { if (fillPct <= BOLT_LEVEL_THRESHOLD) {
// draw the bolt if opaque // draw the plus if opaque
c.drawPath(mPlusPath, mPlusPaint); c.drawPath(mPlusPath, mPlusPaint);
} else { } else {
// otherwise cut the bolt out of the overall shape
mShapePath.op(mPlusPath, Path.Op.DIFFERENCE); mShapePath.op(mPlusPath, Path.Op.DIFFERENCE);
if (mPowerSaveAsColorError) {
c.drawPath(mPlusPath, mPlusPaint);
}
} }
} }

View File

@@ -129,6 +129,7 @@ public class BatterySaverTile extends QSTileImpl<BooleanState> implements
super.setBatteryLevel(MAX_BATTERY); super.setBatteryLevel(MAX_BATTERY);
setPowerSave(true); setPowerSave(true);
setCharging(false); setCharging(false);
setPowerSaveAsColorError(false);
} }
@Override @Override