forked from upstream-mirrors/OpenTracks
Addressed comments + new method getLocationId()
This commit is contained in:
@@ -158,11 +158,9 @@ limitations under the License.
|
|||||||
<uses-permission android:name="com.google.android.apps.mytracks.TRACK_NOTIFICATIONS" />
|
<uses-permission android:name="com.google.android.apps.mytracks.TRACK_NOTIFICATIONS" />
|
||||||
|
|
||||||
<!-- Features required -->
|
<!-- Features required -->
|
||||||
<!--
|
|
||||||
<uses-feature android:name="android.hardware.location" android:required="true"/>
|
<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.location.gps" android:required="true"/>
|
||||||
<uses-feature android:name="android.hardware.touchscreen" android:required="true"/>
|
<uses-feature android:name="android.hardware.touchscreen" android:required="true"/>
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Features optional -->
|
<!-- Features optional -->
|
||||||
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
|
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
|
||||||
|
|||||||
+20
-4
@@ -315,6 +315,13 @@ public interface MyTracksProviderUtils {
|
|||||||
* A lightweight wrapper around the original {@link Cursor} with a method to clean up.
|
* A lightweight wrapper around the original {@link Cursor} with a method to clean up.
|
||||||
*/
|
*/
|
||||||
interface LocationIterator extends Iterator<Location> {
|
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.
|
* 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
|
* The default {@class Location}s factory, which creates a new location of 'gps' type.
|
||||||
* time the user advances to the next element using {@link LocationIterator#next()} method.
|
|
||||||
*/
|
*/
|
||||||
LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() {
|
LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() {
|
||||||
@Override
|
@Override
|
||||||
@@ -352,7 +358,11 @@ public interface MyTracksProviderUtils {
|
|||||||
* limitations. Since it's a read-only iterator, {@link Iterator#remove()} always throws
|
* limitations. Since it's a read-only iterator, {@link Iterator#remove()} always throws
|
||||||
* {@class UnsupportedOperationException}.
|
* {@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.
|
* resources are properly deallocated.
|
||||||
*
|
*
|
||||||
* Example use:
|
* Example use:
|
||||||
@@ -371,10 +381,16 @@ public interface MyTracksProviderUtils {
|
|||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param trackId the ID of a track to retrieve locations for.
|
* @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.
|
* @param locationFactory the factory for creating new locations.
|
||||||
|
*
|
||||||
* @return the read-only iterator over the given track's points.
|
* @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},
|
* A factory which can produce instances of {@link MyTracksProviderUtils},
|
||||||
|
|||||||
+10
-5
@@ -937,16 +937,16 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocationIterator getLocationIterator(final long trackId,
|
public LocationIterator getLocationIterator(final long trackId, final long startTrackPointId,
|
||||||
final LocationFactory locationFactory) {
|
final boolean descending, final LocationFactory locationFactory) {
|
||||||
return new LocationIterator() {
|
return new LocationIterator() {
|
||||||
private long lastTrackPointId = -1;
|
private long lastTrackPointId = startTrackPointId - 1;
|
||||||
private Cursor cursor = getCursor();
|
private Cursor cursor = getCursor();
|
||||||
private final int idColumnIdx = cursor != null ?
|
private final int idColumnIdx = cursor != null ?
|
||||||
cursor.getColumnIndexOrThrow(TrackPointsColumns._ID) : -1;
|
cursor.getColumnIndexOrThrow(TrackPointsColumns._ID) : -1;
|
||||||
|
|
||||||
private Cursor getCursor() {
|
private Cursor getCursor() {
|
||||||
return getLocationsCursor(trackId, lastTrackPointId + 1, 2000, false);
|
return getLocationsCursor(trackId, lastTrackPointId + 1, 2000, descending);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean advanceCursorToNextBatch() {
|
private boolean advanceCursorToNextBatch() {
|
||||||
@@ -954,7 +954,12 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
cursor = getCursor();
|
cursor = getCursor();
|
||||||
return cursor != null && cursor.moveToNext();
|
return cursor != null && cursor.moveToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLocationId() {
|
||||||
|
return lastTrackPointId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return cursor != null && !cursor.isAfterLast();
|
return cursor != null && !cursor.isAfterLast();
|
||||||
|
|||||||
Reference in New Issue
Block a user