am dc70340d: Merge "Enable time format localization in keyguard" into klp-dev

* commit 'dc70340d48eeddf4aa92a4d199179cde269c5bd4':
  Enable time format localization in keyguard
This commit is contained in:
Jim Miller
2013-10-11 18:08:00 -07:00
committed by Android Git Automerger
2 changed files with 31 additions and 5 deletions

View File

@ -15,6 +15,12 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- String matching the lock screen format for displaying the date. -->
<!-- Skeleton string format for displaying the date. -->
<string name="abbrev_wday_month_day_no_year">EEEMMMMd</string>
<!-- Skeleton string format for displaying the time in 12-hour format. -->
<string name="clock_12hr_format">hm</string>
<!-- Skeleton string format for displaying the time in 24-hour format. -->
<string name="clock_24hr_format">Hm</string>
</resources>

View File

@ -17,6 +17,7 @@
package com.android.keyguard;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.AttributeSet;
@ -39,6 +40,7 @@ public class KeyguardStatusView extends GridLayout {
private TextView mAlarmStatusView;
private TextClock mDateView;
private TextClock mClockView;
private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
@ -88,6 +90,7 @@ public class KeyguardStatusView extends GridLayout {
super.onFinishInflate();
mAlarmStatusView = (TextView) findViewById(R.id.alarm_status);
mDateView = (TextClock) findViewById(R.id.date_view);
mClockView = (TextClock) findViewById(R.id.clock_view);
mLockPatternUtils = new LockPatternUtils(getContext());
final boolean screenOn = KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
setEnableMarquee(screenOn);
@ -95,10 +98,27 @@ public class KeyguardStatusView extends GridLayout {
}
protected void refresh() {
final String fmt = DateFormat.getBestDateTimePattern(Locale.getDefault(),
mContext.getResources().getString(R.string.abbrev_wday_month_day_no_year));
mDateView.setFormat24Hour(fmt);
mDateView.setFormat12Hour(fmt);
Resources res = mContext.getResources();
Locale locale = Locale.getDefault();
final String dateFormat = DateFormat.getBestDateTimePattern(locale,
res.getString(R.string.abbrev_wday_month_day_no_year));
mDateView.setFormat24Hour(dateFormat);
mDateView.setFormat12Hour(dateFormat);
// 12-hour clock.
// CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton
// format. The following code removes the AM/PM indicator if we didn't want it.
final String clock12skel = res.getString(R.string.clock_12hr_format);
String clock12hr = DateFormat.getBestDateTimePattern(locale, clock12skel);
clock12hr = clock12skel.contains("a") ? clock12hr : clock12hr.replaceAll("a", "").trim();
mClockView.setFormat12Hour(clock12hr);
// 24-hour clock
final String clock24skel = res.getString(R.string.clock_24hr_format);
final String clock24hr = DateFormat.getBestDateTimePattern(locale, clock24skel);
mClockView.setFormat24Hour(clock24hr);
refreshAlarmStatus();
}