Addressed comments + new method getLocationId()

This commit is contained in:
bartn
2010-12-17 13:57:51 -08:00
parent c4a539d2ba
commit 56f22aa073
3 changed files with 30 additions and 11 deletions
-2
View File
@@ -158,11 +158,9 @@ limitations under the License.
<uses-permission android:name="com.google.android.apps.mytracks.TRACK_NOTIFICATIONS" />
<!-- Features required -->
<!--
<uses-feature android:name="android.hardware.location" android:required="true"/>
<uses-feature android:name="android.hardware.location.gps" android:required="true"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="true"/>
-->
<!-- Features optional -->
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
@@ -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<Location> {
/**
* 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 {
* </code>
*
* @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},
@@ -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();