锁屏界面日期显示异常

一、问题现象

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;
                    }

修改方案如上。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值