Match UX spec.
Change-Id: If1408458d488ac2ae3a63449e44ff18fc56e08d5
<!-- Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_minutes_no_seconds"><xliff:g id="minutes">%1$d</xliff:g>m</string>
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "d days" in BatteryHistory -->
- <string name="battery_history_days_only"><xliff:g id="days">%1$d</xliff:g>d</string>
-
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "d days, h hours" in BatteryHistory -->
- <string name="battery_history_days_and_hours"><xliff:g id="days">%1$d</xliff:g>d
- <xliff:g id="hours">%2$d</xliff:g>h</string>
-
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "h hours" in BatteryHistory -->
- <string name="battery_history_hours_only"><xliff:g id="hours">%1$d</xliff:g>h</string>
-
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "h hours, m minutes" in BatteryHistory -->
- <string name="battery_history_hours_and_minutes"><xliff:g id="hours">%1$d</xliff:g>h
- <xliff:g id="minutes">%2$d</xliff:g>m</string>
-
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "m minutes" in BatteryHistory -->
- <string name="battery_history_minutes_only"><xliff:g id="minutes">%1$d</xliff:g>m</string>
-
- <!-- [CHAR LIMIT=20] Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory -->
- <string name="battery_history_minutes_and_seconds"><xliff:g id="minutes">%1$d</xliff:g>m
- <xliff:g id="seconds">%2$d</xliff:g>s</string>
-
<!-- XXX remove? Strings used for displaying usage statistics -->
<string name="usage_stats_label">Usage statistics</string>
<string name="power_discharge_remaining"><xliff:g id="remain">%1$s</xliff:g> remaining</string>
<!-- Display time remaining until battery is charged [CHAR_LIMIT=60] -->
<string name="power_charge_remaining"><xliff:g id="until_charged">%1$s</xliff:g> to charge</string>
+ <!-- [CHAR_LIMIT=40] Label for battery level chart when discharging -->
+ <string name="power_discharging"><xliff:g id="level">%1$d</xliff:g>%%</string>
+ <!-- [CHAR_LIMIT=40] Label for battery level chart when discharging with duration -->
+ <string name="power_discharging_duration"><xliff:g id="level">%1$d</xliff:g>%%
+ - approx. <xliff:g id="time">%2$s</xliff:g> left</string>
+ <!-- [CHAR_LIMIT=40] Label for battery level chart when charging -->
+ <string name="power_charging"><xliff:g id="level">%1$d</xliff:g>%% -
+ <xliff:g id="state">%2$s</xliff:g></string>
+ <!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
+ <string name="power_charging_duration"><xliff:g id="level">%1$d</xliff:g>%% -
+ <xliff:g id="state">%2$s</xliff:g>
+ (<xliff:g id="time">%3$s</xliff:g> until full)</string>
<!-- Battery usage since unplugged -->
<string name="battery_since_unplugged">Battery use since unplugged</string>
<!-- Battery usage since user reset the stats -->
}
public static String getBatteryPercentage(Intent batteryChangedIntent) {
+ return String.valueOf(getBatteryLevel(batteryChangedIntent)) + "%";
+ }
+
+ public static int getBatteryLevel(Intent batteryChangedIntent) {
int level = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int scale = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
- return String.valueOf(level * 100 / scale) + "%";
+ return (level * 100) / scale;
}
public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) {
import android.content.Intent;
import android.os.BatteryManager;
+import android.text.format.Formatter;
import com.android.settings.R;
import android.content.Context;
//mDurationString = getContext().getString(R.string.battery_stats_on_battery,
// durationString);
mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
- mDrainString = com.android.settings.Utils.getBatteryPercentage(mBatteryBroadcast);
- mChargeLabelString = com.android.settings.Utils.getBatteryStatus(getResources(),
- mBatteryBroadcast);
- final long drainTime = mStats.computeBatteryTimeRemaining(elapsedRealtimeUs);
- final long chargeTime = mStats.computeChargeTimeRemaining(elapsedRealtimeUs);
+ int batteryLevel = com.android.settings.Utils.getBatteryLevel(mBatteryBroadcast);
final int status = mBatteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
- if (drainTime > 0) {
- String timeString = Utils.formatShortElapsedTime(getContext(),drainTime / 1000);
- mChargeDurationString = getContext().getResources().getString(
- R.string.power_discharge_remaining, timeString);
- } else if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
- String timeString = Utils.formatShortElapsedTime(getContext(), chargeTime / 1000);
- mChargeDurationString = getContext().getResources().getString(
- R.string.power_charge_remaining, timeString);
+ if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
+ final long drainTime = mStats.computeBatteryTimeRemaining(elapsedRealtimeUs);
+ if (drainTime > 0) {
+ String timeString = Formatter.formatShortElapsedTime(getContext(),
+ drainTime / 1000);
+ mChargeLabelString = getContext().getResources().getString(
+ R.string.power_discharging_duration, batteryLevel, timeString);
+ } else {
+ mChargeLabelString = getContext().getResources().getString(
+ R.string.power_discharging, batteryLevel);
+ }
} else {
- mChargeDurationString = "";
+ final long chargeTime = mStats.computeChargeTimeRemaining(elapsedRealtimeUs);
+ final String statusLabel = com.android.settings.Utils.getBatteryStatus(getResources(),
+ mBatteryBroadcast);
+ if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
+ String timeString = Formatter.formatShortElapsedTime(getContext(),
+ chargeTime / 1000);
+ mChargeLabelString = getContext().getResources().getString(
+ R.string.power_charging_duration, batteryLevel, statusLabel, timeString);
+ } else {
+ mChargeLabelString = getContext().getResources().getString(
+ R.string.power_charging, batteryLevel, statusLabel);
+ }
}
+ mDrainString = "";
+ mChargeDurationString = "";
}
@Override
}
return sb.toString();
}
-
- /**
- * Returns elapsed time for the given millis, in the following format:
- * 2d 5h; will include at most two units, can go down to seconds precision.
- * @param context the application context
- * @param millis the elapsed time in milli seconds
- * @return the formatted elapsed time
- */
- public static String formatShortElapsedTime(Context context, double millis) {
- int seconds = (int) Math.floor(millis / 1000);
-
- int days = 0, hours = 0, minutes = 0;
- if (seconds >= SECONDS_PER_DAY) {
- days = seconds / SECONDS_PER_DAY;
- seconds -= days * SECONDS_PER_DAY;
- }
- if (seconds >= SECONDS_PER_HOUR) {
- hours = seconds / SECONDS_PER_HOUR;
- seconds -= hours * SECONDS_PER_HOUR;
- }
- if (seconds >= SECONDS_PER_MINUTE) {
- minutes = seconds / SECONDS_PER_MINUTE;
- seconds -= minutes * SECONDS_PER_MINUTE;
- }
- if (days >= 4) {
- return context.getString(R.string.battery_history_days_only, days);
- } else if (days > 0) {
- return context.getString(R.string.battery_history_days_and_hours, days, hours);
- } else if (hours >= 12) {
- return context.getString(R.string.battery_history_hours_only, hours);
- } else if (hours > 0) {
- return context.getString(R.string.battery_history_hours_and_minutes, hours, minutes);
- } else if (minutes >= 10) {
- return context.getString(R.string.battery_history_minutes_only, minutes);
- } else if (minutes > 0) {
- return context.getString(R.string.battery_history_minutes_and_seconds, minutes,
- seconds);
- } else {
- return context.getString(R.string.battery_history_seconds, seconds);
- }
- }
}