am 10fdcab4
: Merge "Fix time zone formatting in RTL locales."
* commit '10fdcab4245ce1beeb75c36b36ccaa48bf8953f0': Fix time zone formatting in RTL locales.
This commit is contained in:
@@ -35,13 +35,18 @@ import android.preference.Preference;
|
|||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
|
import android.text.BidiFormatter;
|
||||||
|
import android.text.TextDirectionHeuristics;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class DateTimeSettings extends SettingsPreferenceFragment
|
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);
|
mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
|
||||||
Date dummyDate = mDummyDate.getTime();
|
Date dummyDate = mDummyDate.getTime();
|
||||||
mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.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()));
|
mDatePref.setSummary(shortDateFormat.format(now.getTime()));
|
||||||
mDateFormat.setSummary(shortDateFormat.format(dummyDate));
|
mDateFormat.setSummary(shortDateFormat.format(dummyDate));
|
||||||
mTime24Pref.setSummary(DateFormat.getTimeFormat(getActivity()).format(dummyDate));
|
mTime24Pref.setSummary(DateFormat.getTimeFormat(getActivity()).format(dummyDate));
|
||||||
@@ -373,10 +378,32 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTimeZoneText(TimeZone tz) {
|
public static String getTimeZoneText(TimeZone tz, boolean includeName) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("ZZZZ, zzzz");
|
Date now = new Date();
|
||||||
sdf.setTimeZone(tz);
|
|
||||||
return sdf.format(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() {
|
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||||
|
@@ -229,7 +229,6 @@ public class ZonePicker extends ListFragment {
|
|||||||
new ArrayList<HashMap<String, Object>>();
|
new ArrayList<HashMap<String, Object>>();
|
||||||
private final HashSet<String> mLocalZones = new HashSet<String>();
|
private final HashSet<String> mLocalZones = new HashSet<String>();
|
||||||
private final Date mNow = Calendar.getInstance().getTime();
|
private final Date mNow = Calendar.getInstance().getTime();
|
||||||
private final SimpleDateFormat mGmtFormatter = new SimpleDateFormat("ZZZZ");
|
|
||||||
private final SimpleDateFormat mZoneNameFormatter = new SimpleDateFormat("zzzz");
|
private final SimpleDateFormat mZoneNameFormatter = new SimpleDateFormat("zzzz");
|
||||||
|
|
||||||
private List<HashMap<String, Object>> getZones(Context context) {
|
private List<HashMap<String, Object>> getZones(Context context) {
|
||||||
@@ -270,7 +269,6 @@ public class ZonePicker extends ListFragment {
|
|||||||
private void addTimeZone(String olsonId) {
|
private void addTimeZone(String olsonId) {
|
||||||
// We always need the "GMT-07:00" string.
|
// We always need the "GMT-07:00" string.
|
||||||
final TimeZone tz = TimeZone.getTimeZone(olsonId);
|
final TimeZone tz = TimeZone.getTimeZone(olsonId);
|
||||||
mGmtFormatter.setTimeZone(tz);
|
|
||||||
|
|
||||||
// For the display name, we treat time zones within the country differently
|
// 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"
|
// from other countries' time zones. So in en_US you'd get "Pacific Daylight Time"
|
||||||
@@ -289,7 +287,7 @@ public class ZonePicker extends ListFragment {
|
|||||||
final HashMap<String, Object> map = new HashMap<String, Object>();
|
final HashMap<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put(KEY_ID, olsonId);
|
map.put(KEY_ID, olsonId);
|
||||||
map.put(KEY_DISPLAYNAME, displayName);
|
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()));
|
map.put(KEY_OFFSET, tz.getOffset(mNow.getTime()));
|
||||||
|
|
||||||
mZones.add(map);
|
mZones.add(map);
|
||||||
|
Reference in New Issue
Block a user