forked from upstream-mirrors/OpenTracks
Code cleanup: use getTrackPointLocationIterator instead of getTrackPointCursor
This commit is contained in:
@@ -492,52 +492,60 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
|
|
||||||
long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId);
|
long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId);
|
||||||
int samplingFrequency = -1;
|
int samplingFrequency = -1;
|
||||||
LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator(selectedTrackId,
|
|
||||||
localLastSeenLocationId + 1, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
|
||||||
boolean includeNextPoint = false;
|
boolean includeNextPoint = false;
|
||||||
while (iterator.hasNext()) {
|
LocationIterator locationIterator = null;
|
||||||
Location location = iterator.next();
|
|
||||||
long locationId = iterator.getLocationId();
|
|
||||||
|
|
||||||
// Stop if past the last wanted point
|
try {
|
||||||
if (maxPointId != -1L && locationId > maxPointId) {
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(selectedTrackId,
|
||||||
break;
|
localLastSeenLocationId + 1, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
|
||||||
|
|
||||||
if (localFirstSeenLocationId == -1) {
|
while (locationIterator.hasNext()) {
|
||||||
localFirstSeenLocationId = locationId;
|
Location location = locationIterator.next();
|
||||||
}
|
long locationId = locationIterator.getLocationId();
|
||||||
|
|
||||||
if (samplingFrequency == -1) {
|
// Stop if past the last wanted point
|
||||||
long numTotalPoints = Math.max(0L, lastTrackPointId - localFirstSeenLocationId);
|
if (maxPointId != -1L && locationId > maxPointId) {
|
||||||
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
|
||||||
// TODO: also include the last valid point before a split
|
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
|
||||||
trackDataListener.onSegmentSplit(location);
|
|
||||||
includeNextPoint = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Also include the last point if the selected track is not recording.
|
if (localFirstSeenLocationId == -1) {
|
||||||
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0)
|
localFirstSeenLocationId = locationId;
|
||||||
|| (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
}
|
||||||
includeNextPoint = false;
|
|
||||||
|
if (samplingFrequency == -1) {
|
||||||
|
long numTotalPoints = Math.max(0L, lastTrackPointId - localFirstSeenLocationId);
|
||||||
|
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
|
// TODO: also include the last valid point before a split
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
for (TrackDataListener trackDataListener : sampledInListeners) {
|
||||||
trackDataListener.onSampledInTrackPoint(location);
|
trackDataListener.onSegmentSplit(location);
|
||||||
|
includeNextPoint = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (TrackDataListener trackDataListener : sampledOutListeners) {
|
// Also include the last point if the selected track is not recording.
|
||||||
trackDataListener.onSampledOutTrackPoint(location);
|
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0)
|
||||||
|
|| (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
||||||
|
includeNextPoint = false;
|
||||||
|
for (TrackDataListener trackDataListener : sampledInListeners) {
|
||||||
|
trackDataListener.onSampledInTrackPoint(location);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (TrackDataListener trackDataListener : sampledOutListeners) {
|
||||||
|
trackDataListener.onSampledOutTrackPoint(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
localNumLoadedPoints++;
|
localNumLoadedPoints++;
|
||||||
localLastSeenLocationId = locationId;
|
localLastSeenLocationId = locationId;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (locationIterator != null) {
|
||||||
|
locationIterator.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
iterator.close();
|
|
||||||
|
|
||||||
if (updateSamplingState) {
|
if (updateSamplingState) {
|
||||||
numLoadedPoints = localNumLoadedPoints;
|
numLoadedPoints = localNumLoadedPoints;
|
||||||
|
|||||||
+8
-4
@@ -134,11 +134,13 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
boolean wroteSegment = false;
|
boolean wroteSegment = false;
|
||||||
boolean isLastLocationValid = false;
|
boolean isLastLocationValid = false;
|
||||||
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
|
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
|
||||||
LocationIterator locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
int locationNumber = 0;
|
||||||
track.getId(), -1L, false, locationFactory);
|
LocationIterator locationIterator = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int locationNumber = 0;
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
|
track.getId(), -1L, false, locationFactory);
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (locationIterator.hasNext()) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
throw new InterruptedException();
|
throw new InterruptedException();
|
||||||
@@ -195,7 +197,9 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
trackWriter.writeEndTrack(track, null);
|
trackWriter.writeEndTrack(track, null);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
locationIterator.close();
|
if (locationIterator != null) {
|
||||||
|
locationIterator.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-31
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.file.importer;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||||
@@ -34,7 +35,6 @@ import com.google.android.apps.mytracks.util.UnitConversions;
|
|||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -211,20 +211,19 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
if (track == null) {
|
if (track == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cursor trackPointCursor = null;
|
|
||||||
|
int waypointPosition = -1;
|
||||||
|
Waypoint waypoint = null;
|
||||||
|
Location location = null;
|
||||||
|
TripStatisticsUpdater trackTripStatisticstrackUpdater = new TripStatisticsUpdater(
|
||||||
|
track.getTripStatistics().getStartTime());
|
||||||
|
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(
|
||||||
|
track.getTripStatistics().getStartTime());
|
||||||
|
LocationIterator locationIterator = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
trackPointCursor = myTracksProviderUtils.getTrackPointCursor(track.getId(), -1L, -1, false);
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
if (trackPointCursor == null) {
|
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
return;
|
|
||||||
}
|
|
||||||
int waypointPosition = -1;
|
|
||||||
Waypoint waypoint = null;
|
|
||||||
int trackPointPosition = -1;
|
|
||||||
Location trackPoint = null;
|
|
||||||
TripStatisticsUpdater trackTripStatisticstrackUpdater = new TripStatisticsUpdater(
|
|
||||||
track.getTripStatistics().getStartTime());
|
|
||||||
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(
|
|
||||||
track.getTripStatistics().getStartTime());
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
@@ -235,28 +234,25 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trackPoint == null) {
|
if (location == null) {
|
||||||
trackPointPosition++;
|
if (!locationIterator.hasNext()) {
|
||||||
trackPoint = trackPointCursor.moveToPosition(trackPointPosition) ? myTracksProviderUtils
|
|
||||||
.createTrackPoint(trackPointCursor)
|
|
||||||
: null;
|
|
||||||
if (trackPoint == null) {
|
|
||||||
// No more track points. Ignore the rest of the waypoints.
|
// No more track points. Ignore the rest of the waypoints.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, false,
|
location = locationIterator.next();
|
||||||
|
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||||
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, false,
|
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||||
}
|
}
|
||||||
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
|
if (waypoint.getLocation().getTime() > location.getTime()) {
|
||||||
trackPoint = null;
|
location = null;
|
||||||
} else if (waypoint.getLocation().getTime() < trackPoint.getTime()) {
|
} else if (waypoint.getLocation().getTime() < location.getTime()) {
|
||||||
waypoint = null;
|
waypoint = null;
|
||||||
} else {
|
} else {
|
||||||
// The waypoint location time matches the track point time
|
// The waypoint location time matches the track point time
|
||||||
if (trackPoint.getLatitude() == waypoint.getLocation().getLatitude()
|
if (location.getLatitude() == waypoint.getLocation().getLatitude()
|
||||||
&& trackPoint.getLongitude() == waypoint.getLocation().getLongitude()) {
|
&& location.getLongitude() == waypoint.getLocation().getLongitude()) {
|
||||||
|
|
||||||
// Get tripStatistics, description, and icon
|
// Get tripStatistics, description, and icon
|
||||||
TripStatistics tripStatistics;
|
TripStatistics tripStatistics;
|
||||||
@@ -264,7 +260,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
String icon;
|
String icon;
|
||||||
if (waypoint.getType() == WaypointType.STATISTICS) {
|
if (waypoint.getType() == WaypointType.STATISTICS) {
|
||||||
tripStatistics = markerTripStatisticsUpdater.getTripStatistics();
|
tripStatistics = markerTripStatisticsUpdater.getTripStatistics();
|
||||||
markerTripStatisticsUpdater = new TripStatisticsUpdater(trackPoint.getTime());
|
markerTripStatisticsUpdater = new TripStatisticsUpdater(location.getTime());
|
||||||
waypointDescription = new DescriptionGeneratorImpl(context)
|
waypointDescription = new DescriptionGeneratorImpl(context)
|
||||||
.generateWaypointDescription(tripStatistics);
|
.generateWaypointDescription(tripStatistics);
|
||||||
icon = context.getString(R.string.marker_statistics_icon_url);
|
icon = context.getString(R.string.marker_statistics_icon_url);
|
||||||
@@ -281,15 +277,15 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
// Insert waypoint
|
// Insert waypoint
|
||||||
Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription,
|
Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription,
|
||||||
waypoint.getCategory(), icon, track.getId(), waypoint.getType(), length, duration,
|
waypoint.getCategory(), icon, track.getId(), waypoint.getType(), length, duration,
|
||||||
-1L, -1L, trackPoint, tripStatistics, waypoint.getPhotoUrl());
|
-1L, -1L, location, tripStatistics, waypoint.getPhotoUrl());
|
||||||
myTracksProviderUtils.insertWaypoint(newWaypoint);
|
myTracksProviderUtils.insertWaypoint(newWaypoint);
|
||||||
}
|
}
|
||||||
waypoint = null;
|
waypoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (trackPointCursor != null) {
|
if (locationIterator != null) {
|
||||||
trackPointCursor.close();
|
locationIterator.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-19
@@ -6,6 +6,7 @@ import com.google.android.apps.mytracks.Constants;
|
|||||||
import com.google.android.apps.mytracks.content.DescriptionGenerator;
|
import com.google.android.apps.mytracks.content.DescriptionGenerator;
|
||||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||||
@@ -227,23 +228,19 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
*/
|
*/
|
||||||
private boolean uploadAllTrackPoints(Fusiontables fusiontables, String tableId, Track track)
|
private boolean uploadAllTrackPoints(Fusiontables fusiontables, String tableId, Track track)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Cursor cursor = null;
|
int numberOfPoints = track.getNumberOfPoints();
|
||||||
|
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||||
|
Location lastValidLocation = null;
|
||||||
|
boolean sentStartMarker = false;
|
||||||
|
int readCount = 0;
|
||||||
|
|
||||||
|
LocationIterator locationIterator = null;
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, -1L, -1, false);
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
if (cursor == null) {
|
trackId, -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
Log.d(TAG, "Location cursor is null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = cursor.getCount();
|
while (locationIterator.hasNext()) {
|
||||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
Location location = locationIterator.next();
|
||||||
Location lastValidLocation = null;
|
|
||||||
boolean sentStartMarker = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
cursor.moveToPosition(i);
|
|
||||||
|
|
||||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
|
||||||
locations.add(location);
|
locations.add(location);
|
||||||
|
|
||||||
if (LocationUtils.isValidLocation(location)) {
|
if (LocationUtils.isValidLocation(location)) {
|
||||||
@@ -258,13 +255,13 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Upload periodically
|
// Upload periodically
|
||||||
int readCount = i + 1;
|
readCount++;
|
||||||
if (readCount % MAX_POINTS_PER_UPLOAD == 0) {
|
if (readCount % MAX_POINTS_PER_UPLOAD == 0) {
|
||||||
if (!prepareAndUploadPoints(fusiontables, tableId, track, locations, false)) {
|
if (!prepareAndUploadPoints(fusiontables, tableId, track, locations, false)) {
|
||||||
Log.d(TAG, "Unable to upload points");
|
Log.d(TAG, "Unable to upload points");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updateProgress(readCount, count);
|
updateProgress(readCount, numberOfPoints);
|
||||||
locations.clear();
|
locations.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,8 +282,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (locationIterator != null) {
|
||||||
cursor.close();
|
locationIterator.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.google.android.apps.mytracks.Constants;
|
|||||||
import com.google.android.apps.mytracks.content.DescriptionGenerator;
|
import com.google.android.apps.mytracks.content.DescriptionGenerator;
|
||||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
||||||
@@ -235,33 +236,29 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean uploadAllTrackPoints(Track track) {
|
boolean uploadAllTrackPoints(Track track) {
|
||||||
Cursor cursor = null;
|
int numberOfPoints = track.getNumberOfPoints();
|
||||||
|
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||||
|
Location lastValidLocation = null;
|
||||||
|
boolean sentStartMarker = false;
|
||||||
|
|
||||||
|
// For chart server, limit the number of elevation readings to 250.
|
||||||
|
int elevationSamplingFrequency = Math.max(1, (int) (numberOfPoints / 250.0));
|
||||||
|
Vector<Double> distances = new Vector<Double>();
|
||||||
|
Vector<Double> elevations = new Vector<Double>();
|
||||||
|
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(
|
||||||
|
track.getTripStatistics().getStartTime());
|
||||||
|
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
||||||
|
R.string.recording_distance_interval_key,
|
||||||
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||||
|
int readCount = 0;
|
||||||
|
LocationIterator locationIterator = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, -1L, -1, false);
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
if (cursor == null) {
|
trackId, -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
Log.d(TAG, "Location cursor is null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = cursor.getCount();
|
while (locationIterator.hasNext()) {
|
||||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
Location location = locationIterator.next();
|
||||||
Location lastValidLocation = null;
|
|
||||||
boolean sentStartMarker = false;
|
|
||||||
|
|
||||||
// For chart server, limit the number of elevation readings to 250.
|
|
||||||
int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0));
|
|
||||||
Vector<Double> distances = new Vector<Double>();
|
|
||||||
Vector<Double> elevations = new Vector<Double>();
|
|
||||||
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(
|
|
||||||
track.getTripStatistics().getStartTime());
|
|
||||||
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
|
||||||
R.string.recording_distance_interval_key,
|
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
cursor.moveToPosition(i);
|
|
||||||
|
|
||||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
|
||||||
locations.add(location);
|
locations.add(location);
|
||||||
|
|
||||||
if (LocationUtils.isValidLocation(location)) {
|
if (LocationUtils.isValidLocation(location)) {
|
||||||
@@ -280,19 +277,19 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||||
if (i % elevationSamplingFrequency == 0) {
|
if (readCount % elevationSamplingFrequency == 0) {
|
||||||
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload periodically
|
// Upload periodically
|
||||||
int readCount = i + 1;
|
readCount++;
|
||||||
if (readCount % MAX_POINTS_PER_UPLOAD == 0) {
|
if (readCount % MAX_POINTS_PER_UPLOAD == 0) {
|
||||||
if (!prepareAndUploadPoints(track, locations, false)) {
|
if (!prepareAndUploadPoints(track, locations, false)) {
|
||||||
Log.d(TAG, "Unable to upload points");
|
Log.d(TAG, "Unable to upload points");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updateProgress(readCount, count);
|
updateProgress(readCount, numberOfPoints);
|
||||||
locations.clear();
|
locations.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,8 +315,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (locationIterator != null) {
|
||||||
cursor.close();
|
locationIterator.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -667,6 +667,7 @@ public class TrackRecordingService extends Service {
|
|||||||
try {
|
try {
|
||||||
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (locationIterator.hasNext()) {
|
||||||
Location location = locationIterator.next();
|
Location location = locationIterator.next();
|
||||||
trackTripStatisticsUpdater.addLocation(
|
trackTripStatisticsUpdater.addLocation(
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ public class CalorieUtils {
|
|||||||
try {
|
try {
|
||||||
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
track.getId(), startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
track.getId(), startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (locationIterator.hasNext()) {
|
||||||
tripStatisticsUpdater.addLocation(
|
tripStatisticsUpdater.addLocation(
|
||||||
locationIterator.next(), recordingDistanceInterval, true, activityType, weight);
|
locationIterator.next(), recordingDistanceInterval, true, activityType, weight);
|
||||||
|
|||||||
Reference in New Issue
Block a user