Merge "Fix time zone formatting in RTL locales."
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.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 @@
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 @@
}
}
- 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() {
diff --git a/src/com/android/settings/ZonePicker.java b/src/com/android/settings/ZonePicker.java
index 0a82383..2019954 100644
--- a/src/com/android/settings/ZonePicker.java
+++ b/src/com/android/settings/ZonePicker.java
@@ -229,7 +229,6 @@
new ArrayList<HashMap<String, Object>>();
private final HashSet<String> mLocalZones = new HashSet<String>();
private final Date mNow = Calendar.getInstance().getTime();
- private final SimpleDateFormat mGmtFormatter = new SimpleDateFormat("ZZZZ");
private final SimpleDateFormat mZoneNameFormatter = new SimpleDateFormat("zzzz");
private List<HashMap<String, Object>> getZones(Context context) {
@@ -270,7 +269,6 @@
private void addTimeZone(String olsonId) {
// We always need the "GMT-07:00" string.
final TimeZone tz = TimeZone.getTimeZone(olsonId);
- mGmtFormatter.setTimeZone(tz);
// For the display name, we treat time zones within the country differently
// from other countries' time zones. So in en_US you'd get "Pacific Daylight Time"
@@ -289,7 +287,7 @@
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put(KEY_ID, olsonId);
map.put(KEY_DISPLAYNAME, displayName);
- map.put(KEY_GMT, mGmtFormatter.format(mNow));
+ map.put(KEY_GMT, DateTimeSettings.getTimeZoneText(tz, false));
map.put(KEY_OFFSET, tz.getOffset(mNow.getTime()));
mZones.add(map);