課程設(shè)計報告模版_第1頁
課程設(shè)計報告模版_第2頁
課程設(shè)計報告模版_第3頁
課程設(shè)計報告模版_第4頁
課程設(shè)計報告模版_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、湘南學(xué)院課程設(shè)計報告課程名稱: 嵌入式系統(tǒng) 設(shè)計題目: Android 客戶端開發(fā) 專業(yè)班級: 網(wǎng)絡(luò)工程1班 學(xué)生姓名: 歐陽亞平 學(xué)生學(xué)號: 2 指導(dǎo)老師: 2013年 月 日目 錄1概述11.1背景11.2設(shè)計要求21.3開發(fā)環(huán)境31.4關(guān)鍵技術(shù)52概要設(shè)計82.1軟件結(jié)構(gòu)82.2各功能模塊設(shè)計103詳細設(shè)計與實現(xiàn)13 3.1界面說明16 3.2程序流程15 3.3關(guān)鍵代碼154測試分析184.1測試方法184.2測試用例194.3測試結(jié)果195小結(jié)19參考文獻 24附錄(備選)2624 / 26文檔可自由編輯打印1 概述通過API接口服務(wù)器返回json數(shù)據(jù)。再將返回來的json數(shù)據(jù)時行解

2、析,讓其顯示在手機上。 1.1背景隨著手機和互聯(lián)網(wǎng)的使用越來越普遍,通過手機瀏覽網(wǎng)頁越來來方便,但是如果用手機瀏覽電腦版網(wǎng)頁就會使得用戶體驗很差,因為手機手頻目太小。這樣就需要將電腦版網(wǎng)頁轉(zhuǎn)化成手機版網(wǎng)頁。1.2設(shè)計要求 通過API接口訪問服務(wù)器返回json數(shù)據(jù)進行解析,得到需要顯示手機上的圖片或文字。1.3開發(fā)環(huán)境eclipse插件ADT;1.4關(guān)鍵技術(shù)將如下json數(shù)據(jù)進行解析:2概要設(shè)計2.1、軟件結(jié)構(gòu)1. 顯示網(wǎng)頁主界面2. 登入顯示已購買商品2.2、各功能模塊設(shè)計1. 顯示網(wǎng)頁主界面:2. 登入顯示已購買商品3詳細設(shè)計與實現(xiàn)3.1、界面說明利用android各種控件來布局界面:如Te

3、xtView,Button,ListView等;3.2、程序流程先調(diào)用api接口:URL url=new URL(urls);HttpURLConnection conn=(HttpURLConnection)url.openConnection();String result=;int responseCode = conn.getResponseCode();if (responseCode = HttpURLConnection.HTTP_OK) InputStream is = conn.getInputStream();byte data = new byte1024;int len

