use of libcore.icu.LocaleData in project android_frameworks_base by ParanoidAndroid.
the class DateFormat method format.
/**
* Given a format string and a {@link java.util.Calendar} object, returns a CharSequence
* containing the requested date.
* @param inFormat the format string, as described in {@link android.text.format.DateFormat}
* @param inDate the date to format
* @return a {@link CharSequence} containing the requested text
*/
public static CharSequence format(CharSequence inFormat, Calendar inDate) {
SpannableStringBuilder s = new SpannableStringBuilder(inFormat);
int count;
LocaleData localeData = LocaleData.get(Locale.getDefault());
int len = inFormat.length();
for (int i = 0; i < len; i += count) {
count = 1;
int c = s.charAt(i);
if (c == QUOTE) {
count = appendQuotedText(s, i, len);
len = s.length();
continue;
}
while ((i + count < len) && (s.charAt(i + count) == c)) {
count++;
}
String replacement;
switch(c) {
case 'A':
case 'a':
replacement = localeData.amPm[inDate.get(Calendar.AM_PM) - Calendar.AM];
break;
case 'd':
replacement = zeroPad(inDate.get(Calendar.DATE), count);
break;
case 'c':
case 'E':
replacement = getDayOfWeekString(localeData, inDate.get(Calendar.DAY_OF_WEEK), count, c);
break;
// hour in am/pm (0-11)
case 'K':
case // hour in am/pm (1-12)
'h':
{
int hour = inDate.get(Calendar.HOUR);
if (c == 'h' && hour == 0) {
hour = 12;
}
replacement = zeroPad(hour, count);
}
break;
// hour in day (0-23)
case 'H':
case // hour in day (1-24) [but see note below]
'k':
{
int hour = inDate.get(Calendar.HOUR_OF_DAY);
// times are abusing 'k'. http://b/8359981.
if (false && c == 'k' && hour == 0) {
hour = 24;
}
replacement = zeroPad(hour, count);
}
break;
case 'L':
case 'M':
replacement = getMonthString(localeData, inDate.get(Calendar.MONTH), count, c);
break;
case 'm':
replacement = zeroPad(inDate.get(Calendar.MINUTE), count);
break;
case 's':
replacement = zeroPad(inDate.get(Calendar.SECOND), count);
break;
case 'y':
replacement = getYearString(inDate.get(Calendar.YEAR), count);
break;
case 'z':
replacement = getTimeZoneString(inDate, count);
break;
default:
replacement = null;
break;
}
if (replacement != null) {
s.replace(i, i + count, replacement);
// CARE: count is used in the for loop above
count = replacement.length();
len = s.length();
}
}
if (inFormat instanceof Spanned) {
return new SpannedString(s);
} else {
return s.toString();
}
}
use of libcore.icu.LocaleData in project android_frameworks_base by ParanoidAndroid.
the class Time method format.
/**
* Print the current value given the format string provided. See man
* strftime for what means what. The final string must be less than 256
* characters.
* @param format a string containing the desired format.
* @return a String containing the current time expressed in the current locale.
*/
public String format(String format) {
synchronized (Time.class) {
Locale locale = Locale.getDefault();
if (sLocale == null || locale == null || !(locale.equals(sLocale))) {
LocaleData localeData = LocaleData.get(locale);
sAm = localeData.amPm[0];
sPm = localeData.amPm[1];
sZeroDigit = localeData.zeroDigit;
sShortMonths = localeData.shortMonthNames;
sLongMonths = localeData.longMonthNames;
sLongStandaloneMonths = localeData.longStandAloneMonthNames;
sShortWeekdays = localeData.shortWeekdayNames;
sLongWeekdays = localeData.longWeekdayNames;
Resources r = Resources.getSystem();
sTimeOnlyFormat = r.getString(com.android.internal.R.string.time_of_day);
sDateOnlyFormat = r.getString(com.android.internal.R.string.month_day_year);
sDateTimeFormat = r.getString(com.android.internal.R.string.date_and_time);
sLocale = locale;
}
String result = format1(format);
if (sZeroDigit != '0') {
result = localizeDigits(result);
}
return result;
}
}
use of libcore.icu.LocaleData in project android_frameworks_base by ParanoidAndroid.
the class TextClock method init.
private void init() {
if (mFormat12 == null || mFormat24 == null) {
LocaleData ld = LocaleData.get(getContext().getResources().getConfiguration().locale);
if (mFormat12 == null) {
mFormat12 = ld.timeFormat12;
}
if (mFormat24 == null) {
mFormat24 = ld.timeFormat24;
}
}
createTime(mTimeZone);
// Wait until onAttachedToWindow() to handle the ticker
chooseFormat(false);
}
use of libcore.icu.LocaleData in project android_frameworks_base by ParanoidAndroid.
the class TextClock method chooseFormat.
/**
* Selects either one of {@link #getFormat12Hour()} or {@link #getFormat24Hour()}
* depending on whether the user has selected 24-hour format.
*
* @param handleTicker true if calling this method should schedule/unschedule the
* time ticker, false otherwise
*/
private void chooseFormat(boolean handleTicker) {
final boolean format24Requested = is24HourModeEnabled();
LocaleData ld = LocaleData.get(getContext().getResources().getConfiguration().locale);
if (format24Requested) {
mFormat = abc(mFormat24, mFormat12, ld.timeFormat24);
} else {
mFormat = abc(mFormat12, mFormat24, ld.timeFormat12);
}
boolean hadSeconds = mHasSeconds;
mHasSeconds = DateFormat.hasSeconds(mFormat);
if (handleTicker && mAttached && hadSeconds != mHasSeconds) {
if (hadSeconds)
getHandler().removeCallbacks(mTicker);
else
mTicker.run();
}
}
use of libcore.icu.LocaleData in project android_frameworks_base by AOSPA.
the class DateUtils method getMonthString.
/**
* Return a localized string for the month of the year.
* @param month One of {@link Calendar#JANUARY Calendar.JANUARY},
* {@link Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
* @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_MEDIUM},
* or {@link #LENGTH_SHORTEST}.
* Undefined lengths will return {@link #LENGTH_MEDIUM}
* but may return something different in the future.
* @return Localized month of the year.
* @deprecated Use {@link java.text.SimpleDateFormat} instead.
*/
@Deprecated
public static String getMonthString(int month, int abbrev) {
LocaleData d = LocaleData.get(Locale.getDefault());
String[] names;
switch(abbrev) {
case LENGTH_LONG:
names = d.longMonthNames;
break;
case LENGTH_MEDIUM:
names = d.shortMonthNames;
break;
case LENGTH_SHORT:
names = d.shortMonthNames;
break;
case LENGTH_SHORTER:
names = d.shortMonthNames;
break;
case LENGTH_SHORTEST:
names = d.tinyMonthNames;
break;
default:
names = d.shortMonthNames;
break;
}
return names[month];
}
Aggregations