




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告安卓实训设计报告Android 天气预报设计题目: Android天气预报 班 级: 姓 名:_ 学 号:_ 指导老师: 日 期: 2012年6月7日 内容要求一、题目分析,功能要求。 1.1 实验目的 熟悉Android软件开发的基本架构 利用Eclipse和ADT插件设计贪天气预报 1.2 功能 本软件就是利用现有的网络快速获取网络上的天气信息并显示到手机终端上,为用户提供实时的天气查询和近期天气查询服务,为工作、出行等带来便利。通过Web Service等技术让用户体验到前所未有的移动计算。二、实验设计 本软件是一个App Widget应用程序,启动程序后可以进行城市、更新频率的设置,可以通过图片和文字显示当前和未来的天气状况,包括温度、湿度、风向和雨雪情况等。这些天气数据是通过后台服务获取的,这个后台服务可以按照一定的时间间隔,通过Google提供的服务获取天气预报信息,并将天气信息保存在数据库中。该软件的基本功能需求有:(1) 启动App Widget应用程序;(2) 设置界面:对要显示天气预报的城市及更新频率进行设置;(3) 显示界面:通过文字和图片显示当前的天气情况,包括日期、时间、城市、最高温度、最低温度、当前温度等。(4) 详细界面:在显示出“显示界面”上所有信息的同时用列表的形式显示今后四天的天气情况。三、实验程序见附录一。四、实验效果图图 五、总结(1)在Android 平台上可以通过Web Service 技术方便的获取互联网上的资源信息,在智能手机强大的硬件功能和快速的移动互联网的支持下,可以更加方便的利用网络上的资源,为生活、工作带来极大的便利。(2)Android语言的开发组件Activity、Intent Receiver、Service、Content Provider等提供了强大的数据处理功能。合理的设计数据库可以方便的实现各页面、进程之间的数据共享、数据的传递,也会使程序的运行更加稳定。(3)Android系统中的视图组件View和View Group等的灵活使用,可以设计出界面美观,用户操作方便灵活的页面,并可以实现页面各种不同的显示布局以及动画效果等。(4)使用SAX的方式解析android应用程序中的XML数据文件,可以提供很好的性能需求。之所以选择SAX的方式来解析XML文件,是因为它是一种非常优秀的轻量级解决方案。使用android平台的硬件环境主要是手机和其它一些嵌入式设备。这些设备都需要比较快的解析速度和尽可能少的内存占用,同时满足这两方面要求的技术中SAX是一个非常好的选择。附录一布局1. 2. 7. 12. 18. 24. 将网络图片转换为android的bitmap对象25. package com.sbs.weather; 26. import java.io.IOException; 27. import java.io.InputStream; 28. import .HttpURLConnection; 29. import .MalformedURLException; 30. import .URL; 31. import android.graphics.Bitmap; 32. import android.graphics.BitmapFactory; 33. public class Utils 34. public static String week(String enWeek) 35. if (enWeek.equals(Mon) | enWeek.equals(Monday) 36. return 星期一; 37. else if (enWeek.equals(Tue) | enWeek.equals(Tuesday) 38. return 星期二; 39. else if (enWeek.equals(Wed) | enWeek.equals(Wednesday) 40. return 星期三; 41. else if (enWeek.equals(Thu) | enWeek.equals(Thursday) 42. return 星期四; 43. else if (enWeek.equals(Fri) | enWeek.equals(Friday) 44. return 星期五; 45. else if (enWeek.equals(Sat) | enWeek.equals(Saturday) 46. return 星期六; 47. else if (enWeek.equals(Sun) | enWeek.equals(Sunday) 48. return 星期日; 49. return ; 50. 51. public static String weather(String enWeather) 52. if (enWeather.equals(Clear) 53. return 晴; 54. else if (enWeather.equals(Partly Sunny) 55. | enWeather.equals(partly_cloudy) 56. return 多云; 57. else if (enWeather.equals(Chance of Rain) 58. return 晴转雨; 59. else if (enWeather.equals(storm) 60. return 暴雨; 61. else if (enWeather.equals(thunderstorm) 62. return 雷阵雨; 63. else if (enWeather.equals(fog) 64. return 大雾; 65. else if (enWeather.equals(haze) 66. return 有雾; 67. else if (enWeather.equals(rain) 68. return 雨; 69. else if (enWeather.equals(heavyrain) 70. return 大雨; 71. else if (enWeather.equals(lightrain) 72. return 小雨; 73. else if (enWeather.equals(heavyrain) 74. return 大雨; 75. else if (enWeather.equals(snow) 76. return 有雪; 77. / / 还需要补充。 78. return ; 79. 80. public static Bitmap returnBitMap(String imgUrl) 81. URL myImgUrl = null; 82. Bitmap bitmap = null; 83. try 84. myImgUrl = new URL(imgUrl); 85. catch (MalformedURLException e) 86. e.printStackTrace(); 87. 88. try 89. HttpURLConnection conn = (HttpURLConnection) myImgUrl 90. .openConnection(); 91. conn.setDoInput(true); 92. conn.connect(); 93. InputStream is = conn.getInputStream(); 94. bitmap = BitmapFactory.decodeStream(is); 95. is.close(); 96. catch (IOException e) 97. e.printStackTrace(); 98. 99. return bitmap; 100. 101. 下面的程序通过Google提供的api来获取天气预报信息1. package com.sbs.weather; 2. import java.io.InputStream; 3. import javax.xml.parsers.DocumentBuilder; 4. import javax.xml.parsers.DocumentBuilderFactory; 5. import org.apache.http.HttpEntity; 6. import org.apache.http.HttpResponse; 7. import org.apache.http.client.methods.HttpGet; 8. import org.apache.http.client.methods.HttpUriRequest; 9. import org.apache.http.impl.client.DefaultHttpClient; 10. import org.apache.http.util.EntityUtils; 11. import org.w3c.dom.Document; 12. import org.w3c.dom.NodeList; 13. import org.xml.sax.InputSource; 14. import android.app.Activity; 15. import android.graphics.Bitmap; 16. import android.os.Bundle; 17. import android.os.Handler; 18. import android.os.Message; 19. import android.util.Log; 20. import android.view.View; 21. import android.widget.Button; 22. import android.widget.EditText; 23. import android.widget.ImageView; 24. import android.widget.TextView; 25. public class Weather extends Activity 26. public EditText ETplace; 27. public TextView TvPlace; 28. public Button query; 29. public TextView placeName; 30. public ImageView imView; 31. /* Called when the activity is first created. */ 32. Override 33. public void onCreate(Bundle savedInstanceState) 34. super.onCreate(savedInstanceState); 35. setContentView(R.layout.main); 36.37. ETplace = (EditText)findViewById(R.id.place); 38. query = (Button)findViewById(R.id.query); 39. imView = (ImageView)findViewById(R.id.myImageView); 40. placeName = (TextView)findViewById(R.id.placeName); 41. query.setOnClickListener(new Button.OnClickListener() 42. public void onClick(View v) 43. try 44. TvPlace = (TextView)findViewById(R.id.tvPlace); 45. String place = CntoEn.getFullSpell(ETplace.getText().toString(); 46. placeName.setText(place); 47. String weather = ; 48. String url = /ig/api?&weather=+place; 49. DefaultHttpClient client = new DefaultHttpClient(); 50. HttpUriRequest req = new HttpGet(url); 51. HttpResponse resp = client.execute(req); 52. /String strResult = EntityUtils.toString(resp.getEntity(); 53. /Log.i(weather-, strResult); 54. /一华氏度等于9/5摄氏度数值+32 55. HttpEntity ent = resp.getEntity(); 56. InputStream stream = ent.getCon
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 学校清单制管理制度
- 学校自管委管理制度
- 学生沐浴间管理制度
- 宁夏请销假管理制度
- 安全环境部管理制度
- 安置点建设管理制度
- 定向粮用途管理制度
- 实训室安全管理制度
- 宠物店员工管理制度
- 客房低耗品管理制度
- 冶金企业电气安全
- 全国爱肝日-中国肝硬化临床诊治共识意见知识讲座
- 重难点09 极值点偏移与拐点偏移问题(举一反三)(新高考专用)(学生版) 2025年高考数学一轮复习专练(新高考专用)
- 大数据调研报告
- 煤炭运输合同
- 2024年职业健康安全和环境管理目标、指标及管理方案
- 深圳市建筑小区及市政排水管网设计和施工技术指引
- 2022年《数据结构(本)》形考任务实践活动3
- T-HNNJ 0004-2021 水稻机械化收割技术规程
- 汽车电气系统实训工单课后练习题答案章节测试题1-9单元全题库
- 兽医实验室质量管理手册
评论
0/150
提交评论