diff options
author | Elliott Hughes <enh@google.com> | 2013-09-18 15:04:25 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-09-18 15:07:43 -0700 |
commit | 04487594d73c89aa53548e6ad864e40d15324c62 (patch) | |
tree | 69fccfeeea8442b44b0df4119aef2fc9f085d56e /src/com/android/settings/DateTimeSettings.java | |
parent | caeb7a6e627a8326b3268a8ca588b7ea0d3d700c (diff) | |
download | packages_apps_Settings-04487594d73c89aa53548e6ad864e40d15324c62.zip packages_apps_Settings-04487594d73c89aa53548e6ad864e40d15324c62.tar.gz packages_apps_Settings-04487594d73c89aa53548e6ad864e40d15324c62.tar.bz2 |
Fix time zone formatting in RTL locales.
This fixes ar, fa, and he/iw.
Bug: 10231161
Change-Id: I31acc044443c026ba8b8e1967810f7aa476bcae7
Diffstat (limited to 'src/com/android/settings/DateTimeSettings.java')
-rw-r--r-- | src/com/android/settings/DateTimeSettings.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java index 6c6553b..f02f838 100644 --- a/src/com/android/settings/DateTimeSettings.java +++ b/src/com/android/settings/DateTimeSettings.java @@ -35,13 +35,18 @@ import android.preference.Preference; import android.preference.PreferenceScreen; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; +import android.text.TextUtils; import android.text.format.DateFormat; +import android.view.View; import android.widget.DatePicker; import android.widget.TimePicker; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; public class DateTimeSettings extends SettingsPreferenceFragment @@ -182,7 +187,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0); Date dummyDate = mDummyDate.getTime(); mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.getTime())); - mTimeZone.setSummary(getTimeZoneText(now.getTimeZone())); + mTimeZone.setSummary(getTimeZoneText(now.getTimeZone(), true)); mDatePref.setSummary(shortDateFormat.format(now.getTime())); mDateFormat.setSummary(shortDateFormat.format(dummyDate)); mTime24Pref.setSummary(DateFormat.getTimeFormat(getActivity()).format(dummyDate)); @@ -373,10 +378,32 @@ public class DateTimeSettings extends SettingsPreferenceFragment } } - private static String getTimeZoneText(TimeZone tz) { - SimpleDateFormat sdf = new SimpleDateFormat("ZZZZ, zzzz"); - sdf.setTimeZone(tz); - return sdf.format(new Date()); + public static String getTimeZoneText(TimeZone tz, boolean includeName) { + Date now = new Date(); + + // Use SimpleDateFormat to format the GMT+00:00 string. + SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ"); + gmtFormatter.setTimeZone(tz); + String gmtString = gmtFormatter.format(now); + + // Ensure that the "GMT+" stays with the "00:00" even if the digits are RTL. + BidiFormatter bidiFormatter = BidiFormatter.getInstance(); + Locale l = Locale.getDefault(); + boolean isRtl = TextUtils.getLayoutDirectionFromLocale(l) == View.LAYOUT_DIRECTION_RTL; + gmtString = bidiFormatter.unicodeWrap(gmtString, + isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR); + + if (!includeName) { + return gmtString; + } + + // Optionally append the time zone name. + SimpleDateFormat zoneNameFormatter = new SimpleDateFormat("zzzz"); + zoneNameFormatter.setTimeZone(tz); + String zoneNameString = zoneNameFormatter.format(now); + + // We don't use punctuation here to avoid having to worry about localizing that too! + return gmtString + " " + zoneNameString; } private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |