一、問題現象
1、設定-日期&時間-選擇日期格式-選擇第一個Regional(12.31.16),鎖屏界面日期顯示異常。
2、點選Settings-Backup&reset-Device Reset後鎖屏界面日期顯示異常。
二、問題分析
Date & time-Choose date format選項是通過device/tct/idol4/perso/plf/frameworks/base/core/res/isdm_framework-res.splf中SDM值def_tctfw_SystemUI_Date_format_same_with_setting定制生效的,具體配置在DateTimeSettings.java中,
鎖屏界面日期是通過TextClock.java 中的onTimeChanged方法中設定的:
private void onTimeChanged() {
mTime.setTimeInMillis(System.currentTimeMillis());
setText(DateFormat.format(mFormat, mTime));//此處設定
setContentDescription(DateFormat.format(mDescFormat, mTime));
}
DateTimeSettings.java
//Defect1061782-yongjie.xiao begin
Log.d(TAG, "def_tctfw_SystemUI_Date_format_same_with_setting =
" + showChooseDateFormat);
System.out.println("ran.zhou-DTS-L216-showChooseDateFormat = "
+ showChooseDateFormat);
if (!showChooseDateFormat) {
getPreferenceScreen().removePreference(mDateFormat);
return;
}
String [] dateFormats =
getResources().getStringArray(R.array.date_format_values);
String [] formattedDates = new String[dateFormats.length];
String currentFormat = getDateFormat();
System.out.println("ran.zhou-DTS-L224-currentFormat = " +
currentFormat);
Log.i(TAG, "initUI currentFormat=" + currentFormat);
// Initialize if DATE_FORMAT is not set in the system settings
// This can happen after a factory reset (or data wipe)
if (currentFormat == null) {
currentFormat = "";
}
currentFormat = currentFormat.replace("-", ".").replace("/", ".");;
mDummyDate.set(mDummyDate.get(Calendar.YEAR),
mDummyDate.DECEMBER, 31, 13, 0, 0);
java.text.DateFormat shortDateFormat =
DateFormat.getDateFormat(getActivity());
String formatted;
for (int i = 0; i < formattedDates.length; i++) {
if (i == 0) {
formatted = shortDateFormat.format(mDummyDate.getTime());
formatted = formatted.replace("/", ".");
formattedDates[i] = getResources()
.getString(R.string.normal_date_format, formatted);
System.out.println("ran.zhou-DTS-L240-formattedDates[" + i + "] = " +
formattedDates[i] + ", formatted = " + formatted);
Log.i(TAG, "initUI formatted" + i + "=" +
formattedDates[i]);
} else{
SimpleDateFormat sdf = new
SimpleDateFormat(dateFormats[i]);
formatted = sdf.format(mDummyDate.getTime());
Log.i(TAG, "initUI formatted" + i + "=" + formatted);
formattedDates[i] = formatted;
System.out.println("ran.zhou-DTS-L247-formattedDates[" + i + "] = " +
formattedDates[i] + ", formatted = " + formatted);
}
}
mDateFormat.setEntries(formattedDates);
mDateFormat.setEntryValues(dateFormats);
for (int i = 0; i < dateFormats.length; i++) {
System.out.println("ran.zhou-DTS-L254-dateFormats[" + i +
"] = " + dateFormats[i]);
}
/* MODIFIED-BEGIN by qiang.sun, 2016-05-03,BUG-2012268*/
if(TextUtils.isEmpty(currentFormat)){
currentFormat = dateFormats[0];
}
/* MODIFIED-END by qiang.sun,BUG-2012268*/
mDateFormat.setValue(currentFormat);
//Defect1061782-yongjie.xiao end
}
mDateFormat.setEntryValues(dateFormats)中設定了日期格式,
dateFormats數組存的是packages/app/Settings/res/values/arrays.xml中name = date_format_values的string-array數組,經查發現此string-array數組第一條item值為空,由此導緻鎖屏界面擷取的日期錯誤。
<string-array name="date_format_values" translatable="false">
<item></item>
<item>MM.dd.yyyy</item>
<item>dd.MM.yyyy</item>
<item>yyyy.MM.dd</item>
</string-array>
Device reset 和Factory data reset後choose data format的格式不一緻,前者選擇的是Region,後者選擇的是MM.dd.yyyy格式
為空時的處理如下
quicl/platform/frameworks/base / packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java
private Context mContext;
if (res.getBoolean(com.android.internal.R.bool.def_tctfw_SystemUI_Date_format_same_with_setting)) {
final String dateformat = Settings.System.getString(context.getContentResolver(),
Settings.System.DATE_FORMAT);
final String split = res.getString(com.android.internal.R.string.systemui_date_format_spilt);//modify by kun.gao for defect 987658, default is ".".
if (null == dateformat || "".equals(dateformat)) {
//default date format begin
java.text.DateFormat format = null;
format = java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT);
if (null == format) {
return;
}
private static Context mContext;
if (res.getBoolean(com.android.internal.R.bool.def_tctfw_SystemUI_Date_format_same_with_setting)) {
final String dateformat = Settings.System.getString(context.getContentResolver(),
Settings.System.DATE_FORMAT);
final String split = res.getString(com.android.internal.R.string.systemui_date_format_spilt);//modify by kun.gao for defect 987658, default is ".".
if (null == dateformat || "".equals(dateformat)) {
//default date format begin
//java.text.DateFormat format = null;
//format = java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT);
java.text.DateFormat format = DateFormat.getDateFormat(mContext);
if (null == format) {
return;
}
修改方案如上。