Loading src/com/android/settings/fuelgauge/BatteryMeterView.java +20 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.settings.fuelgauge; import android.annotation.Nullable; import android.content.Context; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; Loading @@ -38,7 +37,8 @@ public class BatteryMeterView extends ImageView { ColorFilter mErrorColorFilter; @VisibleForTesting ColorFilter mAccentColorFilter; private boolean mPowerSaveEnabled; @VisibleForTesting ColorFilter mForegroundColorFilter; public BatteryMeterView(Context context) { this(context, null, 0); Loading @@ -57,7 +57,9 @@ public class BatteryMeterView extends ImageView { PorterDuff.Mode.SRC); mErrorColorFilter = new PorterDuffColorFilter( context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN); mForegroundColorFilter =new PorterDuffColorFilter( Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground), PorterDuff.Mode.SRC); mDrawable = new BatteryMeterDrawable(context, frameColor); mDrawable.setColorFilter(mAccentColorFilter); setImageDrawable(mDrawable); Loading @@ -65,20 +67,16 @@ public class BatteryMeterView extends ImageView { public void setBatteryLevel(int level) { mDrawable.setBatteryLevel(level); if (level < mDrawable.getCriticalLevel()) { mDrawable.setColorFilter(mErrorColorFilter); } else { mDrawable.setColorFilter(mAccentColorFilter); } updateColorFilter(); } public void setPowerSave(boolean powerSave) { mDrawable.setPowerSaveEnabled(powerSave); mPowerSaveEnabled = powerSave; updateColorFilter(); } public boolean getPowerSave() { return mPowerSaveEnabled; return mDrawable.getPowerSaveEnabled(); } public int getBatteryLevel() { Loading @@ -94,6 +92,18 @@ public class BatteryMeterView extends ImageView { return mDrawable.getCharging(); } private void updateColorFilter() { final boolean powerSaveEnabled = mDrawable.getPowerSaveEnabled(); final int level = mDrawable.getBatteryLevel(); if (powerSaveEnabled) { mDrawable.setColorFilter(mForegroundColorFilter); } else if (level < mDrawable.getCriticalLevel()) { mDrawable.setColorFilter(mErrorColorFilter); } else { mDrawable.setColorFilter(mAccentColorFilter); } } public static class BatteryMeterDrawable extends ThemedBatteryDrawable { private final int mIntrinsicWidth; private final int mIntrinsicHeight; Loading tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ public class BatteryMeterViewTest { private ColorFilter mErrorColorFilter; @Mock private ColorFilter mAccentColorFilter; @Mock private ColorFilter mForegroundColorFilter; private Context mContext; private BatteryMeterView mBatteryMeterView; private BatteryMeterView.BatteryMeterDrawable mDrawable; Loading @@ -58,6 +60,7 @@ public class BatteryMeterViewTest { mBatteryMeterView.mDrawable = mDrawable; mBatteryMeterView.mAccentColorFilter = mAccentColorFilter; mBatteryMeterView.mErrorColorFilter = mErrorColorFilter; mBatteryMeterView.mForegroundColorFilter = mForegroundColorFilter; when(mDrawable.getCriticalLevel()).thenReturn(BATTERY_CRITICAL_LEVEL); } Loading Loading @@ -88,5 +91,6 @@ public class BatteryMeterViewTest { mBatteryMeterView.setPowerSave(true); assertThat(mBatteryMeterView.getPowerSave()).isEqualTo(true); verify(mDrawable).setColorFilter(mForegroundColorFilter); } } Loading
src/com/android/settings/fuelgauge/BatteryMeterView.java +20 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.settings.fuelgauge; import android.annotation.Nullable; import android.content.Context; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; Loading @@ -38,7 +37,8 @@ public class BatteryMeterView extends ImageView { ColorFilter mErrorColorFilter; @VisibleForTesting ColorFilter mAccentColorFilter; private boolean mPowerSaveEnabled; @VisibleForTesting ColorFilter mForegroundColorFilter; public BatteryMeterView(Context context) { this(context, null, 0); Loading @@ -57,7 +57,9 @@ public class BatteryMeterView extends ImageView { PorterDuff.Mode.SRC); mErrorColorFilter = new PorterDuffColorFilter( context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN); mForegroundColorFilter =new PorterDuffColorFilter( Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground), PorterDuff.Mode.SRC); mDrawable = new BatteryMeterDrawable(context, frameColor); mDrawable.setColorFilter(mAccentColorFilter); setImageDrawable(mDrawable); Loading @@ -65,20 +67,16 @@ public class BatteryMeterView extends ImageView { public void setBatteryLevel(int level) { mDrawable.setBatteryLevel(level); if (level < mDrawable.getCriticalLevel()) { mDrawable.setColorFilter(mErrorColorFilter); } else { mDrawable.setColorFilter(mAccentColorFilter); } updateColorFilter(); } public void setPowerSave(boolean powerSave) { mDrawable.setPowerSaveEnabled(powerSave); mPowerSaveEnabled = powerSave; updateColorFilter(); } public boolean getPowerSave() { return mPowerSaveEnabled; return mDrawable.getPowerSaveEnabled(); } public int getBatteryLevel() { Loading @@ -94,6 +92,18 @@ public class BatteryMeterView extends ImageView { return mDrawable.getCharging(); } private void updateColorFilter() { final boolean powerSaveEnabled = mDrawable.getPowerSaveEnabled(); final int level = mDrawable.getBatteryLevel(); if (powerSaveEnabled) { mDrawable.setColorFilter(mForegroundColorFilter); } else if (level < mDrawable.getCriticalLevel()) { mDrawable.setColorFilter(mErrorColorFilter); } else { mDrawable.setColorFilter(mAccentColorFilter); } } public static class BatteryMeterDrawable extends ThemedBatteryDrawable { private final int mIntrinsicWidth; private final int mIntrinsicHeight; Loading
tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ public class BatteryMeterViewTest { private ColorFilter mErrorColorFilter; @Mock private ColorFilter mAccentColorFilter; @Mock private ColorFilter mForegroundColorFilter; private Context mContext; private BatteryMeterView mBatteryMeterView; private BatteryMeterView.BatteryMeterDrawable mDrawable; Loading @@ -58,6 +60,7 @@ public class BatteryMeterViewTest { mBatteryMeterView.mDrawable = mDrawable; mBatteryMeterView.mAccentColorFilter = mAccentColorFilter; mBatteryMeterView.mErrorColorFilter = mErrorColorFilter; mBatteryMeterView.mForegroundColorFilter = mForegroundColorFilter; when(mDrawable.getCriticalLevel()).thenReturn(BATTERY_CRITICAL_LEVEL); } Loading Loading @@ -88,5 +91,6 @@ public class BatteryMeterViewTest { mBatteryMeterView.setPowerSave(true); assertThat(mBatteryMeterView.getPowerSave()).isEqualTo(true); verify(mDrawable).setColorFilter(mForegroundColorFilter); } }