From 0c48689b088b6379ae2ffa0e3c884b1349e8b8af Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 11 Oct 2013 16:21:45 -0700 Subject: [PATCH] Enable time format localization in keyguard Fixes bug 11173871 Change-Id: Ife44c93b01770a3349343d034fe6adb1c6d66185 --- .../Keyguard/res/values/donottranslate.xml | 8 +++++- .../android/keyguard/KeyguardStatusView.java | 28 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/Keyguard/res/values/donottranslate.xml b/packages/Keyguard/res/values/donottranslate.xml index 5ee226b78115a..16f5a3e77c3ef 100644 --- a/packages/Keyguard/res/values/donottranslate.xml +++ b/packages/Keyguard/res/values/donottranslate.xml @@ -15,6 +15,12 @@ --> - + EEEMMMMd + + + hm + + + Hm diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java index 57fd82ce901f6..d93327526f656 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java @@ -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(); }