




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
安卓实训设计报告Android天气预报设计题目:Android天气预报班级:姓名:_学号:_指导老师:日期:2023年6月7日内容要求一、题目分析,功能要求。1.1实验目的熟悉Android软件开发的根本架构利用Eclipse和ADT插件设计贪天气预报1.2功能本软件就是利用现有的网络快速获取网络上的天气信息并显示到终端上,为用户提供实时的天气查询和近期天气查询效劳,为工作、出行等带来便利。通过WebService等技术让用户体验到前所未有的移动计算。二、实验设计本软件是一个AppWidget应用程序,启动程序后可以进行城市、更新频率的设置,可以通过图片和文字显示当前和未来的天气状况,包括温度、湿度、风向和雨雪情况等。这些天气数据是通过后台效劳获取的,这个后台效劳可以按照一定的时间间隔,通过Google提供的效劳获取天气预报信息,并将天气信息保存在数据库中。该软件的根本功能需求有:(1)启动AppWidget应用程序;(2)设置界面:对要显示天气预报的城市及更新频率进行设置;(3)显示界面:通过文字和图片显示当前的天气情况,包括日期、时间、城市、最高温度、最低温度、当前温度等。(4)详细界面:在显示出“显示界面〞上所有信息的同时用列表的形式显示今后四天的天气情况。三、实验程序见附录一。四、实验效果图图五、总结(1)在Android平台上可以通过WebService技术方便的获取互联网上的资源信息,在智能强大的硬件功能和快速的移动互联网的支持下,可以更加方便的利用网络上的资源,为生活、工作带来极大的便利。(2)Android语言的开发组件Activity、IntentReceiver、Service、ContentProvider等提供了强大的数据处理功能。合理的设计数据库可以方便的实现各页面、进程之间的数据共享、数据的传递,也会使程序的运行更加稳定。(3)Android系统中的视图组件View和ViewGroup等的灵活使用,可以设计出界面美观,用户操作方便灵活的页面,并可以实现页面各种不同的显示布局以及动画效果等。(4)使用SAX的方式解析android应用程序中的XML数据文件,可以提供很好的性能需求。之所以选择SAX的方式来解析XML文件,是因为它是一种非常优秀的轻量级解决方案。使用android平台的硬件环境主要是和其它一些嵌入式设备。这些设备都需要比拟快的解析速度和尽可能少的内存占用,同时满足这两方面要求的技术中SAX是一个非常好的选择。附录一 布局<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="://schemas.android/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:id="@+id/tvPlace"android:layout_width="fill_parent"android:layout_height="wrap_content"/><EditTextandroid:id="@+id/place"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="输入城市名称〔汉字或者拼音〕"/><Buttonandroid:id="@+id/query"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="查询"/></LinearLayout>将网络图片转换为android的bitmap对象packagecom.sbs.weather;importjava.io.IOException;importjava.io.InputStream;import.URLConnection;import.MalformedURLException;import.URL;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;publicclassUtils{publicstaticStringweek(StringenWeek){
if(enWeek.equals("Mon")||enWeek.equals("Monday"))return"星期一";
elseif(enWeek.equals("Tue")||enWeek.equals("Tuesday"))return"星期二";
elseif(enWeek.equals("Wed")||enWeek.equals("Wednesday"))return"星期三";
elseif(enWeek.equals("Thu")||enWeek.equals("Thursday"))return"星期四";
elseif(enWeek.equals("Fri")||enWeek.equals("Friday"))return"星期五";
elseif(enWeek.equals("Sat")||enWeek.equals("Saturday"))return"星期六";
elseif(enWeek.equals("Sun")||enWeek.equals("Sunday"))return"星期日";
return"";}publicstaticStringweather(StringenWeather){
if(enWeather.equals("Clear"))return"晴";
elseif(enWeather.equals("PartlySunny")||enWeather.equals("partly_cloudy"))return"多云";
elseif(enWeather.equals("ChanceofRain"))return"晴转雨";
elseif(enWeather.equals("storm"))return"暴雨";
elseif(enWeather.equals("thunderstorm"))return"雷阵雨";
elseif(enWeather.equals("fog"))return"大雾";
elseif(enWeather.equals("haze"))return"有雾";
elseif(enWeather.equals("rain"))return"雨";
elseif(enWeather.equals("heavyrain"))return"大雨";
elseif(enWeather.equals("lightrain"))return"小雨";
elseif(enWeather.equals("heavyrain"))return"大雨";
elseif(enWeather.equals("snow"))return"有雪";
///还需要补充。。。。
return"";}publicstaticBitmapreturnBitMap(StringimgUrl){
URLmyImgUrl=null;
Bitmapbitmap=null;
try{myImgUrl=newURL(imgUrl);
}catch(MalformedURLExceptione){e.printStackTrace();
}
try{URLConnectionconn=(URLConnection)myImgUrl.openConnection();conn.setDoInput(true);conn.connect();InputStreamis=conn.getInputStream();bitmap=BitmapFactory.decodeStream(is);is.close();
}catch(IOExceptione){e.printStackTrace();
}
returnbitmap;}}下面的程序通过Google提供的api来获取天气预报信息packagecom.sbs.weather;importjava.io.InputStream;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importorg.apache..Entity;Response;importorg.apache..client.methods.Get;importorg.apache..client.methods.UriRequest;importorg.apache..impl.client.DefaultClient;importorg.apache..util.EntityUtils;importorg.w3c.dom.Document;importorg.w3c.dom.NodeList;importorg.xml.sax.InputSource;importandroid.app.Activity;importandroid.graphics.Bitmap;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.util.Log;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.ImageView;importandroid.widget.TextView;publicclassWeatherextendsActivity{publicEditTextETplace;publicTextViewTvPlace;publicButtonquery;publicTextViewplaceName;publicImageViewimView;/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);ETplace=(EditText)findViewById(R.id.place);query=(Button)findViewById(R.id.query);imView=(ImageView)findViewById(R.id.myImageView);placeName=(TextView)findViewById(R.id.placeName);query.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){try{TvPlace=(TextView)findViewById(R.id.tvPlace);Stringplace=CntoEn.getFullSpell(ETplace.getText().toString());placeName.setText(place);Stringweather="";Stringurl="://google/ig/api?&weather="+place;DefaultClientclient=newDefaultClient();UriRequestreq=newGet(url);Responseresp=client.execute(req);//StringstrResult=EntityUtils.toString(resp.getEntity());//Log.i("weather->",strResult);//一华氏度等于9/5摄氏度数值+32Entityent=resp.getEntity();InputStreamstream=ent.getContent();DocumentBuilderb=DocumentBuilderFactory.newInstance().newDocumentBuilder();Documentd=b.parse(newInputSource(stream));NodeListn=d.getElementsByTagName("forecast_conditions");//获得图片url当天的。StringimgUrl="://google";imgUrl+=n.item(0).getChildNodes().item(3).getAttributes().item(0).getNodeValue();imView.setImageBitmap(Utils.returnBitMap(imgUrl));//今后4天预报for(inti=0;i<n.getLength();i++){weather+=Utils.week(n.item(i).getChildNodes().item(0).getAttributes().item(0).getNodeValue());weather+=",";weather+=(Integer.parseInt(n.item(i).getChildNodes().item(1).getAttributes().item(0).getNodeValue())-32)*5/9;weather+="~";weather+=(Integer.parseInt(n.item(i).getChildNodes().item(2).getAttributes().item(0).getNodeValue())-32)*5/9;weather+=",";weather+=Utils.weather(n.item(i).getChildNodes().item(4).getAttribu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 承包合同终止协议
- 木材公司销售合同
- 平面模特拍摄合同
- 电力施工劳务合同
- 漫画助理外包合同
- 油漆劳务分包合同协议书
- 无人机物流配送运营合作项目合同
- 商丘幼儿师范高等专科学校《旅行社经营管理》2023-2024学年第二学期期末试卷
- 山东管理学院《高阶地质资源勘查与评价》2023-2024学年第二学期期末试卷
- 文华学院《地理科学类专业导论》2023-2024学年第二学期期末试卷
- 慢阻肺的慢病管理课件
- (中职)化学分析技术项目一 走进化学分析实验室教学课件
- 探放水工培训教材
- 某县某年度高标准基本农田建设项目复核报告
- 秘书实务完整版课件全套ppt教程
- 酒店电子商务全套课件
- 质量体系的职能架构
- 《旅游经济学》全书PPT课件
- 幼儿园一日活动流程表
- 最后一分钟安全检查
- 散装水泥罐体标准资料
评论
0/150
提交评论