Make battery icon as red when battery level < 20%

Bug: 139457284
Test: manually
Change-Id: I235dd86975b3c867183ff845893c3ed95c847356
This commit is contained in:
hughchen
2019-10-03 15:40:58 +08:00
parent 616707f486
commit cf15f47ac7

View File

@@ -60,6 +60,7 @@ import java.util.Map;
public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceController implements public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceController implements
LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback { LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback {
private static final String TAG = "AdvancedBtHeaderCtrl"; private static final String TAG = "AdvancedBtHeaderCtrl";
private static final int LOW_BATTERY_LEVEL = 20;
@VisibleForTesting @VisibleForTesting
LayoutPreference mLayoutPreference; LayoutPreference mLayoutPreference;
@@ -182,9 +183,11 @@ 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);
final int attr = level > LOW_BATTERY_LEVEL || charging
? android.R.attr.colorControlNormal
: android.R.attr.colorError;
drawable.setColorFilter(new PorterDuffColorFilter( drawable.setColorFilter(new PorterDuffColorFilter(
com.android.settings.Utils.getColorAttrDefaultColor(context, com.android.settings.Utils.getColorAttrDefaultColor(context, attr),
android.R.attr.colorControlNormal),
PorterDuff.Mode.SRC_IN)); PorterDuff.Mode.SRC_IN));
drawable.setCharging(charging); drawable.setCharging(charging);