summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2014-06-10 20:20:52 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2014-06-10 20:26:42 -0700
commita7a62c5b66189f114a8ad41c53bbe0bb00ae1e90 (patch)
treeac173ba22e4517549327f92f9ed1f6c7cee508ca
parentda8babaedf45caf55eb77320f0c3ea873d195c4d (diff)
downloadpackages_apps_Settings-a7a62c5b66189f114a8ad41c53bbe0bb00ae1e90.tar.gz
packages_apps_Settings-a7a62c5b66189f114a8ad41c53bbe0bb00ae1e90.tar.bz2
packages_apps_Settings-a7a62c5b66189f114a8ad41c53bbe0bb00ae1e90.zip
Fix bug #15545573 Battery use chart is incorrect for date labels and time axis labels
- use DateFormat.getBestDateTimePattern(...) to get the best Date and Time format depending on the Locale - format the label according to the best format - remove non needed formatting strings Change-Id: I78b62b9a7c9401e47e62c7161214636bb43324fc
-rw-r--r--res/values/strings.xml10
-rw-r--r--src/com/android/settings/fuelgauge/BatteryHistoryChart.java36
2 files changed, 11 insertions, 35 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fd25212f9..d5cb89a75 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3565,16 +3565,6 @@
<string name="battery_stats_phone_signal_label">Mobile network signal</string>
<!-- Battery usage during last unplugged period -->
<string name="battery_stats_last_duration">@string/menu_stats_last_unplugged</string>
- <!-- [CHAR_LIMIT=5] Label for an hour time when using 24 hour mode -->
- <string name="battery_stats_hour_24_label"><xliff:g id="time">%1$d</xliff:g>:00</string>
- <!-- [CHAR_LIMIT=5] Label for an hour time when using 12 hour mode in the AM -->
- <string name="battery_stats_hour_am_label"><xliff:g id="time">%1$d</xliff:g> AM</string>
- <!-- [CHAR_LIMIT=5] Label for an hour time when using 12 hour mode in the PM -->
- <string name="battery_stats_hour_pm_label"><xliff:g id="time">%1$d</xliff:g> PM</string>
- <!-- [CHAR_LIMIT=3] Label for date of day and month (not year) when the day is shown first -->
- <string name="battery_stats_date_day_first_label"><xliff:g id="day">%1$d</xliff:g>/<xliff:g id="month">%2$d</xliff:g></string>
- <!-- [CHAR_LIMIT=3] Label for date of day and month (not year) when the month is shown first -->
- <string name="battery_stats_date_month_first_label"><xliff:g id="month">%2$d</xliff:g>/<xliff:g id="day">%1$d</xliff:g></string>
<!-- CPU awake time title -->
<string name="awake">Device awake time</string>
<!-- Wifi on time -->
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index 4c6a503c7..04f405084 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -45,6 +45,7 @@ import libcore.icu.LocaleData;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Locale;
public class BatteryHistoryChart extends View {
static final boolean DEBUG = false;
@@ -315,22 +316,11 @@ public class BatteryHistoryChart extends View {
final String label;
final int width;
- TimeLabel(Context context, TextPaint paint, int x, Calendar cal, boolean use24hr) {
+ TimeLabel(TextPaint paint, int x, Calendar cal, boolean use24hr) {
this.x = x;
- if (use24hr) {
- label = context.getString(R.string.battery_stats_hour_24_label,
- cal.get(Calendar.HOUR_OF_DAY));
- } else {
- int hour = cal.get(Calendar.HOUR);
- if (hour == 0) {
- hour = 12;
- }
- if (cal.get(Calendar.AM_PM) == Calendar.AM) {
- label = context.getString(R.string.battery_stats_hour_am_label, hour);
- } else {
- label = context.getString(R.string.battery_stats_hour_pm_label, hour);
- }
- }
+ final String bestFormat = DateFormat.getBestDateTimePattern(
+ Locale.getDefault(), use24hr ? "km" : "ha");
+ label = DateFormat.format(bestFormat, cal).toString();
width = (int)paint.measureText(label);
}
}
@@ -340,15 +330,11 @@ public class BatteryHistoryChart extends View {
final String label;
final int width;
- DateLabel(Context context, TextPaint paint, int x, Calendar cal, boolean dayFirst) {
+ DateLabel(TextPaint paint, int x, Calendar cal, boolean dayFirst) {
this.x = x;
- if (dayFirst) {
- label = context.getString(R.string.battery_stats_date_day_first_label,
- cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH));
- } else {
- label = context.getString(R.string.battery_stats_date_month_first_label,
- cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH));
- }
+ final String bestFormat = DateFormat.getBestDateTimePattern(
+ Locale.getDefault(), dayFirst ? "dM" : "Md");
+ label = DateFormat.format(bestFormat, cal).toString();
width = (int)paint.measureText(label);
}
}
@@ -1033,7 +1019,7 @@ public class BatteryHistoryChart extends View {
void addTimeLabel(Calendar cal, int levelLeft, int levelRight, boolean is24hr) {
final long walltimeStart = mStartWallTime;
final long walltimeChange = mEndWallTime-walltimeStart;
- mTimeLabels.add(new TimeLabel(getContext(), mTextPaint,
+ mTimeLabels.add(new TimeLabel(mTextPaint,
levelLeft + (int)(((cal.getTimeInMillis()-walltimeStart)*(levelRight-levelLeft))
/ walltimeChange),
cal, is24hr));
@@ -1042,7 +1028,7 @@ public class BatteryHistoryChart extends View {
void addDateLabel(Calendar cal, int levelLeft, int levelRight, boolean isDayFirst) {
final long walltimeStart = mStartWallTime;
final long walltimeChange = mEndWallTime-walltimeStart;
- mDateLabels.add(new DateLabel(getContext(), mTextPaint,
+ mDateLabels.add(new DateLabel(mTextPaint,
levelLeft + (int)(((cal.getTimeInMillis()-walltimeStart)*(levelRight-levelLeft))
/ walltimeChange),
cal, isDayFirst));