Loading src/com/android/settings/DateTimeSettings.java +32 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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)); Loading Loading @@ -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() { Loading src/com/android/settings/ZonePicker.java +1 −3 Original line number Diff line number Diff line Loading @@ -229,7 +229,6 @@ public class ZonePicker extends ListFragment { 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) { Loading Loading @@ -270,7 +269,6 @@ public class ZonePicker extends ListFragment { 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" Loading @@ -289,7 +287,7 @@ public class ZonePicker extends ListFragment { 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); Loading Loading
src/com/android/settings/DateTimeSettings.java +32 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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)); Loading Loading @@ -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() { Loading
src/com/android/settings/ZonePicker.java +1 −3 Original line number Diff line number Diff line Loading @@ -229,7 +229,6 @@ public class ZonePicker extends ListFragment { 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) { Loading Loading @@ -270,7 +269,6 @@ public class ZonePicker extends ListFragment { 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" Loading @@ -289,7 +287,7 @@ public class ZonePicker extends ListFragment { 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); Loading