安卓天气预报实训报告

时间:2024.4.20

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

安卓实训设计报告

Android 天气预报

设计题目: Android天气预报

班 级:

姓 名:_

学 号:_

指导老师:

日 期: 20xx年6月7日

- 1 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

内容要求

一、题目分析,功能要求。

1.1 实验目的

熟悉Android软件开发的基本架构

利用Eclipse和ADT插件设计贪天气预报

1.2 功能

本软件就是利用现有的网络快速获取网络上的天气信息并显示到手机终

端上,为用户提供实时的天气查询和近期天气查询服务,为工作、出行等带来便利。通过Web Service等技术让用户体验到前所未有的移动计算。

二、实验设计

本软件是一个App Widget应用程序,启动程序后可以进行城市、更新频率的设置,可以通过图片和文字显示当前和未来的天气状况,包括温度、湿度、风向和雨雪情况等。这些天气数据是通过后台服务获取的,这个后台服务可以按照一定的时间间隔,通过Google提供的服务获取天气预报信息,并将天气信息保存在数据库中。

该软件的基本功能需求有:

(1) 启动App Widget应用程序;

(2) 设置界面:对要显示天气预报的城市及更新频率进行设置;

(3) 显示界面:通过文字和图片显示当前的天气情况,包括日期、时间、城市、最高温度、最低温度、当前温度等。

(4) 详细界面:在显示出“显示界面”上所有信息的同时用列表的形式显示今后四天的天气情况。

三、实验程序

见附录一。

四、实验效果图图

- 2 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

安卓天气预报实训报告

安卓天气预报实训报告

安卓天气预报实训报告

安卓天气预报实训报告

- 3 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

安卓天气预报实训报告

五、总结

(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是一个非常好的选择。

安卓天气预报实训报告

- 4 -

安卓天气预报实训报告

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

附录一

布局

1. <?xml version="1.0" encoding="utf-8"?>

2. <LinearLayout xmlns:android="/apk/res/android"

3. android:orientation="vertical"

4. android:layout_width="fill_parent"

5. android:layout_height="fill_parent"

6. >

7. <TextView

8. android:id="@+id/tvPlace"

9. android:layout_width="fill_parent"

10. android:layout_height="wrap_content"

11. />

12. <EditText

13. android:id="@+id/place"

14. android:layout_width="fill_parent"

15. android:layout_height="wrap_content"

16. android:hint="输入城市名称(汉字或者拼音)"

17. />

18. <Button

19. android:id="@+id/query"

20. android:layout_width="fill_parent"

21. android:layout_height="wrap_content"

22. android:text="查询"

23. />

24. </LinearLayout>

将网络图片转换为android的bitmap对象

25. package com.sbs.weather;

26. import java.io.IOException;

27. import java.io.InputStream;

28. import java.net.HttpURLConnection;

29. import java.net.MalformedURLException;

30. import java.net.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"))

- 5 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

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) {

- 6 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

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;

- 7 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

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.getContent();

57. DocumentBuilder b = DocumentBuilderFactory.newInstance()

58. .newDocumentBuilder();

59. Document d = b.parse(new InputSource(stream));

60. NodeList n = d.getElementsByTagName("forecast_conditions");

61. // 获得图片url 当天的。

62. String imgUrl = "";

63. imgUrl += n.item(0).getChildNodes().item(3).getAttributes().item(0).getNodeValue();

64. imView.setImageBitmap(Utils.returnBitMap(imgUrl));

65. // 今后4天预报

66. for (int i = 0; i < n.getLength(); i++) {

67. weather += Utils.week(n.item(i).getChildNodes().item(0)

68. .getAttributes().item(0).getNodeValue());

69. weather += ", ";

70. weather += (Integer

71. .parseInt(n.item(i).getChildNodes().item(1)

72. .getAttributes().item(0).getNodeValue()) - 32) * 5 / 9;

73. weather += " ~ ";

- 8 -

电子与信息工程学院计算机科学与技术系 开放与创新实验设计报告

74. weather += (Integer

75. .parseInt(n.item(i).getChildNodes().item(2)

76. .getAttributes().item(0).getNodeValue()) - 32) * 5 / 9;

77. weather += ", ";

78. weather += Utils.weather(n.item(i).getChildNodes().item(4)

79. .getAttributes().item(0).getNodeValue());

80. weather += "\n";

81. }

82. Log.i("parseed weather->", weather);

83. TvPlace.setText(weather);

84.

85. } catch (Exception e) {

86. e.printStackTrace();

87. }

88.

89. }});

90. }

91. }

添加权限

1. <?xml version="1.0" encoding="utf-8"?>

2. <manifest xmlns:android="/apk/res/android"

3. package="com.sbs.weather"

4. android:versionCode="1"

5. android:versionName="1.0">

6. <uses-permission android:name="android.permission.INTERNET"></uses-permission>

7. <application android:icon="@drawable/icon" android:label="@string/app_name">

8. <activity android:name=".Weather"

9. android:label="@string/app_name">

10. <intent-filter>

11. <action android:name="android.intent.action.MAIN" />

12. <category android:name="android.intent.category.LAUNCHER" />

13. </intent-filter>

14. </activity>

15. </application>

16. </manifest>

- 9 -

更多相关推荐:
Android实训报告

通信与电子信息专业实训报告项目名称基于Android的游戏开发班级10通信1班姓名学号指导教师成绩实训时间年月日目录一实训目的及其意义311目的及意义312研究现状3二实训主要任务重点及难点421任务422重点...

安卓实训报告

实习报告书专业计算机科学与技术系别报告题目安卓报告人班级指导教师带队教师实习时间实习地点教务处监制

android实训报告

多媒体技术综合实训课题名称多媒体展示系统的设计与开发计算机与软件学院计算机多媒体游戏软件设计与开发计媒10211002553224学号10025532061002553218院系专业班级100255321210...

android实训报告

android实训报告学号09090103姓名冯超洁南京师范大学泰州学院题目学姓班信息工程学院Android实训报告AndroidGPS系统号09090103名冯超洁级信工09120xx年6月1AndroidG...

安卓实训

实训报告题目:Android学号:姓名:班级:指导教师:20##年6月摘要Android(安卓)系统是手机或一些平板电脑等终端的操作系统,可以说是现在最流行的系统之一。是目前最流行的手机智能平台开放的开发平台,…

android实训报告总结

学员个人实训总结

android实训报告

实习报告实习性质学院班级学生姓名学号指导老师实习时间一实训目的和任务1实训任务信息工程学院android视频播放器系统的设计与实现2实训目的本学期我们学习了JAVA课程和Android应用程序开发课程而Andr...

android实训报告

实训总结通过这为期三周的android实训我们学会了用eclipse的android编程方法以及开发用的MVC变成开发模式和团队开发所使用的SVN团队编程版本控制器在以后学习过程中希望大家多多提点我和我们组的组...

安卓通讯录实训报告

安卓实训设计报告安卓通讯录设计题目:安卓通讯录班级:姓名:学号:指导老师:日期:内容要求一、题目分析,功能要求。1.1实验目的熟悉Android软件开发的基本架构利用Eclipse和ADT插件设计通讯录1.2功…

安卓实验报告模板

Android应用程序开发结课报告软件名称班级学号学生姓名指导教师年月日

android项目实训报告

Android项目实训报告

android视频播放器实训报告

实训报告书实训名称系部专业班级学生姓名学号指导教师完成日期目录1实训目的22android视频播放器系统的分析与设计2装345订线21系统功能描述222系统模块设计3主要代码清单3程序运行与测试4实训总结9an...

安卓实训报告(31篇)