diff options
| author | Elliott Hughes <enh@google.com> | 2012-09-18 15:16:00 -0700 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2012-09-18 15:16:00 -0700 |
| commit | 6323b6c61775992e400c2d38981332583107c32b (patch) | |
| tree | 151d4c87f060ccef5118fb1b5909d776862af79e /core/java | |
| parent | 315a7c0335fb54beced23b1703c10563ce02ee82 (diff) | |
| download | frameworks_base-6323b6c61775992e400c2d38981332583107c32b.zip frameworks_base-6323b6c61775992e400c2d38981332583107c32b.tar.gz frameworks_base-6323b6c61775992e400c2d38981332583107c32b.tar.bz2 | |
Use localized digits for Time formatting.
This fixes the digits in places like Settings' data usage page
and Calendar's drop-down, for languages such as Arabic.
Bug: 6811327
Change-Id: I2dafcc342e3279937735697b3748b47fdfc8e691
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/text/format/Time.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/java/android/text/format/Time.java b/core/java/android/text/format/Time.java index e2de8f2..5ef86b1 100644 --- a/core/java/android/text/format/Time.java +++ b/core/java/android/text/format/Time.java @@ -151,6 +151,7 @@ public class Time { private static String sDateTimeFormat; private static String sAm; private static String sPm; + private static char sZeroDigit; // Referenced by native code. private static String sDateCommand = "%a %b %e %H:%M:%S %Z %Y"; @@ -325,6 +326,7 @@ public class Time { sAm = localeData.amPm[0]; sPm = localeData.amPm[1]; + sZeroDigit = localeData.zeroDigit; sShortMonths = localeData.shortMonthNames; sLongMonths = localeData.longMonthNames; @@ -340,12 +342,32 @@ public class Time { sLocale = locale; } - return format1(format); + String result = format1(format); + if (sZeroDigit != '0') { + result = localizeDigits(result); + } + return result; } } native private String format1(String format); + // TODO: unify this with java.util.Formatter's copy. + private String localizeDigits(String s) { + int length = s.length(); + int offsetToLocalizedDigits = sZeroDigit - '0'; + StringBuilder result = new StringBuilder(length); + for (int i = 0; i < length; ++i) { + char ch = s.charAt(i); + if (ch >= '0' && ch <= '9') { + ch += offsetToLocalizedDigits; + } + result.append(ch); + } + return result.toString(); + } + + /** * Return the current time in YYYYMMDDTHHMMSS<tz> format */ |
