Use ThemedBatteryDrawable in settings
Changed out BatteryMeterDrawable to inherit from ThemedBatteryDrawable instead of BatteryMeterDrawableBase. Also removed warning text paint because it seemed unused and simplified the interface. Bug: 123705805 Test: visual Change-Id: I30496e3d8881803d9d3d8a316c10387482a8f610
This commit is contained in:
@@ -98,8 +98,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
new BatteryMeterView.BatteryMeterDrawable(context,
|
new BatteryMeterView.BatteryMeterDrawable(context,
|
||||||
context.getColor(R.color.meter_background_color));
|
context.getColor(R.color.meter_background_color));
|
||||||
drawable.setBatteryLevel(level);
|
drawable.setBatteryLevel(level);
|
||||||
drawable.setShowPercent(false);
|
drawable.setColorFilter(new PorterDuffColorFilter(
|
||||||
drawable.setBatteryColorFilter(new PorterDuffColorFilter(
|
|
||||||
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
||||||
android.R.attr.colorControlNormal),
|
android.R.attr.colorControlNormal),
|
||||||
PorterDuff.Mode.SRC_IN));
|
PorterDuff.Mode.SRC_IN));
|
||||||
|
@@ -29,7 +29,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.graph.BatteryMeterDrawableBase;
|
import com.android.settingslib.graph.ThemedBatteryDrawable;
|
||||||
|
|
||||||
public class BatteryMeterView extends ImageView {
|
public class BatteryMeterView extends ImageView {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -54,29 +54,27 @@ public class BatteryMeterView extends ImageView {
|
|||||||
final int frameColor = context.getColor(R.color.meter_background_color);
|
final int frameColor = context.getColor(R.color.meter_background_color);
|
||||||
mAccentColorFilter = new PorterDuffColorFilter(
|
mAccentColorFilter = new PorterDuffColorFilter(
|
||||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
|
Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
|
||||||
PorterDuff.Mode.SRC_IN);
|
PorterDuff.Mode.SRC);
|
||||||
mErrorColorFilter = new PorterDuffColorFilter(
|
mErrorColorFilter = new PorterDuffColorFilter(
|
||||||
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
|
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
mDrawable = new BatteryMeterDrawable(context, frameColor);
|
mDrawable = new BatteryMeterDrawable(context, frameColor);
|
||||||
mDrawable.setShowPercent(false);
|
mDrawable.setColorFilter(mAccentColorFilter);
|
||||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
|
||||||
mDrawable.setWarningColorFilter(
|
|
||||||
new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
|
|
||||||
setImageDrawable(mDrawable);
|
setImageDrawable(mDrawable);
|
||||||
|
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatteryLevel(int level) {
|
public void setBatteryLevel(int level) {
|
||||||
mDrawable.setBatteryLevel(level);
|
mDrawable.setBatteryLevel(level);
|
||||||
if (level < mDrawable.getCriticalLevel()) {
|
if (level < mDrawable.getCriticalLevel()) {
|
||||||
mDrawable.setBatteryColorFilter(mErrorColorFilter);
|
mDrawable.setColorFilter(mErrorColorFilter);
|
||||||
} else {
|
} else {
|
||||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
mDrawable.setColorFilter(mAccentColorFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPowerSave(boolean powerSave) {
|
public void setPowerSave(boolean powerSave) {
|
||||||
mDrawable.setPowerSave(powerSave);
|
mDrawable.setPowerSaveEnabled(powerSave);
|
||||||
mPowerSaveEnabled = powerSave;
|
mPowerSaveEnabled = powerSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +83,7 @@ public class BatteryMeterView extends ImageView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getBatteryLevel() {
|
public int getBatteryLevel() {
|
||||||
return mDrawable.getBatteryLevel();
|
return mDrawable.getLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharging(boolean charging) {
|
public void setCharging(boolean charging) {
|
||||||
@@ -97,7 +95,7 @@ public class BatteryMeterView extends ImageView {
|
|||||||
return mDrawable.getCharging();
|
return mDrawable.getCharging();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
|
public static class BatteryMeterDrawable extends ThemedBatteryDrawable {
|
||||||
private final int mIntrinsicWidth;
|
private final int mIntrinsicWidth;
|
||||||
private final int mIntrinsicHeight;
|
private final int mIntrinsicHeight;
|
||||||
|
|
||||||
@@ -119,16 +117,5 @@ public class BatteryMeterView extends ImageView {
|
|||||||
public int getIntrinsicHeight() {
|
public int getIntrinsicHeight() {
|
||||||
return mIntrinsicHeight;
|
return mIntrinsicHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
|
|
||||||
mWarningTextPaint.setColorFilter(colorFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
|
|
||||||
mFramePaint.setColorFilter(colorFilter);
|
|
||||||
mBatteryPaint.setColorFilter(colorFilter);
|
|
||||||
mBoltPaint.setColorFilter(colorFilter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
@@ -73,14 +73,14 @@ public class BatteryMeterViewTest {
|
|||||||
public void testSetBatteryInfo_levelLow_setErrorColor() {
|
public void testSetBatteryInfo_levelLow_setErrorColor() {
|
||||||
mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
|
mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
|
||||||
|
|
||||||
verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
|
verify(mDrawable).setColorFilter(mErrorColorFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetBatteryInfo_levelNormal_setNormalColor() {
|
public void testSetBatteryInfo_levelNormal_setNormalColor() {
|
||||||
mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
|
mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
|
||||||
|
|
||||||
verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
|
verify(mDrawable).setColorFilter(mAccentColorFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user