(MAX_POINTS_PER_UPLOAD);
progressIndicator.setProgressMessage(
R.string.progress_message_reading_track);
@@ -238,15 +243,15 @@ public class SendToMyMaps implements Runnable {
if (totalLocationsRead % 100 == 0) {
updateProgress();
}
-
+
Location loc = providerUtils.createLocation(locationsCursor);
locations.add(loc);
-
+
if (totalLocationsRead == 0) {
// Put a marker at the first point of the first valid segment:
mapsClient.uploadMarker(mapId, track.getName(), track.getDescription(), loc, true);
}
-
+
// Add to the elevation profile.
if (loc != null && LocationUtils.isValidLocation(loc)) {
// All points go into the smoothing buffer...
@@ -256,19 +261,19 @@ public class SendToMyMaps implements Runnable {
double dist = lastLocation.distanceTo(loc);
totalDistance += dist;
}
-
+
// ...but only a few points are really used to keep the url short.
if (totalLocationsRead % elevationSamplingFrequency == 0) {
distances.add(totalDistance);
elevations.add(elevationBuffer.getAverage());
}
}
-
+
// If the location was not valid, it's a segment split, so make sure the
// distance between the previous segment and the new one is not accounted
// for in the next iteration.
lastLocation = loc;
-
+
// Every now and then, upload the accumulated points
if (totalLocationsRead % MAX_POINTS_PER_UPLOAD
== MAX_POINTS_PER_UPLOAD - 1) {
@@ -276,28 +281,30 @@ public class SendToMyMaps implements Runnable {
return false;
}
}
-
+
totalLocationsRead++;
} while (locationsCursor.moveToNext());
-
+
// Do a final upload with what's left
if (!prepareAndUploadPoints(track, locations)) {
return false;
}
-
+
// Put an end marker at the last point of the last valid segment:
if (lastLocation != null) {
track.setDescription("" + originalDescription + "
"
+ stringUtils.generateTrackDescription(
track, distances, elevations)
+ "
");
- return mapsClient.uploadMarker(mapId, track.getName(), track.getDescription(),
+ return mapsClient.uploadMarker(mapId, track.getName(), track.getDescription(),
lastLocation, false);
}
-
+
return true;
} finally {
- locationsCursor.close();
+ if (locationsCursor != null) {
+ locationsCursor.close();
+ }
}
}
@@ -306,17 +313,17 @@ public class SendToMyMaps implements Runnable {
progressIndicator.setProgressMessage(
R.string.progress_message_preparing_track);
updateProgress();
-
+
int numLocations = locations.size();
if (numLocations < 2) {
Log.d(TAG, "Not preparing/uploading too few points");
totalLocationsUploaded += numLocations;
return true;
}
-
+
// Prepare/pre-process the points
ArrayList