Android編程之短信列表的時間顯示實(shí)例分析
本文實(shí)例講述了Android編程之短信列表的時間顯示。分享給大家供大家參考,具體如下:
Android的短信的時間的顯示做的很精細(xì),首先保存在短信數(shù)據(jù)庫mmssms.db中的短信時間都是Long型的數(shù)字,查詢動作結(jié)束,取到這個值之后,會做轉(zhuǎn)換,具體轉(zhuǎn)換的動作在MessageUtils.java的formatTimeStampString函數(shù)中完成;
public static String formatTimeStampString(Context context, long when) { return formatTimeStampString(context, when, false); } public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }
從第二個具體實(shí)現(xiàn)的函數(shù)可以看出來,Android是根據(jù)當(dāng)前的時間為比較的依據(jù)來決定顯示的時間格式:
1. 如果當(dāng)前的短信時間中年份跟手機(jī)當(dāng)前的年份不一致,則顯示年月日,不顯示具體的幾點(diǎn)幾分,如:2010-6-30;
2. 如果短信的時間跟手機(jī)當(dāng)前時間在同一年,但不是同一天,則只顯示月日,如:6月29日;
3. 如果是當(dāng)天的短信,則會計算是上午還是下午的短信,同時顯示幾點(diǎn)幾分記錄的該短信,如:下午 12:55;
綜合考慮下來,這樣的顯示設(shè)計還是很合理的
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
android編程實(shí)現(xiàn)局部界面動態(tài)切換的方法
這篇文章主要介紹了android編程實(shí)現(xiàn)局部界面動態(tài)切換的方法,以實(shí)例形式較為詳細(xì)的分析了Android局部切換的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11Android UI設(shè)計與開發(fā)之ViewPager介紹和簡單實(shí)現(xiàn)引導(dǎo)界面
這篇文章主要為大家詳細(xì)介紹了Android UI設(shè)計與開發(fā)之ViewPager介紹和簡單實(shí)現(xiàn)引導(dǎo)界面,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08android動態(tài)壁紙調(diào)用的簡單實(shí)例
動態(tài)壁紙的實(shí)現(xiàn)其實(shí)就是在Activity中調(diào)用動態(tài)壁紙服務(wù),通過綁定服務(wù)得到IWallpaperService,調(diào)用該接口中的attach函數(shù)實(shí)現(xiàn)壁紙的調(diào)用。2013-06-06Android 有效的解決內(nèi)存泄漏的問題實(shí)例詳解
這篇文章主要介紹了Android 有效的解決內(nèi)存泄漏的問題的相關(guān)資料,這里舉例說明,如何實(shí)現(xiàn)解決內(nèi)存泄漏,需要的朋友可以參考下2016-11-11Android自定義日歷Calender代碼實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了Android自定義日歷Calender實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09Android開發(fā)自定義實(shí)時圖表控件實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Android自定義實(shí)時圖表控件實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06Android 桌面圖標(biāo)右上角顯示未讀消息數(shù)字
本文主要介紹了Android 桌面圖標(biāo)右上角顯示未讀消息數(shù)字的方法。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04Android 自定義imageview實(shí)現(xiàn)圖片縮放實(shí)例詳解
這篇文章主要介紹了Android 自定義imageview實(shí)現(xiàn)圖片縮放實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04