The time display example analysis of the SMS List of Android programming _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.