Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[issue #87] changed handling of trackpoint updates in Map view to imp…

…rove performance. Thanks to Paul O'Shea.
  • Loading branch information...
commit 8d4da22441bc5738031c1cc1fe77b5b11b347146 1 parent 6a40e00
Matthias Glaub authored
View
4 AUTHORS
@@ -13,3 +13,7 @@ Matthias Glaub <matthias.glaub at googlemail.com>
Jeremy D Monin <jdmonin at nand.net>
- Help for multi-track ability.
- Various patches and bug fixes.
+
+ Paul O'Shea
+ - Various patches and bug fixes
+
View
54 src/me/guillaumin/android/osmtracker/activity/DisplayTrackMap.java
@@ -1,5 +1,8 @@
package me.guillaumin.android.osmtracker.activity;
+import java.util.ArrayList;
+import java.util.List;
+
import me.guillaumin.android.osmtracker.R;
import me.guillaumin.android.osmtracker.db.TrackContentProvider;
import me.guillaumin.android.osmtracker.db.TrackContentProvider.Schema;
@@ -88,6 +91,13 @@
private GeoPoint currentPosition;
/**
+ * The row id of the last location read from the database that has been added to the
+ * list of layout points. Using this we to reduce DB load by only reading new points.
+ * Initially null, to indicate that no data has yet been read.
+ */
+ private Integer lastTrackPointIdProcessed = null;
+
+ /**
* Observes changes on trackpoints
*/
private ContentObserver trackpointContentObserver;
@@ -153,6 +163,11 @@ protected void onResume() {
TrackContentProvider.trackPointsUri(currentTrackId),
true, trackpointContentObserver);
+ // Forget the last waypoint read from the DB
+ // This ensures that all waypoints for the track will be reloaded
+ // from the database to populate the path layout
+ lastTrackPointIdProcessed = null;
+
// Reload path
pathChanged();
@@ -242,22 +257,45 @@ private void pathChanged() {
return;
}
- // Update only the new points
+ // Projection: The columns to retrieve. Here, we want the latitude,
+ // longitude and primary key only
+ String[] projection = {Schema.COL_LATITUDE, Schema.COL_LONGITUDE, Schema.COL_ID};
+ // Selection: The where clause to use
+ String selection = null;
+ // SelectionArgs: The parameter replacements to use for the '?' in the selection
+ String[] selectionArgs = null;
+
+ // Only request the track points that we have not seen yet
+ // If we have processed any track points in this session then
+ // lastTrackPointIdProcessed will not be null. We only want
+ // to see data from rows with a primary key greater than lastTrackPointIdProcessed
+ if (lastTrackPointIdProcessed != null) {
+ selection = TrackContentProvider.Schema.COL_ID + " > ?";
+ List<String> selectionArgsList = new ArrayList<String>();
+ selectionArgsList.add(lastTrackPointIdProcessed.toString());
+
+ selectionArgs = selectionArgsList.toArray(new String[1]);
+ }
+
+ // Retrieve any points we have not yet seen
Cursor c = getContentResolver().query(
TrackContentProvider.trackPointsUri(currentTrackId),
- null, null, null, TrackContentProvider.Schema.COL_TIMESTAMP + " asc");
- int existingPoints = pathOverlay.getNumberOfPoints();
+ projection, selection, selectionArgs, Schema.COL_ID + " asc");
- // Process only if we have data, and new data only
- if (c.getCount() > 0 && c.getCount() > existingPoints) {
- c.moveToPosition(existingPoints);
+ int numberOfPointsRetrieved = c.getCount();
+ if (numberOfPointsRetrieved > 0 ) {
+ c.moveToFirst();
double lastLat = 0;
double lastLon = 0;
+ int primaryKeyColumnIndex = c.getColumnIndex(Schema.COL_ID);
+ int latitudeColumnIndex = c.getColumnIndex(Schema.COL_LATITUDE);
+ int longitudeColumnIndex = c.getColumnIndex(Schema.COL_LONGITUDE);
// Add each new point to the track
while(!c.isAfterLast()) {
- lastLat = c.getDouble(c.getColumnIndex(Schema.COL_LATITUDE));
- lastLon = c.getDouble(c.getColumnIndex(Schema.COL_LONGITUDE));
+ lastLat = c.getDouble(latitudeColumnIndex);
+ lastLon = c.getDouble(longitudeColumnIndex);
+ lastTrackPointIdProcessed = c.getInt(primaryKeyColumnIndex);
pathOverlay.addPoint((int)(lastLat * 1e6), (int)(lastLon * 1e6));
c.moveToNext();
}
View
26 src/me/guillaumin/android/osmtracker/db/TrackContentProvider.java
@@ -1,5 +1,8 @@
package me.guillaumin.android.osmtracker.db;
+import java.util.ArrayList;
+import java.util.List;
+
import me.guillaumin.android.osmtracker.OSMTracker;
import android.content.ContentProvider;
import android.content.ContentResolver;
@@ -196,6 +199,7 @@ public Uri insert(Uri uri, ContentValues values) {
return null;
}
+
@Override
public Cursor query(Uri uri, String[] projection, String selectionIn, String[] selectionArgsIn, String sortOrder) {
Log.v(TAG, "query(), uri=" + uri);
@@ -207,14 +211,26 @@ public Cursor query(Uri uri, String[] projection, String selectionIn, String[] s
// Select which datatype was requested
switch (uriMatcher.match(uri)) {
case Schema.URI_CODE_TRACK_TRACKPOINTS:
- if (selectionIn != null || selectionArgsIn != null) {
- // Any selection/selectionArgs will be ignored
- throw new UnsupportedOperationException();
- }
String trackId = uri.getPathSegments().get(1);
qb.setTables(Schema.TBL_TRACKPOINT);
selection = Schema.COL_TRACK_ID + " = ?";
- selectionArgs = new String[] {trackId};
+ // Deal with any additional selection info provided by the caller
+ if (null != selectionIn) {
+ selection += " AND " + selectionIn;
+ }
+
+ List<String> selctionArgsList = new ArrayList<String>();
+ selctionArgsList.add(trackId);
+ // Add the callers selection arguments, if any
+ if (null != selectionArgsIn) {
+ for (String arg : selectionArgsIn) {
+ selctionArgsList.add(arg);
+ }
+ }
+ selectionArgs = selctionArgsList.toArray(new String[0]);
+ // Finished with the temporary selection arguments list. release it for GC
+ selctionArgsList.clear();
+ selctionArgsList = null;
break;
case Schema.URI_CODE_TRACK_WAYPOINTS:
if (selectionIn != null || selectionArgsIn != null) {
Please sign in to comment.
Something went wrong with that request. Please try again.