diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml
index d5a7c09ca..5f52f7262 100755
--- a/MyTracks/AndroidManifest.xml
+++ b/MyTracks/AndroidManifest.xml
@@ -158,11 +158,9 @@ limitations under the License.
-
diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java
index bf04eb8c6..2dd891ac2 100644
--- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java
+++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java
@@ -315,6 +315,13 @@ public interface MyTracksProviderUtils {
* A lightweight wrapper around the original {@link Cursor} with a method to clean up.
*/
interface LocationIterator extends Iterator {
+ /**
+ * Returns ID of the most recently retrieved track point through a call to {@link #next()}.
+ *
+ * @return the ID of the most recent track point ID.
+ */
+ long getLocationId();
+
/**
* Should be called in case the underlying iterator hasn't reached the last record.
*/
@@ -336,8 +343,7 @@ public interface MyTracksProviderUtils {
}
/**
- * The default {@class Location}s factory, which creates a new location of 'gps' type each
- * time the user advances to the next element using {@link LocationIterator#next()} method.
+ * The default {@class Location}s factory, which creates a new location of 'gps' type.
*/
LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() {
@Override
@@ -352,7 +358,11 @@ public interface MyTracksProviderUtils {
* limitations. Since it's a read-only iterator, {@link Iterator#remove()} always throws
* {@class UnsupportedOperationException}.
*
- * Once constructed, the user must call {@link LocationIterator#close()} to make sure that all
+ * Each call to {@link LocationIterator#next()} may advance to the next DB record, and if so,
+ * the iterator calls {@link LocationFactory#createLocation()} and populates it with information
+ * retrieved from the record.
+ *
+ * When done with iteration, you must call {@link LocationIterator#close()} to make sure that all
* resources are properly deallocated.
*
* Example use:
@@ -371,10 +381,16 @@ public interface MyTracksProviderUtils {
*
*
* @param trackId the ID of a track to retrieve locations for.
+ * @param startTrackPointId the ID of the first track point to load, or -1 to start from
+ * the first point.
+ * @param descending if true the results will be returned in descending ID
+ * order (latest location first).
* @param locationFactory the factory for creating new locations.
+ *
* @return the read-only iterator over the given track's points.
*/
- LocationIterator getLocationIterator(long trackId, LocationFactory locationFactory);
+ LocationIterator getLocationIterator(long trackId, long startTrackPointId, boolean descending,
+ LocationFactory locationFactory);
/**
* A factory which can produce instances of {@link MyTracksProviderUtils},
diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java
index 428a59c5c..4893f8d05 100644
--- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java
+++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java
@@ -937,16 +937,16 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
}
@Override
- public LocationIterator getLocationIterator(final long trackId,
- final LocationFactory locationFactory) {
+ public LocationIterator getLocationIterator(final long trackId, final long startTrackPointId,
+ final boolean descending, final LocationFactory locationFactory) {
return new LocationIterator() {
- private long lastTrackPointId = -1;
+ private long lastTrackPointId = startTrackPointId - 1;
private Cursor cursor = getCursor();
private final int idColumnIdx = cursor != null ?
cursor.getColumnIndexOrThrow(TrackPointsColumns._ID) : -1;
private Cursor getCursor() {
- return getLocationsCursor(trackId, lastTrackPointId + 1, 2000, false);
+ return getLocationsCursor(trackId, lastTrackPointId + 1, 2000, descending);
}
private boolean advanceCursorToNextBatch() {
@@ -954,7 +954,12 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
cursor = getCursor();
return cursor != null && cursor.moveToNext();
}
-
+
+ @Override
+ public long getLocationId() {
+ return lastTrackPointId;
+ }
+
@Override
public boolean hasNext() {
return cursor != null && !cursor.isAfterLast();