1.系统设计(略)
2.程序排错(略)
3.功能编码(可以整理)
Ui布局 (简单的 拖动布局)
网络通信(JSON)
正常流程:根据接口去http请求,得到JSON,发送Handler, 接收数据反映到界面。
通用的post请求
/**
* 通用的post请求
*
* @param url
* 接口地址
* @param params
* 传参数和值的map集合
* @return json 字符串
*/
public static String generalPost(String url, Map<String, String> params) {
HttpPost request = new HttpPost(url);
// 创建HTTP POST请求
try {
JSONObject jsonRequest = new JSONObject();
if (params != null) {
for (String key : params.keySet()) {
jsonRequest.put(key, params.get(key));
}
}
// map-->json-->stringentity
StringEntity se = new StringEntity(jsonRequest.toString());
request.setEntity(se);
HttpResponse httpResponse = new DefaultHttpClient()
.execute(request);
String retSrc = EntityUtils.toString(httpResponse.getEntity());
return retSrc;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
/**
* 通用JSON解析
*
* @param jsonString JSON数据
*
* @param keyString 返回key
*
* @return
*/
public String backJson(String jsonString, String keyString) {
String val = null;
try {
JSONObject jsonResponse = new JSONObject(jsonString);
val = jsonResponse.getString(keyString);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return val;
}
内容推送(Notification)
/**
* 在状态栏显示通知
*
* 加权限 <uses-permission android:name="android.permission.VIBRATE" />
*
*/
private void showNotification() {
// 创建一个NotificationManager的引用
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
// 定义Notification的各种属性
Notification notification = new Notification(R.drawable.ic_launcher,
"测试系统", System.currentTimeMillis());
// FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉
// FLAG_NO_CLEAR 该通知不能被状态栏的清除按钮给清除掉
// FLAG_ONGOING_EVENT 通知放置在正在运行
// FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应
notification.flags |= Notification.FLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中
notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// DEFAULT_ALL 使用所有默认值,比如声音,震动,闪屏等等
// DEFAULT_LIGHTS 使用默认闪光提示
// DEFAULT_SOUNDS 使用默认提示声音
// DEFAULT_VIBRATE 使用默认手机震动,需加上<uses-permission
notification.defaults = Notification.DEFAULT_LIGHTS;
// 叠加效果常量
// notification.defaults=Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 5000; // 闪光时间,毫秒
// 设置通知的事件消息
CharSequence contentTitle = "测试系统标题"; // 通知栏标题
CharSequence contentText = "测试系统内容"; // 通知栏内容
Intent notificationIntent = new Intent(MainActivity.this,
MainActivity.class); // 点击该通知后要跳转的Activity
PendingIntent contentItent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(this, contentTitle, contentText,
contentItent);
// 把Notification传递给NotificationManager
notificationManager.notify(0, notification);
}
// 删除通知
private void clearNotification() {
// 启动后删除之前我们定义的通知
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(0);
}
数据图表展现(折线图)
android画图 常用的是第三方常用的开源类库,例子:点击打开链接, 非常简单好用。但是估计比赛时,不一定会给开源jar包,所以得自己画图,比较复杂 例子:点击打 开链接
本地数据库(Sqlite)
//打开或创建test.db数据库
SQLiteDatabase db = openOrCreateDatabase("test.db", Context.MODE_PRIVATE, null);
db.execSQL("DROP TABLE IF EXISTS person");
//创建person表
db.execSQL("CREATE TABLE person (_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLINT)");
//实体类
Person person = new Person();
person.name = "john";
person.age = 30;
//插入数据
db.execSQL("INSERT INTO person VALUES (NULL, ?, ?)", new Object[]{person.name, person.age});
//添加、更新和删除
// db.executeSQL(String sql);
// db.executeSQL(String sql, Object[] bindArgs);//sql语句,然后第二个参数是实际的参数集
//查询数据
Cursor c = db.rawQuery("SELECT * FROM person WHERE age >= ?", new String[]{"33"});
while (c.moveToNext()) {
int _id = c.getInt(c.getColumnIndex("_id"));
String name = c.getString(c.getColumnIndex("name"));
int age = c.getInt(c.getColumnIndex("age"));
Log.i("db", "_id=>" + _id + ", name=>" + name + ", age=>" + age);
}
c.close();
//关闭当前数据库
db.close();