课程设计报告模版.doc_第1页
课程设计报告模版.doc_第2页
课程设计报告模版.doc_第3页
课程设计报告模版.doc_第4页
课程设计报告模版.doc_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

湘南学院课程设计报告课程名称: 嵌入式系统 设计题目: Android 客户端开发 专业班级: 网络工程1班 学生姓名: 欧阳亚平 学生学号: 201114160114 指导老师: 2013年 月 日目 录1概述11.1背景11.2设计要求21.3开发环境31.4关键技术52概要设计82.1软件结构82.2各功能模块设计103详细设计与实现13 3.1界面说明16 3.2程序流程15 3.3关键代码154测试分析184.1测试方法184.2测试用例194.3测试结果195小结19参考文献 24附录(备选)26嵌入式 课程设计报告1 概述通过API接口服务器返回json数据。再将返回来的json数据时行解析,让其显示在手机上。 1.1背景随着手机和互联网的使用越来越普遍,通过手机浏览网页越来来方便,但是如果用手机浏览电脑版网页就会使得用户体验很差,因为手机手频目太小。这样就需要将电脑版网页转化成手机版网页。1.2设计要求 通过API接口访问服务器返回json数据进行解析,得到需要显示手机上的图片或文字。1.3开发环境eclipse插件ADT;1.4关键技术将如下json数据进行解析:2概要设计2.1、软件结构1. 显示网页主界面2. 登入显示已购买商品2.2、各功能模块设计1. 显示网页主界面:2. 登入显示已购买商品3详细设计与实现3.1、界面说明利用android各种控件来布局界面:如TextView,Button,ListView等;3.2、程序流程先调用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 = 0;ByteArrayOutputStream out = new ByteArrayOutputStream();while (len = is.read(data) != -1) out.write(data, 0, len);返回json数据,再对此数据进行处理:for (int i = offset; i totalnumber; +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, 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);最后再显示在手机的界面:ListView.setAdapter(new Adapter);3.3、关键代码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 catalog = null;private Button orderby = null;private ArrayAdapter adapterCatalog = null;private File imagecache;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);Groable.init(this);setContentView(R.layout.activity_main);list = (ListView) findViewById(R.id.list);catalog = (Spinner) findViewById(R.id.catalog);orderby = (Button) findViewById(R.id.order_by);adapterCatalog = ArrayAdapter.createFromResource(this, R.array.catalog,android.R.layout.simple_spinner_item);adapterCatalog.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);catalog.setAdapter(adapterCatalog);catalog.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() 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(正在加载数据,请稍后.);pro.show();Thread t = new Thread() Overridepublic 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.onCreateContextMenu(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.getJSONObject(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, 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 menu) 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, 团购).setIcon(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 onOptionsMenuClosed(Menu menu) super.onOptionsMenuClosed(menu);Overridepublic boolean onPrepareOptionsMenu(Menu menu) return true;Overrideprotected void onDestroy() for (File file : imagecache.listFiles() file.delete();super.onDestroy();public class ProductListAdapter extends BaseAdapter private ListMap allvalues;private Context ctx;private LayoutInflater inflater;private File imagecache;public ProductListAdapter(ListMap allvalues,Context context, File imagecache) this.allvalues = allvalues;this.ctx = context;this.imagecache = imagecache;Overridepublic int getCount() return allvalues.size();Overridepublic Object getItem(int position) return allvalues.get(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 (convertView = 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 = (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, price, 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);contact.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.get(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, imagecache);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 = 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 File imagecache) final Handler handler = new Handler() Overridepublic 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 fileName = new MD5Code().getMD5ofStr(imgurl)+ imgurl.substring(imgurl.lastIndexOf(.);File f = new File(imagecache, fileName);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 FileOutputStream(f);byte data = new byte1024;int len = 0;while (len = is.read(data) != -1) os.write(data, 0, len);Uri uri= 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 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 File imgcache=null;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.getFilesDir().getPath() + /imagecache; File imgcach

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论