Merge "Use ThemedBatteryDrawable in settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3776476764
@@ -164,8 +164,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
new BatteryMeterView.BatteryMeterDrawable(context,
|
||||
context.getColor(R.color.meter_background_color));
|
||||
drawable.setBatteryLevel(level);
|
||||
drawable.setShowPercent(false);
|
||||
drawable.setBatteryColorFilter(new PorterDuffColorFilter(
|
||||
drawable.setColorFilter(new PorterDuffColorFilter(
|
||||
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.colorControlNormal),
|
||||
PorterDuff.Mode.SRC_IN));
|
||||
|
@@ -29,7 +29,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.graph.BatteryMeterDrawableBase;
|
||||
import com.android.settingslib.graph.ThemedBatteryDrawable;
|
||||
|
||||
public class BatteryMeterView extends ImageView {
|
||||
@VisibleForTesting
|
||||
@@ -54,29 +54,27 @@ public class BatteryMeterView extends ImageView {
|
||||
final int frameColor = context.getColor(R.color.meter_background_color);
|
||||
mAccentColorFilter = new PorterDuffColorFilter(
|
||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
PorterDuff.Mode.SRC);
|
||||
mErrorColorFilter = new PorterDuffColorFilter(
|
||||
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
|
||||
|
||||
mDrawable = new BatteryMeterDrawable(context, frameColor);
|
||||
mDrawable.setShowPercent(false);
|
||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
||||
mDrawable.setWarningColorFilter(
|
||||
new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
|
||||
mDrawable.setColorFilter(mAccentColorFilter);
|
||||
setImageDrawable(mDrawable);
|
||||
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
|
||||
public void setBatteryLevel(int level) {
|
||||
mDrawable.setBatteryLevel(level);
|
||||
if (level < mDrawable.getCriticalLevel()) {
|
||||
mDrawable.setBatteryColorFilter(mErrorColorFilter);
|
||||
mDrawable.setColorFilter(mErrorColorFilter);
|
||||
} else {
|
||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
||||
mDrawable.setColorFilter(mAccentColorFilter);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPowerSave(boolean powerSave) {
|
||||
mDrawable.setPowerSave(powerSave);
|
||||
mDrawable.setPowerSaveEnabled(powerSave);
|
||||
mPowerSaveEnabled = powerSave;
|
||||
}
|
||||
|
||||
@@ -85,7 +83,7 @@ public class BatteryMeterView extends ImageView {
|
||||
}
|
||||
|
||||
public int getBatteryLevel() {
|
||||
return mDrawable.getBatteryLevel();
|
||||
return mDrawable.getLevel();
|
||||
}
|
||||
|
||||
public void setCharging(boolean charging) {
|
||||
@@ -97,7 +95,7 @@ public class BatteryMeterView extends ImageView {
|
||||
return mDrawable.getCharging();
|
||||
}
|
||||
|
||||
public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
|
||||
public static class BatteryMeterDrawable extends ThemedBatteryDrawable {
|
||||
private final int mIntrinsicWidth;
|
||||
private final int mIntrinsicHeight;
|
||||
|
||||
@@ -119,16 +117,5 @@ public class BatteryMeterView extends ImageView {
|
||||
public int getIntrinsicHeight() {
|
||||
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() {
|
||||
mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
|
||||
|
||||
verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
|
||||
verify(mDrawable).setColorFilter(mErrorColorFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetBatteryInfo_levelNormal_setNormalColor() {
|
||||
mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
|
||||
|
||||
verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
|
||||
verify(mDrawable).setColorFilter(mAccentColorFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user