设计
题目
南通航运职业技术学院 学生课程设计报告 系 部 管理信息系 专业 班级 学生姓名 完成日期
1
指导老师
一、实训目的
1.以“天气预报软件”为实训示例,运用以往的学习的知识和技巧,设计天气预报软件
2.通过实训,掌握Android应用程序的设计步骤和各种组件的综合运用
3.掌握Android应用程序的设计思路和开发方法
二、实训内容
设计并制作一款天气预报的软件,通过图片和文字显示当前和未来几天的天气情况,包括温度、湿度、风向、雨雪情况。通过后台获取天气信息,定时间隔从Google 上获取实时的天气信息。手机用户还可以通过发送SMS短息,在短息中包含的定的天气关键字,程序将天气信息通过SMS短信回复给用户。
三、实训设计
软件具有显示天气信息情况的用户界面、用户浏览或者删除消息记录的模块、显示配置信息的界面。
(1)显示天气预报的用户界面
(2)显示已发送SMS信息的用户界面
(3)浏览和设置配置信息的用户界面
根据用户功能的需求,用户界面和内部功能的关系如下:
1)显示天气预报的用户界面
①获取Google的天气数据
②保存天气数据信息
2)显示SMS信息的用户界面
①根据关键字监视SMS信息
②发送包含天气信息的SMS信息
③将发送SMS信息的相关信息写入数据库
3)浏览和设置配置信息的用户界面
①将用户设置的配置信息保存到数据库
②启动时读取数据库中的配置信息
③支持恢复默认设置
一.用户界面设计
显示界面中,显示目标城市目标城市的实时天气状况,包括城市名称、温度、湿度、风向、雨雪状况和获取时间,并在下方显示未来四天的天气状况。
显示SMS信息用户界面只能怪,显示每个回复信息的时间、目标手机、目标手机的号码、城市名称、当天的天气状况和未来一天的天气状况。在浏览和设置配置界面中,显示希望获取天气预报的城市名称,获取数据的时间频率和短信监视的关键字,永续用户设置是
2
否提供短信回复,以及是否记录回复短信信息。
二、数据库设计
配置信息的数据库表
四、实训过程
这次实训从工程的文件结构、数据库的适配器、短信监听器、后台服务器和用户界面等展开具体的设计过程。(详见附录1:)
五、实训总结
通过本次实训,考核了自己在平时学习时掌握的知识和方法,对Android应用开发的一些方法加深了印象,对一些组件的运用更加的灵活。
天气软件是一款比较复杂的软件实例。其中所用到的知识很多都在我们学科的范围之外,其中有些组件的运用更加的详细和灵活,而且用到的属性和功能比较全面,有些属性平时几乎没有接触。但是经过请教老师和一些相关资料的查询,基本解决了这些问题,当然还有一些比较专业的问题至今没有解决,有待老师的进一步指导。
这款软件是参照网络上流行的天气软件设计制作,本身并没有没显示的特点。主要是用来练习和实践,其中的功能及界面都存在不太完善地方。作为我们的实训练习,就算是对我们的挑战了。特别是设计思路方面,平时注重的是技能的锻炼,对整体的软件设计接触很少,没有系统的学习,当接到这个练习的时候,很茫然不知所措,在整体的思路上没有具体的想法。而后经过慢慢的学习,初步制定出设计,在设计和软件的制作中,对初定的设计计划做了很大的修改和完善,例如在用户界面设计时,起初的界面规划很不合理,在参考其他相关的软件的设计后,逐渐的改善设计稿。
这次实训让我们亲身实际的完成一个项目,是对平时零散知识、技能的综合,对Android应用开发的整天把握和具体的组件运用,对设计思路和软件操作都有了很大的提高,为我们今后工作提供了锻炼的机会。
3
4
第二篇:Android 中文天气预报程序
Android 中文天气预报程序
20xx年09月13日 星期一 12:47
大家好!由于项目原因好长时间没学android了。今天抽出点儿时间做个天气预报程序。贴出来希望对大家有用。
先说一下Google天气预报的AIP吧。 /ig/api?&weather=城市名(中文全拼).
我发现在模拟器上面返回的结果和在pc上返回的结果不太一样,pc上有中文的,android模拟器上没有的。
好了不说别的了。开始吧!
now start。
1。建立工程。我取名sbsWeather。结构如下:
我们一步一步来,慢慢完善
2。我习惯先写布局。
1.
2. <?xml version="1.0" encoding="utf-8"?>
3. <LinearLayout xmlns:android="/apk/res/android"
4. android:orientation="vertical"
5. android:layout_width="fill_parent"
6. android:layout_height="fill_parent"
7. >
8. <TextView
9. android:id="@+id/tvPlace"
10. android:layout_width="fill_parent"
11. android:layout_height="wrap_content"
12. />
13. <EditText
14. android:id="@+id/place"
15. android:layout_width="fill_parent"
16. android:layout_height="wrap_content"
17. android:hint="输入城市名称(汉字或者拼音)"
18. />
19. <Button
20. android:id="@+id/query"
21. android:layout_width="fill_parent"
22. android:layout_height="wrap_content"
23. android:text="查询"
24. />
25. </LinearLayout>
复制代码
3。我们要做的是中文天气预报哦。可是Google为我们返回的是中文。再有我们得把用户输入的中文转换为拼音再传给Google才可以。
现在,需要准备一些工具。
编写中文拼音转换类,CntoEn.java。网上好多的。自己随便找一个就哦了。
这个不贴代码了。搜Java 中文转音频 即可。
Utils.java 转换Google返回的英文。。。一对一的转换吧,好像没别的跟好的办法。 另外其中还有个方法是将网络图片转换为android的bitmap对象的。
1.
2. package com.sbs.weather;
3. import java.io.IOException;
4. import java.io.InputStream;
5. import java.net.HttpURLConnection;
6. import java.net.MalformedURLException;
7. import java.net.URL;
8. import android.graphics.Bitmap;
9. import android.graphics.BitmapFactory;
10. public class Utils {
11. public static String week(String enWeek) {
12. if (enWeek.equals("Mon") || enWeek.equals("Monday"))
13. return "星期一";
14. else if (enWeek.equals("Tue") || enWeek.equals("Tuesday"))
15. return "星期二";
16. else if (enWeek.equals("Wed") || enWeek.equals("Wednesday"))
17. return "星期三";
18. else if (enWeek.equals("Thu") || enWeek.equals("Thursday"))
19. return "星期四";
20. else if (enWeek.equals("Fri") || enWeek.equals("Friday"))
21. return "星期五";
22. else if (enWeek.equals("Sat") || enWeek.equals("Saturday"))
23. return "星期六";
24. else if (enWeek.equals("Sun") || enWeek.equals("Sunday"))
25. return "星期日";
26. return "";
27. }
28. public static String weather(String enWeather) {
29. if (enWeather.equals("Clear"))
30. return "晴";
31. else if (enWeather.equals("Partly Sunny")
32. || enWeather.equals("partly_cloudy"))
33. return "多云";
34. else if (enWeather.equals("Chance of Rain"))
35. return "晴转雨";
36. else if (enWeather.equals("storm"))
37. return "暴雨";
38. else if (enWeather.equals("thunderstorm"))
39. return "雷阵雨";
40. else if (enWeather.equals("fog"))
41. return "大雾";
42. else if (enWeather.equals("haze"))
43. return "有雾";
44. else if (enWeather.equals("rain"))
45. return "雨";
46. else if (enWeather.equals("heavyrain"))
47. return "大雨";
48. else if (enWeather.equals("lightrain"))
49. return "小雨";
50. else if (enWeather.equals("heavyrain"))
51. return "大雨";
52. else if (enWeather.equals("snow"))
53. return "有雪";
54. // / 还需要补充。。。。
55. return "";
56. }
57. public static Bitmap returnBitMap(String imgUrl) {
58. URL myImgUrl = null;
59. Bitmap bitmap = null;
60. try {
61. myImgUrl = new URL(imgUrl);
62. } catch (MalformedURLException e) {
63. e.printStackTrace();
64. }
65. try {
66. HttpURLConnection conn = (HttpURLConnection) myImgUrl
67. .openConnection();
68. conn.setDoInput(true);
69. conn.connect();
70. InputStream is = conn.getInputStream();
71. bitmap = BitmapFactory.decodeStream(is);
72. is.close();
73. } catch (IOException e) {
74. e.printStackTrace();
75. }
76. return bitmap;
77. }
78. }
复制代码
4。开始真正的工作咯。下面的程序通过Google提供的api来获取天气预报信息。
1. package com.sbs.weather;
2.
3. import java.io.InputStream;
4.
5. import javax.xml.parsers.DocumentBuilder;
6. import javax.xml.parsers.DocumentBuilderFactory;
7.
8. import org.apache.http.HttpEntity;
9. import org.apache.http.HttpResponse;
10. import org.apache.http.client.methods.HttpGet;
11. import org.apache.http.client.methods.HttpUriRequest;
12. import org.apache.http.impl.client.DefaultHttpClient;
13. import org.apache.http.util.EntityUtils;
14. import org.w3c.dom.Document;
15. import org.w3c.dom.NodeList;
16. import org.xml.sax.InputSource;
17.
18. import android.app.Activity;
19. import android.graphics.Bitmap;
20. import android.os.Bundle;
21. import android.os.Handler;
22. import android.os.Message;
23. import android.util.Log;
24. import android.view.View;
25. import android.widget.Button;
26. import android.widget.EditText;
27. import android.widget.ImageView;
28. import android.widget.TextView;
29.
30. public class Weather extends Activity {
31.
32. public EditText ETplace;
33. public TextView TvPlace;
34. public Button query;
35. public TextView placeName;
36. public ImageView imView;
37.
38. /** Called when the activity is first created. */
39. @Override
40. public void onCreate(Bundle savedInstanceState) {
41. super.onCreate(savedInstanceState);
42. setContentView(R.layout.main);
43.
44. ETplace = (EditText)findViewById(R.id.place);
45. query = (Button)findViewById(R.id.query);
46. imView = (ImageView)findViewById(R.id.myImageView);
47. placeName = (TextView)findViewById(R.id.placeName); 48.
49. query.setOnClickListener(new Button.OnClickListener() {
50. public void onClick(View v) {
51. try{
52. TvPlace = (TextView)findViewById(R.id.tvPlace);
53.
54. String place = CntoEn.getFullSpell(ETplace.getText().toString());
55. placeName.setText(place);
56. String weather = "";
57. String url = "/ig/api?&weather="+place;
58. DefaultHttpClient client = new DefaultHttpClient();
59. HttpUriRequest req = new HttpGet(url);
60. HttpResponse resp = client.execute(req);
61.
62. //String strResult = EntityUtils.toString(resp.getEntity());
63. //Log.i("weather->", strResult);
64. //一华氏度等于9/5摄氏度数值+32
65.
66. HttpEntity ent = resp.getEntity();
67. InputStream stream = ent.getContent();
68.
69. DocumentBuilder b = DocumentBuilderFactory.newInstance()
70. .newDocumentBuilder();
71. Document d = b.parse(new InputSource(stream));
72. NodeList n = d.getElementsByTagName("forecast_conditions");
73.
74. // 获得图片url 当天的。
75. String imgUrl = "";
76. imgUrl += n.item(0).getChildNodes().item(3).getAttributes().item(0).getNodeValue();
77. imView.setImageBitmap(Utils.returnBitMap(imgUrl));
78.
79. // 今后4天预报
80. for (int i = 0; i < n.getLength(); i++) {
81. weather += Utils.week(n.item(i).getChildNodes().item(0)
82. .getAttributes().item(0).getNodeValue());
83. weather += ", ";
84. weather += (Integer
85. .parseInt(n.item(i).getChildNodes().item(1)
86. .getAttributes().item(0).getNodeValue()) - 32) * 5 / 9;
87. weather += " ~ ";
88. weather += (Integer
89. .parseInt(n.item(i).getChildNodes().item(2)
90. .getAttributes().item(0).getNodeValue()) - 32) * 5 / 9;
91. weather += ", ";
92. weather += Utils.weather(n.item(i).getChildNodes().item(4)
93. .getAttributes().item(0).getNodeValue());
94. weather += "\n";
95. }
96. Log.i("parseed weather->", weather);
97. TvPlace.setText(weather);
98.
99. } catch (Exception e) {
100. e.printStackTrace();
101. }
102.
103. }});
104. }
105. }
复制代码
5。嗯这一步相当重要,就是添加权限。要是没有权限一切白搭!
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.
16. </application>
17. </manifest>
复制代码
6。开始运行咯。
源码在这里:
喜欢的下载吧。。。 嗯呢,我是好人! sbsWeather.rar (64.82 KB)
7。总结:可以使用数据库,保存用户常用的设置。比如存5个城市等。 还可以加上触屏拖动切换城市的效果这样子就比较完美了。
当然为了节省流量完全可以使用本地图片而不用网络图片。
总之希望各位朋友,尤其是大牛们,提出建议,帮着完善。 02.png (128.52 KB)