freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

畢業(yè)論文-基于android平臺(tái)的3g手機(jī)氣象預(yù)報(bào)軟件設(shè)計(jì)與實(shí)現(xiàn)(已改無(wú)錯(cuò)字)

2023-07-19 10:39:10 本頁(yè)面
  

【正文】 */ @Override public String getType(Uri uri) { // TODO Autogenerated method stub switch ((uri)) { case WIDGETS: return 。 case WIDGETS_ID: return 。 case WIDGETS_FORECASTS: return 。 case FORECASTS: return 。 case FORECASTS_ID: return 。 } throw new IllegalStateException()。 } //構(gòu)造無(wú)匹配方式的 uriMatcher private static final UriMatcher uriMatcher = new UriMatcher( )。 private static final int WIDGETS = 101。 private static final int WIDGETS_ID = 102。 private static final int WIDGETS_FORECASTS = 103。 private static final int FORECASTS = 201。 private static final int FORECASTS_ID = 202。 //聲明了 uriMatcher的匹配方式和返回代碼 第五章 程序開(kāi)發(fā) static { (AUTHORITY, widgets, WIDGETS)。 (AUTHORITY, widgets/, WIDGETS_ID)。 (AUTHORITY, widgets//forecasts, WIDGETS_FORECASTS)。 (AUTHORITY, forecasts, FORECASTS)。 (AUTHORITY, forecasts/, FORECASTS_ID)。 } } 后臺(tái)服務(wù) 后臺(tái)服務(wù)是 tyweather工程的核心模塊,在用戶啟動(dòng)后持續(xù)在后臺(tái)運(yùn)行,直到用戶停止服務(wù)。后臺(tái)服務(wù)主要有三個(gè)功能,一是周期性的獲取 Google的天氣數(shù)據(jù)并存儲(chǔ)到 SQLite,二是從 SQLite讀取出要顯示的數(shù)據(jù),三是定時(shí)更新“顯示頁(yè)面”的時(shí)間。 獲取天氣數(shù)據(jù) 天氣數(shù)據(jù)的獲取天氣數(shù)據(jù)分為以下三個(gè)步驟: (1) 從 Google提供的 Web Service中獲取的天氣數(shù)據(jù),數(shù)據(jù)的獲取地址是: 下: public static WidgetEntity queryWebservice(String postalCode) throws ForecastParseException { //編碼出錯(cuò) if (postalCode == null) { throw new ForecastParseException(can not covert to entity)。 } Reader responseReader。 WidgetEntity widgetEntity = null。 //通過(guò) HttpClient創(chuàng)建 Http連接 HttpClient client = new DefaultHttpClient()。 //創(chuàng)建 Http Get請(qǐng)求 HttpGet request = new HttpGet((WEBSERVICE_URL, postalCode))。 try { (TAG, get google39。s weather infomation)。 //發(fā)出請(qǐng)求 HttpResponse response = (request)。 StatusLine status = ()。 第五章 程序開(kāi)發(fā) (TAG, Request returned status + status)。 //取出回復(fù)信息 HttpEntity entity = ()。 responseReader = new InputStreamReader((), GB2312)。 } catch (IOException e) { throw new ForecastParseException(Problem calling forecast API, e)。 } if (responseReader != null) { widgetEntity = parseResponse(responseReader)。 } return widgetEntity。 } (2) 調(diào)用輕量級(jí) XML解析器 XmlPullParser對(duì)從網(wǎng)絡(luò)上獲取的字節(jié)流數(shù)據(jù)進(jìn)行解析,并且將 解析結(jié)果保存在 WidgetEntity對(duì)象中 。核心代碼如下: //返回類型為 WidgetEntity private static WidgetEntity parseResponse(Reader responseReader) throws ForecastParseException { ...... try { //使用工廠類 XmlPullParserFactory來(lái)創(chuàng)建解析器 XmlPullParser XmlPullParserFactory factory = ()。 XmlPullParser xpp = ()。 String tagName = null。 (responseReader)。 int eventType = ()。 while (eventType != ) { if (eventType == ) { tagName = ()。 //根據(jù)不同的標(biāo)簽做不同的解析 if ((tagName)) { throw new ForecastParseException( the city is non correct!)。 } else if ((tagName)) { dealWithInfomation(tagName, widgetEntity, xpp)。 } else if ((tagName)) { dealWithCurrentConditions(tagName, widgetEntity, xpp)。 } else if ((tagName)) { 第五章 程序開(kāi)發(fā) dealWithForecastConditions(tagName, widgetEntity, xpp)。 } } eventType = ()。 } } catch (IOException e) { ...... } return widgetEntity。 } (3) 將 解 析 好 的 數(shù) 據(jù) 存 儲(chǔ) 到 SQLite 數(shù) 據(jù) 庫(kù) 中 。 其 過(guò) 程 是 : 使 用ContentResolver 對(duì)象,通過(guò) URI 間接調(diào)用 ContentProvider, 使用ContentResolver 對(duì)象與 ContentProvider 進(jìn) 行 交 互 , 而ContentResolver則通過(guò) URI確定需要訪問(wèn)的 ContentProvider的數(shù)據(jù)集。核心代碼如下,調(diào)用關(guān)系如圖 。 C o n t e n t P r o v i d e文 件 系 統(tǒng) 數(shù) 據(jù) 庫(kù) 網(wǎng) 絡(luò)C o n t e n t R e s o l v e rU R I 圖 ContentProvider調(diào)用關(guān)系 ContentResolver resolver = ()。 (forecastUri, null, null)。 ContentValues values = new ContentValues()。 for (ForecastEntity forecast : ()) { ()。 (, ())。 ...... (forecastUri, values)。 } 注意: 第五章 程序開(kāi)發(fā) for (ForecastEntity forecast : ())相當(dāng)于 foreach語(yǔ)句,在 ()集合里打印出所有類型為 ForecastEntity的 forecast變量。 讀取天氣數(shù)據(jù)實(shí)例 通過(guò) ()方法 操作數(shù)據(jù)庫(kù)取出所需要的數(shù)據(jù),這一部分與上一節(jié)的“ 將解析好的數(shù)據(jù)存儲(chǔ)到 SQLite數(shù)據(jù)庫(kù)中”的關(guān)鍵點(diǎn)相同,為節(jié)約篇幅,此處不贅 述。 定時(shí)更新時(shí)間。 AppWidget一啟動(dòng)就會(huì)啟動(dòng) ForcastTimeService這個(gè)后臺(tái)服務(wù),此服務(wù)設(shè)置了每隔 20秒刷新一次時(shí)間,“顯示頁(yè)面”通過(guò)這個(gè)后臺(tái)服務(wù)獲取系統(tǒng)時(shí)間從而顯示。核心代碼如下: AlarmManager alarmManager = (AlarmManager)getSystemService()。 (, now + updateMilis, pendingIntent)。 至此,后臺(tái)服務(wù)介紹完畢,最后還需要在 注冊(cè)后臺(tái)服務(wù)。 service android:name=ForecastService/service service android:name=ForecastTimeService/service 用戶界面 在用戶界面設(shè)計(jì)上,采用了 AppWidget框架結(jié)構(gòu),提供直觀的交互操作。三個(gè)用戶界面風(fēng)格簡(jiǎn)約、操作簡(jiǎn)便,用戶體驗(yàn)將非常好。 程序入口類 ForecastWidget ForecastWidget在設(shè)計(jì)上采用了 AppWidget框架結(jié)構(gòu), AppWidget就是HomeScreen上顯示的小部件,通過(guò)在 HomeScreen空白處長(zhǎng)按,在彈出的對(duì)話框中選擇 Widget部件來(lái)進(jìn)行創(chuàng)建。此外,長(zhǎng)按部件后并拖動(dòng)到垃圾箱里進(jìn)行刪除。第五章 程序開(kāi)發(fā) 創(chuàng)建 AppWidget需要以下四個(gè)步驟: (1) 定義 Widget布局文件,此文件是 res/layout/,采用AbsoluteLayout方式進(jìn)行布局 需要注意的是在這個(gè)文件中所使用的組件必須是 RemoteViews所支持的。 (2) 定義 Widget的基本屬性文件,此文件是 /res/xml/。代碼如下: ?xml version= encoding=utf8? appwidgetprovider xmlns:android= android:initialLayout=@layout/weather //Widget的布局文件 //在啟動(dòng)前首先要啟動(dòng) ConfigureActivity進(jìn)行設(shè)置 android:configure= android:minWidth=292dip //定義 Widget組件的寬度 android:minHeight=144dip //定義 Widget組件的高度 android:updatePeriodMillis=0 //更新的時(shí)間周期 /appwidgetprovider (3) 創(chuàng)建 ,此類繼承自 AppWidgetProvider,主要的功能有:獲取需要更新的桌面小控件;啟動(dòng)獲取天氣預(yù)報(bào)信息的服務(wù);啟動(dòng)時(shí)間信息的服務(wù);更新桌面小控件顯示內(nèi)容;更新時(shí)間信息。核心代碼如下: public class ForecastWidget extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) { (context, appWidgetManager, appWidgetIds)。 // 獲取需要更新的桌面小控件 (appWidgetIds)。 // 啟動(dòng)獲取天氣預(yù)報(bào)信息的服務(wù) (new Intent(context, ))。 // 啟動(dòng)時(shí)間信息的服務(wù) (new Intent(context, ))。 } //更新桌面小空間顯示內(nèi)容 public static RemoteViews updateViews(Context context, Uri uri) { } //更新時(shí)間信息 public static RemoteViews updateTime(Context context) { } (4) AppWidgetProvider對(duì)應(yīng)一個(gè) receiver屬性,需要更新 。代碼如下: !receiver字段定義的是 AppWidgetProvider類 — 第五章 程序開(kāi)發(fā) receiver and
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計(jì)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1