Merge "Use ThemedBatteryDrawable in settings"

This commit is contained in:
TreeHugger Robot
2019-02-27 06:02:49 +00:00
committed by Android (Google) Code Review
3 changed files with 12 additions and 26 deletions

View File

@@ -164,8 +164,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));

View File

@@ -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);
}
} }
} }

View File

@@ -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