2015高职院校移动互联网应用软件开发赛准备小结

来源:互联网 发布:千岛片淘宝叫什么 编辑:程序博客网 时间:2024/04/30 19:49

http://blog.csdn.net/f5647/article/details/45668265


1.系统设计(略)

2.程序排错(略)

3.功能编码(可以整理)

Ui布局 (简单的 拖动布局)

网络通信(JSON)

       正常流程:根据接口去http请求,得到JSON,发送Handler, 接收数据反映到界面。

       通用的post请求

[java] view plain copy
  1. /** 
  2.      * 通用的post请求 
  3.      *  
  4.      * @param url 
  5.      *            接口地址 
  6.      * @param params 
  7.      *            传参数和值的map集合 
  8.      * @return json 字符串 
  9.      */  
  10.     public static String generalPost(String url, Map<String, String> params) {  
  11.         HttpPost request = new HttpPost(url);  
  12.         // 创建HTTP POST请求  
  13.         try {  
  14.             JSONObject jsonRequest = new JSONObject();  
  15.             if (params != null) {  
  16.                 for (String key : params.keySet()) {  
  17.                     jsonRequest.put(key, params.get(key));  
  18.                 }  
  19.             }  
  20.             // map-->json-->stringentity  
  21.             StringEntity se = new StringEntity(jsonRequest.toString());  
  22.             request.setEntity(se);  
  23.             HttpResponse httpResponse = new DefaultHttpClient()  
  24.                     .execute(request);  
  25.             String retSrc = EntityUtils.toString(httpResponse.getEntity());  
  26.             return retSrc;  
  27.         } catch (UnsupportedEncodingException e) {  
  28.             e.printStackTrace();  
  29.         } catch (ClientProtocolException e) {  
  30.             e.printStackTrace();  
  31.         } catch (ParseException e) {  
  32.             e.printStackTrace();  
  33.         } catch (JSONException e) {  
  34.             e.printStackTrace();  
  35.         } catch (IOException e) {  
  36.             e.printStackTrace();  
  37.         }  
  38.         return "";  
  39.     }  

[java] view plain copy
  1. /** 
  2.      * 通用JSON解析 
  3.      *  
  4.      * @param jsonString   JSON数据 
  5.      *  
  6.      * @param keyString  返回key 
  7.      *             
  8.      * @return 
  9.      */  
  10.     public String backJson(String jsonString, String keyString) {  
  11.         String val = null;  
  12.         try {  
  13.             JSONObject jsonResponse = new JSONObject(jsonString);  
  14.             val = jsonResponse.getString(keyString);  
  15.         } catch (JSONException e) {  
  16.             // TODO Auto-generated catch block  
  17.             e.printStackTrace();  
  18.         }  
  19.         return val;  
  20.     }  

内容推送(Notification)

[java] view plain copy
  1. /** 
  2.      * 在状态栏显示通知 
  3.      *  
  4.      * 加权限 <uses-permission android:name="android.permission.VIBRATE" /> 
  5.      *  
  6.      */  
  7.     private void showNotification() {  
  8.         // 创建一个NotificationManager的引用  
  9.         NotificationManager notificationManager = (NotificationManager) this  
  10.                 .getSystemService(android.content.Context.NOTIFICATION_SERVICE);  
  11.   
  12.         // 定义Notification的各种属性  
  13.         Notification notification = new Notification(R.drawable.ic_launcher,  
  14.                 "测试系统", System.currentTimeMillis());  
  15.         // FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉  
  16.         // FLAG_NO_CLEAR 该通知不能被状态栏的清除按钮给清除掉  
  17.         // FLAG_ONGOING_EVENT 通知放置在正在运行  
  18.         // FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应  
  19.         notification.flags |= Notification.FLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中  
  20.         notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用  
  21.         notification.flags |= Notification.FLAG_SHOW_LIGHTS;  
  22.         // DEFAULT_ALL 使用所有默认值,比如声音,震动,闪屏等等  
  23.         // DEFAULT_LIGHTS 使用默认闪光提示  
  24.         // DEFAULT_SOUNDS 使用默认提示声音  
  25.         // DEFAULT_VIBRATE 使用默认手机震动,需加上<uses-permission  
  26.         notification.defaults = Notification.DEFAULT_LIGHTS;  
  27.         // 叠加效果常量  
  28.         // notification.defaults=Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND;  
  29.         notification.ledARGB = Color.BLUE;  
  30.         notification.ledOnMS = 5000// 闪光时间,毫秒  
  31.   
  32.         // 设置通知的事件消息  
  33.         CharSequence contentTitle = "测试系统标题"// 通知栏标题  
  34.         CharSequence contentText = "测试系统内容"// 通知栏内容  
  35.         Intent notificationIntent = new Intent(MainActivity.this,  
  36.                 MainActivity.class); // 点击该通知后要跳转的Activity  
  37.         PendingIntent contentItent = PendingIntent.getActivity(this0,  
  38.                 notificationIntent, 0);  
  39.         notification.setLatestEventInfo(this, contentTitle, contentText,  
  40.                 contentItent);  
  41.   
  42.         // 把Notification传递给NotificationManager  
  43.         notificationManager.notify(0, notification);  
  44.     }  
  45.   
  46.     // 删除通知  
  47.     private void clearNotification() {  
  48.         // 启动后删除之前我们定义的通知  
  49.         NotificationManager notificationManager = (NotificationManager) this  
  50.                 .getSystemService(NOTIFICATION_SERVICE);  
  51.         notificationManager.cancel(0);  
  52.   
  53.     }  


数据图表展现(折线图)

          android画图 常用的是第三方常用的开源类库,例子:点击打开链接, 非常简单好用。但是估计比赛时,不一定会给开源jar包,所以得自己画图,比较复杂 例子:点击打            开链接

本地数据库(Sqlite)

[java] view plain copy
  1. //打开或创建test.db数据库  
  2.             SQLiteDatabase db = openOrCreateDatabase("test.db", Context.MODE_PRIVATE, null);  
  3.             db.execSQL("DROP TABLE IF EXISTS person");  
  4.             //创建person表  
  5.             db.execSQL("CREATE TABLE person (_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLINT)");  
  6.             //实体类  
  7.             Person person = new Person();  
  8.             person.name = "john";  
  9.             person.age = 30;  
  10.             //插入数据  
  11.             db.execSQL("INSERT INTO person VALUES (NULL, ?, ?)"new Object[]{person.name, person.age});  
  12.             //添加、更新和删除  
  13. //          db.executeSQL(String sql);  
  14. //          db.executeSQL(String sql, Object[] bindArgs);//sql语句,然后第二个参数是实际的参数集           
  15.             //查询数据  
  16.             Cursor c = db.rawQuery("SELECT * FROM person WHERE age >= ?"new String[]{"33"});  
  17.             while (c.moveToNext()) {  
  18.                 int _id = c.getInt(c.getColumnIndex("_id"));  
  19.                 String name = c.getString(c.getColumnIndex("name"));  
  20.                 int age = c.getInt(c.getColumnIndex("age"));  
  21.                 Log.i("db""_id=>" + _id + ", name=>" + name + ", age=>" + age);  
  22.             }  
  23.             c.close();  
  24.               
  25.               
  26.             //关闭当前数据库  
  27.             db.close();  


原创粉丝点击