




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
安卓實訓(xùn)設(shè)計報告Android天氣預(yù)報設(shè)計題目:Android天氣預(yù)報班級:姓名:_學(xué)號:_指導(dǎo)老師:日期:2023年6月7日內(nèi)容要求一、題目分析,功能要求。1.1實驗?zāi)康氖煜ndroid軟件開發(fā)的根本架構(gòu)利用Eclipse和ADT插件設(shè)計貪天氣預(yù)報1.2功能本軟件就是利用現(xiàn)有的網(wǎng)絡(luò)快速獲取網(wǎng)絡(luò)上的天氣信息并顯示到終端上,為用戶提供實時的天氣查詢和近期天氣查詢效勞,為工作、出行等帶來便利。通過WebService等技術(shù)讓用戶體驗到前所未有的移動計算。二、實驗設(shè)計本軟件是一個AppWidget應(yīng)用程序,啟動程序后可以進(jìn)行城市、更新頻率的設(shè)置,可以通過圖片和文字顯示當(dāng)前和未來的天氣狀況,包括溫度、濕度、風(fēng)向和雨雪情況等。這些天氣數(shù)據(jù)是通過后臺效勞獲取的,這個后臺效勞可以按照一定的時間間隔,通過Google提供的效勞獲取天氣預(yù)報信息,并將天氣信息保存在數(shù)據(jù)庫中。該軟件的根本功能需求有:(1)啟動AppWidget應(yīng)用程序;(2)設(shè)置界面:對要顯示天氣預(yù)報的城市及更新頻率進(jìn)行設(shè)置;(3)顯示界面:通過文字和圖片顯示當(dāng)前的天氣情況,包括日期、時間、城市、最高溫度、最低溫度、當(dāng)前溫度等。(4)詳細(xì)界面:在顯示出“顯示界面〞上所有信息的同時用列表的形式顯示今后四天的天氣情況。三、實驗程序見附錄一。四、實驗效果圖圖五、總結(jié)(1)在Android平臺上可以通過WebService技術(shù)方便的獲取互聯(lián)網(wǎng)上的資源信息,在智能強(qiáng)大的硬件功能和快速的移動互聯(lián)網(wǎng)的支持下,可以更加方便的利用網(wǎng)絡(luò)上的資源,為生活、工作帶來極大的便利。(2)Android語言的開發(fā)組件Activity、IntentReceiver、Service、ContentProvider等提供了強(qiáng)大的數(shù)據(jù)處理功能。合理的設(shè)計數(shù)據(jù)庫可以方便的實現(xiàn)各頁面、進(jìn)程之間的數(shù)據(jù)共享、數(shù)據(jù)的傳遞,也會使程序的運(yùn)行更加穩(wěn)定。(3)Android系統(tǒng)中的視圖組件View和ViewGroup等的靈活使用,可以設(shè)計出界面美觀,用戶操作方便靈活的頁面,并可以實現(xiàn)頁面各種不同的顯示布局以及動畫效果等。(4)使用SAX的方式解析android應(yīng)用程序中的XML數(shù)據(jù)文件,可以提供很好的性能需求。之所以選擇SAX的方式來解析XML文件,是因為它是一種非常優(yōu)秀的輕量級解決方案。使用android平臺的硬件環(huán)境主要是和其它一些嵌入式設(shè)備。這些設(shè)備都需要比擬快的解析速度和盡可能少的內(nèi)存占用,同時滿足這兩方面要求的技術(shù)中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>將網(wǎng)絡(luò)圖片轉(zhuǎn)換為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"晴轉(zhuǎn)雨";
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"有雪";
///還需要補(bǔ)充。。。。
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來獲取天氣預(yù)報信息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攝氏度數(shù)值+32Entityent=resp.getEntity();InputStreamstream=ent.getContent();DocumentBuilderb=DocumentBuilderFactory.newInstance().newDocumentBuilder();Documentd=b.parse(newInputSource(stream));NodeListn=d.getElementsByTagName("forecast_conditions");//獲得圖片url當(dāng)天的。StringimgUrl="://google";imgUrl+=n.item(0).getChildNodes().item(3).getAttributes().item(0).getNodeValue();imView.setImageBitmap(Utils.returnBitMap(imgUrl));//今后4天預(yù)報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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中醫(yī)骨科試題及答案
- 新疆阿克蘇地區(qū)庫車縣二中2025屆數(shù)學(xué)高二第二學(xué)期期末聯(lián)考模擬試題含解析
- 浙江省麗水、湖州、衢州市2025屆數(shù)學(xué)高二第二學(xué)期期末預(yù)測試題含解析
- 浙江省新2024-2025學(xué)年高二數(shù)學(xué)第二學(xué)期期末考試模擬試題含解析
- 財務(wù)外包服務(wù)合同
- 旅游度假村場地使用權(quán)轉(zhuǎn)讓合同范本
- 房地產(chǎn)項目財務(wù)擔(dān)保服務(wù)合同
- 特色美食餐廳轉(zhuǎn)讓及裝修改造合同
- 桉樹造林項目投資合作合同模板
- 環(huán)保節(jié)能型料磚渣采購與質(zhì)量監(jiān)控合同
- 人教版五年級下冊分?jǐn)?shù)加減法簡便計算300道及答案
- (廣東二模)2025年廣東省高三高考模擬測試(二)語文試卷(含答案解析)
- 2024中遠(yuǎn)海運(yùn)博鰲有限公司“啟明星”等你來筆試參考題庫附帶答案詳解
- 成人腸造口護(hù)理-中華護(hù)理學(xué)會團(tuán)體標(biāo)準(zhǔn)
- 湖北省武漢市2025屆高中畢業(yè)生四月調(diào)研考試歷史試題及答案(武漢四調(diào))
- 地址掛靠合同協(xié)議
- 2025-2030中國汽車玻璃行業(yè)發(fā)展分析及發(fā)展前景與趨勢預(yù)測研究報告
- 2025年湖北省初中學(xué)業(yè)水平考試地理模擬卷(三)(學(xué)生版)
- 2025屆江蘇省南京市南京師范大學(xué)附屬中學(xué)高三下學(xué)期“揚(yáng)帆起航”數(shù)學(xué)試題
- 2025年中國陸上風(fēng)電行業(yè)運(yùn)行態(tài)勢及市場發(fā)展?jié)摿︻A(yù)測報告
- 2025年福建省廈門市思明區(qū)廈門第一中學(xué)初三5月二模試題英語試題含答案
評論
0/150
提交評論