iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android编程之短信列表的时间显示实例分析
  • 214
分享到

Android编程之短信列表的时间显示实例分析

程之列表Android 2022-06-06 09:06:38 214人浏览 薄情痞子
摘要

本文实例讲述了Android编程之短信列表的时间显示。分享给大家供大家参考,具体如下: Android的短信的时间的显示做的很精细,首先保存在短信数据库mmSSMs.db中的短

本文实例讲述了Android编程之短信列表的时间显示。分享给大家供大家参考,具体如下:

Android的短信的时间的显示做的很精细,首先保存在短信数据库mmSSMs.db中的短信时间都是Long型的数字,查询动作结束,取到这个值之后,会做转换,具体转换的动作在MessageUtils.java的fORMatTimeStampString函数中完成;


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

从第二个具体实现的函数可以看出来,Android是根据当前的时间为比较的依据来决定显示的时间格式:

1. 如果当前的短信时间中年份跟手机当前的年份不一致,则显示年月日,不显示具体的几点几分,如:2010-6-30;

2. 如果短信的时间跟手机当前时间在同一年,但不是同一天,则只显示月日,如:6月29日;

3. 如果是当天的短信,则会计算是上午还是下午的短信,同时显示几点几分记录的该短信,如:下午 12:55;

综合考虑下来,这样的显示设计还是很合理的

希望本文所述对大家Android程序设计有所帮助。

您可能感兴趣的文章:Android视频处理之动态时间水印效果Android学习系列一用按钮实现显示时间Android调用系统时间格式显示时间信息Android开发技巧之永不关闭的Toast信息框(长时间显示而非系统关闭)Android 动态的显示时间


--结束END--

本文标题: Android编程之短信列表的时间显示实例分析

本文链接: https://www.lsjlt.com/news/26343.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作