Merge "Update battery saver colors to make them more obvious" into pi-dev
am: 3dc91c1426
Change-Id: I88202e9d06e60f8862aa4b32c8df6c981a89c3f7
This commit is contained in:
18
packages/SettingsLib/res/color/batterymeter_plus_color.xml
Normal file
18
packages/SettingsLib/res/color/batterymeter_plus_color.xml
Normal 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>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ public class BatterySaverTile extends QSTileImpl<BooleanState> implements
|
||||
super.setBatteryLevel(MAX_BATTERY);
|
||||
setPowerSave(true);
|
||||
setCharging(false);
|
||||
setPowerSaveAsColorError(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user