Upload
xavier-yin
View
740
Download
0
Embed Size (px)
Citation preview
行動APP開發管理實務實作簡易網路資料瀏覽App
網路資料的擷取與應用 - 使用Volley & GSON
尹君耀 Xavier Yin
課程大綱
簡介環境與控制項
實作需求
網路請求
資料格式與剖析
實作步驟
關於我
尹君耀(Xavier Yin)– 任職:Hiiir 時間軸科技,電子商業事業處
– 職稱:行動軟體工程師
– 專長:
Android App開發
Design pattern
Objected-Oriented development
UML
環境安裝
JDK– Download JDK (or from Oracle)
– Installation and Environment Variable Settings
JAVA_HOME
PATH
Installation result on cmd
Android SDK and Studio– Download Android SDK and Studio (or from Android Developer)
– Installation
Launch the .exe file you just downloaded
Follow the setup wizard
基本元件
Activity
Service
BroadcastReceiver
ContentProvider
控制項
View class– This class represents the basic
building block for user interfacecomponents.
ViewGroup class– The ViewGroup subclass is the base
class for layouts, which are invisiblecontainers that hold other Views (orother ViewGroups) and define theirlayout properties.
控制項
View class– This class represents the basic
building block for user interfacecomponents.
ViewGroup class– The ViewGroup subclass is the base
class for layouts, which are invisiblecontainers that hold other Views (orother ViewGroups) and define theirlayout properties.
控制項
View class– This class represents the basic
building block for user interfacecomponents.
ViewGroup class– The ViewGroup subclass is the base
class for layouts, which are invisiblecontainers that hold other Views (orother ViewGroups) and define theirlayout properties.
網路資源請求和回應
Http Request & Response– org.apache.http.client.methods
HttpGet, HttpPost, HttpPut & HttpDelete
– HttpURLConnection & HttpClient
– Okhttp
– Retrofit
– Volley
Volley
org.apache.http.client.methods, HttpURLConnection & HttpClient– 用法複雜
– 寫出重覆的程式碼
Volley – 處理簡單的HTTP Request
– 下載圖片,但不適合下載多張圖片
– 輕量級的HTTP Request處理工具,但不適合大量數據處理,例如下載文件。
資料格式與剖析工具
XML– XmlPullParser
CSV– 3rd party或檔案剖析
JSON– org.json
實作步驟
開新專案並選擇Navigation Drawer Activity
實作步驟
從Project Structure匯入相關Libs – Volley和Gson
實作步驟
修改專案內容,保留與修改成我們想要的內容– 修改Drawer內的Menu項目
移除main.xml的item – settings
修改activity_main_drawer.xml的item
實作步驟
修改專案內容,保留與修改成我們想要的內容– 修改app_bar_main.xml
刪除FloatingActionButton(若有想要實作,則保留)
實作步驟
修改專案內容,保留與修改成我們想要的內容– 修改nav_header_main.xml
實作步驟
修改專案內容,保留與修改成我們想要的內容– 修改nav_header_main.xml
實作步驟
修改專案內容,保留與修改成我們想要的內容– 修改content_main.xml
實作步驟
修改MainActivity.java– 刪除FloatingActionButton相關程式碼
實作步驟
修改MainActivity.java– 刪除Action Bar的Settings相關程式碼
實作步驟
修改MainActivity.java– 刪除NavigationItem相關程式碼
實作步驟
修改MainActivity.java– 初始Volley的工作佇列
– 產生相對應的UI元件
– 註冊按鈕相關事件
– 呼叫Volley Request元件
實作步驟
初始Volley的工作佇列– 新增initApiRequestQueue()
實作步驟
產生相對應的UI元件– 新增prepareUI ()
實作步驟
註冊按鈕相關事件– 實作button OnclickListener監聽方法
– 新增prepareEvents ()
實作步驟
呼叫Volley Request元件– 新增名為beans的package,並新增一個MyDataResult物件作為Gson剖析後的Bean data。
– 產生StringRequest物件,並實作Listener和ErrorListener方法
– 新增invokeStringRequest ()
實作步驟
在Manifest加上Internet權限
執行程式並觀察結果
Sample Code and Slides
Slides– https://www.slideshare.net/secret/9yOgwb2EjvVOiJ
Sample Code– https://github.com/xavier0507/TKUNetworkInforApp.git