private void initView() { findViewById(R.id.title_back) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { finish(); } }); if (list == null) list = new ArrayList<LocationBean>(); dp = new DBHelper(this); dp.deleteTable(3); cursor = dp.query("SELECT * FROM " + DBHelper.TABLENAME, null); int count = cursor.getCount(); if (count == 0) return; for (int i = 0; i < count; i++) { LocationBean a = new LocationBean(); cursor.moveToPosition(i); final String tableName = cursor.getString(0); final String describe = cursor.getString(3); final String time = cursor.getString(4); a.setTableName(tableName); a.setDescribe(describe); a.setTime(time); list.add(a); } uploadAdapter = new UploadAdapter(this, list); ((ListView) findViewById(R.id.upload_list)).setAdapter(uploadAdapter); }
private void getdate(String name) { // address, event, starttime, endtime; Cursor cursor = null; cursor = dp.query( "SELECT * FROM " + DBHelper.TABLENAME + " WHERE tablename= " + "\"" + name + "\"", null); if (cursor.getCount() == 0) return; cursor.moveToPosition(0); eventid = cursor.getString(2); eventcon = cursor.getString(3); starttime = cursor.getString(4); endtime = cursor.getString(5); duration = cursor.getString(6); }
private void refresh() { cursor = null; cursor = dp.query("SELECT * FROM " + DBHelper.TABLENAME + " WHERE Artificial = 2", null); list.clear(); int count = cursor.getCount(); for (int i = 0; i < count; i++) { LocationBean a = new LocationBean(); cursor.moveToPosition(i); final String tableName = cursor.getString(0); final String describe = cursor.getString(3); final String time = cursor.getString(4); a.setTableName(tableName); a.setDescribe(describe); a.setTime(time); list.add(a); } uploadAdapter.setdata(list); uploadAdapter.notifyDataSetInvalidated(); }
private void updata(final String name) { if (datalist == null) datalist = new ArrayList<LocationBean>(); datalist.clear(); getdate(name); cursor = null; cursor = dp.query("SELECT * FROM " + name, null); List<LatLng> pts = new ArrayList<LatLng>(); LocationBean a = null; double speedlist[] = new double[cursor.getCount()]; for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); String time = cursor.getString(1); double speed = cursor.getDouble(2); double Latitude = cursor.getDouble(3); double Longitude = cursor.getDouble(4); int pathType = cursor.getInt(5); LatLng pt = new LatLng(Latitude, Longitude); pts.add(pt); speedlist[i] = speed; a = new LocationBean(); a.setLatitude(Latitude); a.setLongitude(Longitude); a.setSpeed(speed); a.setTime(time); a.setPathType(pathType); if (i == 0) { start_point = Longitude + "," + Latitude; } datalist.add(a); } end_point = a.getLongitude() + "," + a.getLatitude(); countDiatance(pts, speedlist); String jsondata = toJson2(datalist); RequestParams param = new RequestParams(); String tokenId = SharedPreferenceUtil.getValue( PreferenceConstant.MARK_ID_TABLE, PreferenceConstant.MARK_ID, UploadedOfflineActivity.this); param.put("token_id", tokenId); param.put("json", jsondata); HttpClient.post( UploadedOfflineActivity.this, ActionUrl.TRAFECTORY, param, new MyAsyncHttpResponseHandler(UploadedOfflineActivity.this, "上传中,请稍后...") { public void onSuccess(String results) { super.onSuccess(results); try { JSONObject jsonObject = new JSONObject(results); if (jsonObject.has("msg")) { String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg"); if (msg.equals("保存成功")) { Toast.makeText(UploadedOfflineActivity.this, "上传成功了", Toast.LENGTH_SHORT).show(); dp.dropTable(name); dp.updateTable(3, name); refresh(); } else { Toast.makeText(UploadedOfflineActivity.this, "上传失败", Toast.LENGTH_SHORT).show(); } } } catch (JSONException e) { e.printStackTrace(); } } public void onFailure(Throwable arg0, String tipInfo) { super.onFailure(arg0, tipInfo); } }); }