Update battery charge/drain label.
Match UX spec. Change-Id: If1408458d488ac2ae3a63449e44ff18fc56e08d5
This commit is contained in:
@@ -3279,27 +3279,6 @@
|
|||||||
<!-- Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory -->
|
<!-- 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>
|
<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 -->
|
<!-- XXX remove? Strings used for displaying usage statistics -->
|
||||||
<string name="usage_stats_label">Usage statistics</string>
|
<string name="usage_stats_label">Usage statistics</string>
|
||||||
|
|
||||||
@@ -3590,6 +3569,18 @@
|
|||||||
<string name="power_discharge_remaining"><xliff:g id="remain">%1$s</xliff:g> remaining</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] -->
|
<!-- 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>
|
<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 -->
|
<!-- Battery usage since unplugged -->
|
||||||
<string name="battery_since_unplugged">Battery use since unplugged</string>
|
<string name="battery_since_unplugged">Battery use since unplugged</string>
|
||||||
<!-- Battery usage since user reset the stats -->
|
<!-- Battery usage since user reset the stats -->
|
||||||
|
@@ -444,9 +444,13 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getBatteryPercentage(Intent batteryChangedIntent) {
|
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 level = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||||
int scale = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
|
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) {
|
public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) {
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
|
import android.text.format.Formatter;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -413,24 +414,36 @@ public class BatteryHistoryChart extends View {
|
|||||||
//mDurationString = getContext().getString(R.string.battery_stats_on_battery,
|
//mDurationString = getContext().getString(R.string.battery_stats_on_battery,
|
||||||
// durationString);
|
// durationString);
|
||||||
mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
|
mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
|
||||||
mDrainString = com.android.settings.Utils.getBatteryPercentage(mBatteryBroadcast);
|
int batteryLevel = com.android.settings.Utils.getBatteryLevel(mBatteryBroadcast);
|
||||||
mChargeLabelString = com.android.settings.Utils.getBatteryStatus(getResources(),
|
|
||||||
mBatteryBroadcast);
|
|
||||||
final long drainTime = mStats.computeBatteryTimeRemaining(elapsedRealtimeUs);
|
|
||||||
final long chargeTime = mStats.computeChargeTimeRemaining(elapsedRealtimeUs);
|
|
||||||
final int status = mBatteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
|
final int status = mBatteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
|
||||||
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
||||||
if (drainTime > 0) {
|
if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
|
||||||
String timeString = Utils.formatShortElapsedTime(getContext(),drainTime / 1000);
|
final long drainTime = mStats.computeBatteryTimeRemaining(elapsedRealtimeUs);
|
||||||
mChargeDurationString = getContext().getResources().getString(
|
if (drainTime > 0) {
|
||||||
R.string.power_discharge_remaining, timeString);
|
String timeString = Formatter.formatShortElapsedTime(getContext(),
|
||||||
} else if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
drainTime / 1000);
|
||||||
String timeString = Utils.formatShortElapsedTime(getContext(), chargeTime / 1000);
|
mChargeLabelString = getContext().getResources().getString(
|
||||||
mChargeDurationString = getContext().getResources().getString(
|
R.string.power_discharging_duration, batteryLevel, timeString);
|
||||||
R.string.power_charge_remaining, timeString);
|
} else {
|
||||||
|
mChargeLabelString = getContext().getResources().getString(
|
||||||
|
R.string.power_discharging, batteryLevel);
|
||||||
|
}
|
||||||
} else {
|
} 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
|
@Override
|
||||||
|
@@ -81,45 +81,4 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user