Fix time zone formatting in RTL locales.
This fixes ar, fa, and he/iw. Bug: 10231161 Change-Id: I31acc044443c026ba8b8e1967810f7aa476bcae7
This commit is contained in:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user