This example describes the time display for the SMS list of Android programming. Share to everyone for your reference, specific as follows:
Android's SMS time display is done very finely, First save in the SMS database mmssms.db SMS time is a long number, the query action is finished, after taking this value, will do the conversion, the specific conversion of the action in the Messageutils.java formattimestampstring function completed;
public static String formattimestampstring (the context, long,) {return formattimestampstring (the context, when, FA
LSE);
The public static String formattimestampstring (the context, long, Boolean Fullformat) {Time then = new Time ();
Then.set (when);
Time now = new Time ();
Now.settonow ();
Basic settings for FormatDateTime () we want to all cases.
int format_flags = Dateutils.format_no_noon_midnight |
Dateutils.format_abbrev_all |
DATEUTILS.FORMAT_CAP_AMPM;
If the message was from 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 ' different day than
Format_flags |= dateutils.format_show_date;
else {//otherwise, if the ' message ' is ' from today ', show ' time.
Format_flags |= Dateutils.format_show_time; }//If The caller has asked for fullDetails, make sure to show the date//and time no matter what we ' ve determined above (but still make showing//the Y
Ear only happen if it was a different year to today. if (Fullformat) {format_flags |= (dateutils.format_show_date |
Dateutils.format_show_time);
Return to Dateutils.formatdatetime (context, when, format_flags);
}
As you can see from the second concretely implemented function, Android determines the time format to display based on the current time comparison:
1. If the current text message time is inconsistent with the current year of the mobile phone, then show the month and day, do not show a specific number of points, such as: 2010-6-30;
2. If the time of the text message and mobile phone current time in the same year, but not the same day, only show the month, such as: June 29;
3. If the message is the day, it will be calculated is the morning or afternoon text messages, while showing a few minutes of the note, such as: 12:55;
Considering this, the display design is quite reasonable.
I hope this article will help you with the Android program.