Permalink
Browse files

修改列表显示格式以及内容

  • Loading branch information...
1 parent 4229712 commit 7b05ba4f68329630b3db6c0caef19e7eb4cb02a4 @feelinglucky committed Apr 13, 2012
File renamed without changes
@@ -60,24 +60,7 @@ public void onCreate(Bundle savedInstanceState) {
super.initMapActivity(bMapManager);
-// toggleSatelliteButton = (ToggleButton) findViewById(R.id.toggle_satellite_mode);
mapView = (MapView) findViewById(R.id.bmapsView);
-
-
-// toggleSatelliteButton.setOnClickListener(new View.OnClickListener() {
-// @Override
-// public void onClick(View view) {
-// if (toggleSatelliteButton.isChecked()) {
-// toggleSatelliteButton.setChecked(false);
-// mapView.setSatellite(false);
-// } else {
-// toggleSatelliteButton.setChecked(true);
-// mapView.setSatellite(true);
-// }
-// }
-// });
-
-
mapViewController = mapView.getController();
archiveFileName = getIntent().getStringExtra(ARCHIVE_FILE_NAME);
@@ -16,13 +16,14 @@
import com.gracecode.tracker.dao.ArchiveMeta;
import com.gracecode.tracker.service.ArchiveNameHelper;
+import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
public class Records extends Base implements AdapterView.OnItemClickListener {
private Context context;
+ private static final String ARCHIVE_FILE_NAME = "archiveName";
- //
private ListView listView;
private ArrayList<String> archiveFileNames;
private ArrayList<Archive> archives;
@@ -35,7 +36,7 @@
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Archive archive = archives.get(i);
Intent intent = new Intent(this, BaiduMap.class);
- intent.putExtra("archiveName", archive.getArchiveFileName());
+ intent.putExtra(ARCHIVE_FILE_NAME, archive.getArchiveFileName());
startActivity(intent);
}
@@ -60,7 +61,10 @@ public View getView(int position, View convertView, ViewGroup parent) {
TextView descriptionView = (TextView) rowView.findViewById(R.id.description);
TextView betweenView = (TextView) rowView.findViewById(R.id.between);
- countView.setText(String.valueOf(archiveMeta.getCount()));
+ File f = new File(archive.getArchiveFileName());
+ countView.setText(String.format("%.2fm", archiveMeta.getDistance()));
+ betweenView.setText(String.valueOf(archiveMeta.getCount()));
+ nameView.setText(f.getName());
// String description = archiveMeta.getDescription();
// if (description.length() <= 0) {
@@ -86,16 +90,6 @@ public void onCreate(Bundle savedInstanceState) {
this.archiveFileNameHelper = new ArchiveNameHelper(context);
archives = new ArrayList<Archive>();
-// progressDialog = new ProgressDialog(this);
-// progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
-// progressDialog.setMessage(getString(R.string.saving));
-// progressDialog.setCancelable(false);
-//
- // locations = new ArrayList<Location>();
-
-// getStorageDatabases();
-//
-//
}
@@ -18,6 +18,7 @@
protected String archiveName;
public final static class DATABASE_COLUMN {
+ static final String ID = "id";
static final String LATITUDE = "latitude";
static final String LONGITUDE = "longitude";
static final String SPEED = "speed";
@@ -26,7 +27,7 @@
static final String ACCURACY = "accuracy";
static final String TIME = "time";
static final String COUNT = "count";
- static final String META_NAME = "archiveName";
+ static final String META_NAME = "meta";
static final String META_VALUE = "value";
}
@@ -49,7 +50,7 @@
private static final String SQL_CREATE_META_TABLE =
"create table " + ArchiveMeta.TABLE_NAME + " ("
+ "id integer primary key autoincrement, "
- + "archiveName string not null unique,"
+ + "meta string not null unique,"
+ "value string default null"
+ ");";
@@ -1,5 +1,6 @@
package com.gracecode.tracker.dao;
+import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
@@ -17,18 +18,70 @@
protected Archive archive;
private Archive.ArchiveDatabaseHelper databaseHelper;
+ private SQLiteDatabase database;
public ArchiveMeta(Archive archive) {
this.archive = archive;
this.databaseHelper = archive.databaseHelper;
+ this.database = databaseHelper.getWritableDatabase();
}
- public String getDescription() {
- return null;
+
+ protected boolean setMeta(String name, String value) {
+ ContentValues values = new ContentValues();
+ values.put(Archive.DATABASE_COLUMN.META_NAME, name);
+ values.put(Archive.DATABASE_COLUMN.META_VALUE, value);
+
+ long result = 0;
+ try {
+ if (isMetaExists(name)) {
+ result = database.update(TABLE_NAME, values, Archive.DATABASE_COLUMN.META_NAME + "=" + name, null);
+ } else {
+ result = database.insert(TABLE_NAME, null, values);
+ }
+ } catch (SQLiteException e) {
+ Logger.e(e.getMessage());
+ }
+
+ return result > 0 ? true : false;
}
- public boolean setDescription(String description) {
- return false;
+ protected String getMeta(String name) {
+ Cursor cursor;
+ String result = "";
+ try {
+ cursor = database.rawQuery(
+ "SELECT " + Archive.DATABASE_COLUMN.META_VALUE
+ + " FROM " + Archive.TABLE_NAME
+ + " LIMIT 1", null);
+ cursor.moveToFirst();
+
+ result = cursor.getString(cursor.getColumnIndex(Archive.DATABASE_COLUMN.META_VALUE));
+ cursor.close();
+ } catch (SQLiteException e) {
+ Logger.e(e.getMessage());
+ }
+
+ return result;
+ }
+
+ protected boolean isMetaExists(String name) {
+ Cursor cursor;
+ int count = 0;
+ try {
+ cursor = database.rawQuery(
+ "SELECT count(id) AS count"
+ + " FROM " + Archive.TABLE_NAME
+ + " WHERE " + Archive.DATABASE_COLUMN.META_NAME + "=" + name, null);
+ cursor.moveToFirst();
+
+ count = cursor.getInt(cursor.getColumnIndex(Archive.DATABASE_COLUMN.COUNT));
+ cursor.close();
+ } catch (SQLiteException e) {
+ Logger.e(e.getMessage());
+ }
+
+ return count > 0 ? true : false;
}
/**
@@ -53,32 +106,39 @@ public float getDistance() {
}
public Date getStartTime() {
-
- return null;
+ return new Date(getMeta(START_TIME));
}
public Date getEndTime() {
- return null;
+ return new Date(getMeta(END_TIME));
+ }
+ public boolean setStartTime(Date date) {
+ long time = date.getTime();
+ return setMeta(START_TIME, String.valueOf(time));
}
- public boolean setStartTime(Date time) {
+ public boolean setEndTime(Date date) {
+ long time = date.getTime();
+ return setMeta(END_TIME, String.valueOf(time));
+ }
- return false;
+ public String getDescription() {
+ return getMeta(DESCRIPTION);
}
- public boolean setEndTime(Date time) {
- return false;
+ public boolean setDescription(String description) {
+ return setMeta(DESCRIPTION, description);
}
public long getCount() {
Cursor cursor;
long count = 0;
- SQLiteDatabase database = databaseHelper.getReadableDatabase();
-
try {
- cursor = database.rawQuery("SELECT count(id) AS count FROM " + Archive.TABLE_NAME
- + " LIMIT 1", null);
+ cursor = database.rawQuery(
+ "SELECT count(id) AS count FROM "
+ + Archive.TABLE_NAME
+ + " LIMIT 1", null);
cursor.moveToFirst();
count = cursor.getLong(cursor.getColumnIndex(Archive.DATABASE_COLUMN.COUNT));
@@ -17,6 +17,7 @@
import com.gracecode.tracker.util.UIHelper;
import java.io.File;
+import java.util.Date;
/**
*
@@ -53,6 +54,7 @@
public class ServiceBinder extends android.os.Binder implements Binder {
private int status = ServiceBinder.STATUS_STOPPED;
+ private ArchiveMeta meta = null;
ServiceBinder() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
@@ -83,6 +85,12 @@ public void startRecord() {
geoArchive.open(archiveFileName);
archiveFileNameHelper.setLastOpenedArchiveFileName(archiveFileName);
+ // 获取 Meta 信息
+ meta = getArchiveMeta();
+
+ // 设置开始时间
+ meta.setStartTime(new Date());
+
// 绑定 GPS 回调
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
minTime, minDistance, listener);
@@ -104,12 +112,18 @@ public void stopRecord() {
(new File(archiveFileName)).delete();
uiHelper.showLongToast(getString(R.string.not_record_anything));
} else {
+ // 设置结束记录时间
+ meta.setEndTime(new Date());
+
uiHelper.showLongToast(String.format(
getString(R.string.result_report), String.valueOf(totalCount)
));
}
+ // 清除操作
geoArchive.close();
+ meta = null;
+
archiveFileNameHelper.clearLastOpenedArchiveFileName();
status = ServiceBinder.STATUS_STOPPED;
}

0 comments on commit 7b05ba4

Please sign in to comment.