Update battery dashboard based on spec

Following CL will change "battery suggestion" to card layout.

Bug: 119618813
Test: Screenshot
Change-Id: If71e5c0e4a4e230358aa0c8aa584028082f31d2e
This commit is contained in:
jackqdyulei
2019-01-02 15:22:55 -08:00
parent 0057e45e6f
commit fd0f48df86
4 changed files with 25 additions and 16 deletions

View File

@@ -21,8 +21,10 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.icu.text.NumberFormat;
import android.os.BatteryManager;
import android.os.PowerManager;
import android.text.TextUtils;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -83,7 +85,7 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mBatteryLayoutPref = (LayoutPreference) screen.findPreference(getPreferenceKey());
mBatteryLayoutPref = screen.findPreference(getPreferenceKey());
mBatteryMeterView = mBatteryLayoutPref
.findViewById(R.id.battery_header_icon);
mBatteryPercentText = mBatteryLayoutPref.findViewById(R.id.battery_percent);
@@ -107,7 +109,7 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
}
public void updateHeaderPreference(BatteryInfo info) {
mBatteryPercentText.setText(Utils.formatPercentage(info.batteryLevel));
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
if (info.remainingLabel == null) {
mSummary1.setText(info.statusLabel);
} else {
@@ -133,6 +135,11 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
mBatteryMeterView.setBatteryLevel(batteryLevel);
mBatteryMeterView.setCharging(!discharging);
mBatteryMeterView.setPowerSave(mPowerManager.isPowerSaveMode());
mBatteryPercentText.setText(Utils.formatPercentage(batteryLevel));
mBatteryPercentText.setText(formatBatteryPercentageText(batteryLevel));
}
private CharSequence formatBatteryPercentageText(int batteryLevel) {
return TextUtils.expandTemplate(mContext.getText(R.string.battery_header_title_alternate),
NumberFormat.getIntegerInstance().format(batteryLevel));
}
}