4、 = 0;ByteArrayOutputStream out = new ByteArrayOutputStream();while (len = is.read(data) != -1) out.write(data, 0, len);返回json數(shù)據(jù),再對此數(shù)據(jù)進行處理:for (int i = offset; i totalnumber; +i) JSONObject obj = data.getJSONObject(i);JSONObject partner = obj.getJSONObject(partner);Map map = new HashMap();map.put(con

5、tact, partner.get(contact).toString();map.put(title, obj.get(title).toString();map.put(image, obj.get(image).toString();map.put(team_price, obj.get(team_price).toString();map.put(market_price, obj.get(market_price).toString();map.put(now_number, obj.get(now_number).toString() + 人);allvalues.add(map)

6、;最后再顯示在手機的界面:ListView.setAdapter(new Adapter);3.3、關(guān)鍵代碼1. public class MainActivity extends Activity private ListView list = null;private TextView footView = null;private Handler handler = null;private ProductListAdapter adapter = null;private ListMap allvalues = new ArrayListMap();private Spinner ca

7、talog = null;private Button orderby = null;private ArrayAdapter adapterCatalog = null;private ;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);Groable.init(this);setContentView(R.layout.activity_main);list = (ListView) findViewById(R.id.list);catalog = (

8、Spinner) findViewByItalog);orderby = (Button) findViewById(R.id.order_by);adapterCatalog = ArrayAdapter.createFromResource(this, talog,android.R.layout.simple_spinner_item);adapterCatalog.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);catalog.setAdapter(adapterCatalog);catalo

9、g.setPrompt(請選擇類別);super.registerForContextMenu(this.orderby);footView = new TextView(this);footView.setTextSize(20);footView.setTextColor(Color.WHITE);footView.setGravity(Gravity.CENTER);footView.setText(正在查詢,請稍候.);list.addFooterView(footView);imagecache = new File(/sdcard);if (!imagecache.exists()

10、 imagecache.mkdirs();handler = new Handler() Overridepublic void handleMessage(Message msg) if (msg.what = 0) list.setAdapter(adapter); else ;final ProgressDialog pro = new ProgressDialog(MainActivity.this);pro.setTitle(提示);pro.setMessage(正在加載數(shù)據(jù),請稍后.);pro.show();Thread t = new Thread() Overridepubli

11、c void run() try loadData();adapter = new ProductListAdapter(allvalues,MainActivity.this, imagecache); catch (Exception e) e.printStackTrace();handler.sendEmptyMessage(0);pro.dismiss();t.start();Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) super.onCreate

12、ContextMenu(menu, v, menuInfo);menu.setHeaderTitle(排序);super.getMenuInflater().inflate(R.menu.order_by, menu);public void loadData() throws Exception String results = Groable.getUrlResult(Groable.BASE_URL+ Tuan/goodsList);JSONObject root = new JSONObject(results);JSONObject result = root.getJSONObje

13、ct(result);JSONArray data = result.getJSONArray(data);System.out.println(data.toString();for (int i = 0; i data.length(); +i) JSONObject obj = data.getJSONObject(i);JSONObject partner = obj.getJSONObject(partner);Map map = new HashMap();map.put(contact, partner.get(contact).toString();map.put(title,

14、 obj.get(title).toString();map.put(image, obj.get(image).toString();map.put(team_price, obj.get(team_price).toString();map.put(market_price, obj.get(market_price).toString();map.put(now_number, obj.get(now_number).toString() + 人);allvalues.add(map);Overridepublic boolean onCreateOptionsMenu(Menu men

15、u) menu.add(menu.NONE, menu.FIRST + 1, 1, 團購).setIcon(android.R.drawable.ic_menu_edit);menu.add(menu.NONE, menu.FIRST + 2, 2, 周邊).setIcon(android.R.drawable.ic_menu_view);menu.add(menu.NONE, menu.FIRST + 3, 3, 團購券).setIcon(android.R.drawable.ic_menu_save);menu.add(menu.NONE, menu.FIRST + 4, 4, 團購).s

16、etIcon(android.R.drawable.ic_menu_more);return true;Overridepublic boolean onOptionsItemSelected(MenuItem item) switch (item.getItemId() case Menu.FIRST + 3:Intent it = new Intent(MainActivity.this, Login.class);MainActivity.this.startActivity(it);break;return false;Overridepublic void onOptionsMenu

17、Closed(Menu menu) super.onOptionsMenuClosed(menu);Overridepublic boolean onPrepareOptionsMenu(Menu menu) return true;Overrideprotected void onDestroy() for ( : imagecache.listFiles() ();super.onDestroy();public class ProductListAdapter extends BaseAdapter private ListMap allvalues;private Context ct

18、x;private LayoutInflater inflater;private ;public ProductListAdapter(ListMap allvalues,Context context, ) this.allvalues = allvalues;this.ctx = context;this.imagecache = imagecache;Overridepublic int getCount() return allvalues.size();Overridepublic Object getItem(int position) return allvalues.get(

19、position);Overridepublic long getItemId(int position) return position;Overridepublic View getView(int position, View convertView, ViewGroup parent) TextView contact = null;TextView title = null;TextView price = null;TextView marketprice = null;TextView now_number = null;ImageView image = null;if (co

20、nvertView = null) inflater = (LayoutInflater) ctx.getSystemService(ctx.LAYOUT_INFLATER_SERVICE);convertView = inflater.inflate(R.duct_list_line, null);contact = (TextView) convertView.findViewById(R.duct_contact);title = (TextView) convertView.findViewById(R.duct_title);price =

21、 (TextView) convertView.findViewById(R.id.team_price);marketprice = (TextView) convertView.findViewById(R.id.market_price);now_number = (TextView) convertView.findViewById(R.id.now_number);image = (ImageView) convertView.findViewById(R.ductimage);convertView.setTag(new DataWrap(image, title, p

22、rice, marketprice,contact, now_number); else DataWrap datawrap = (DataWrap) convertView.getTag();contact = datawrap.contact;title = datawrap.title;price = datawrap.price;now_number = datawrap.now_number;marketprice = datawrap.marketprice;image = datawrap.image;Map map = allvalues.get(position);conta

23、ct.getLayoutParams().height = Groable.SCREEN_HEIGHT / 20;title.getLayoutParams().height = Groable.SCREEN_HEIGHT / 10;price.getLayoutParams().height = Groable.SCREEN_HEIGHT / 20;image.getLayoutParams().height = Groable.SCREEN_HEIGHT / 5;title.setText(map.get(title).toString();price.setText(¥ + map.ge

24、t(team_price).toString();marketprice.setText(/ + map.get(market_price).toString();now_number.setText(map.get(now_number).toString();contact.setText(map.get(contact).toString();String imageurl = (String) map.get(image);DownloadImageUtils.setImageUrl(Groable.UPLOAD_URL + imageurl, image,imageurl, imag

25、ecache);return convertView;private final class DataWrap ImageView image;TextView title;TextView price;TextView marketprice;TextView contact;TextView now_number;public DataWrap(ImageView image, TextView title, TextView price,TextView marketprice, TextView contact, TextView now_number) this.contact =

26、contact;this.image = image;this.marketprice = marketprice;this.now_number = now_number;this.price = price;this.title = title;public class DownloadImageUtils public static void setImageUrl(final String url, final ImageView img,final String imgurl, final ) final Handler handler = new Handler() Overrid

27、epublic void handleMessage(Message msg) Uri uri = (Uri) msg.obj;if (uri != null & img != null) img.setImageURI(uri);System.out.println();Thread t = new Thread() Overridepublic void run() Message msg = new Message();String = new MD5Code().getMD5ofStr(imgurl)+ imgurl.substring(imgurl.lastIndexOf(.);Fi

28、le f = new , );InputStream is = null;OutputStream os = null;/ OutputStream os = null;try if (f.exists() msg.what = 1;msg.obj = Uri.fromFile(f); else is = Groable.getUrlInputStream(url);os = new (f);byte data = new byte1024;int len = 0;while (len = is.read(data) != -1) os.write(data, 0, len);Uri uri=

29、 Uri.fromFile(f);msg.what = 1;msg.obj =uri;handler.sendMessage(msg); catch (Exception e) e.printStackTrace(); finally try if (is != null & os != null) is.close();os.close(); catch (Exception e) e.printStackTrace();t.start(); public class Groable public static String BASE_URL=*; public static String

30、WELCOME_URL=BASE_URL+?s=Tuan/goodsList;public static int SCREEN_WIDTH;public static int SCREEN_HEIGHT;public static String CACHE_IMAGE_DIR;public static String UPLOAD_URL=*;public static ;public static void init(Activity a)SCREEN_HEIGHT=a.getWindowManager().getDefaultDisplay().getHeight();SCREEN_WIDTH=a.getWindowManager().getDefaultDisplay().getWidth();System.out.println(Environment.getExternalStorageState()+yaping);CACHE_IMAGE_DIR=a.get().getPath() + /im

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論