forked from upstream-mirrors/OpenTracks
Merge heads
This commit is contained in:
@@ -192,7 +192,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
@Override
|
||||
public void run() {
|
||||
ApiAdapterFactory.getApiAdapter().invalidMenu(TrackListActivity.this);
|
||||
sectionResourceCursorAdapter.notifyDataSetChanged();
|
||||
getSupportLoaderManager().restartLoader(0, null, loaderCallbacks);
|
||||
boolean isRecording = recordingTrackId
|
||||
!= PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
trackController.update(isRecording, recordingTrackPaused);
|
||||
@@ -273,6 +273,25 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
}
|
||||
};
|
||||
|
||||
private final LoaderCallbacks<Cursor> loaderCallbacks = new LoaderCallbacks<Cursor>() {
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null,
|
||||
null,
|
||||
"IFNULL(" + TracksColumns.SHAREDWITHME + ",0) ASC, " + TracksColumns.STARTTIME + " DESC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
sectionResourceCursorAdapter.swapCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
sectionResourceCursorAdapter.swapCursor(null);
|
||||
}
|
||||
};
|
||||
|
||||
// The following are set in onCreate
|
||||
private MyTracksProviderUtils myTracksProviderUtils;
|
||||
private SharedPreferences sharedPreferences;
|
||||
@@ -371,24 +390,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
ApiAdapterFactory.getApiAdapter()
|
||||
.configureListViewContextualMenu(this, listView, contextualActionModeCallback);
|
||||
|
||||
getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null,
|
||||
null, "IFNULL(" + TracksColumns.SHAREDWITHME + ",0) ASC, " + TracksColumns.STARTTIME
|
||||
+ " DESC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
sectionResourceCursorAdapter.swapCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
sectionResourceCursorAdapter.swapCursor(null);
|
||||
}
|
||||
});
|
||||
getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
|
||||
showStartupDialogs();
|
||||
}
|
||||
|
||||
@@ -414,7 +416,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
|
||||
// Update UI
|
||||
ApiAdapterFactory.getApiAdapter().invalidMenu(this);
|
||||
sectionResourceCursorAdapter.notifyDataSetChanged();
|
||||
getSupportLoaderManager().restartLoader(0, null, loaderCallbacks);
|
||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
trackController.onResume(isRecording, recordingTrackPaused);
|
||||
}
|
||||
|
||||
@@ -96,8 +96,6 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
int numBufferedLocations = 0;
|
||||
}
|
||||
|
||||
protected static final String DEFAULT_ALTITUDE = "0";
|
||||
|
||||
// The maximum number of buffered locations for bulk-insertion
|
||||
private static final int MAX_BUFFERED_LOCATIONS = 512;
|
||||
|
||||
@@ -465,24 +463,29 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
* Creates a location.
|
||||
*/
|
||||
private Location createLocation() throws SAXException {
|
||||
if (latitude == null || longitude == null || altitude == null) {
|
||||
if (latitude == null || longitude == null) {
|
||||
return null;
|
||||
}
|
||||
double longitudeValue;
|
||||
double latitudeValue;
|
||||
double altitudeValue;
|
||||
|
||||
double longitudeValue;
|
||||
try {
|
||||
longitudeValue = Double.parseDouble(longitude);
|
||||
latitudeValue = Double.parseDouble(latitude);
|
||||
altitudeValue = Double.parseDouble(altitude);
|
||||
longitudeValue = Double.parseDouble(longitude);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new SAXException(createErrorMessage(String.format(
|
||||
"Unable to parse longitude latitude altitude: %s %s %s", longitude, latitude, altitude)),
|
||||
e);
|
||||
throw new SAXException(createErrorMessage(
|
||||
String.format("Unable to parse latitude longitude: %s %s", latitude, longitude)), e);
|
||||
}
|
||||
Double altitudeValue = null;
|
||||
if (altitude != null) {
|
||||
try {
|
||||
altitudeValue = Double.parseDouble(altitude);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new SAXException(
|
||||
createErrorMessage(String.format("Unable to parse altitude: %s", altitude)), e);
|
||||
}
|
||||
}
|
||||
|
||||
long timeValue;
|
||||
|
||||
if (time == null) {
|
||||
timeValue = trackData.importTime;
|
||||
} else {
|
||||
@@ -505,11 +508,15 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
* @param timeValue the time value
|
||||
*/
|
||||
private Location createLocation(
|
||||
double latitudeValue, double longitudeValue, double altitudeValue, long timeValue) {
|
||||
double latitudeValue, double longitudeValue, Double altitudeValue, long timeValue) {
|
||||
Location location = new Location(LocationManager.GPS_PROVIDER);
|
||||
location.setLatitude(latitudeValue);
|
||||
location.setLongitude(longitudeValue);
|
||||
location.setAltitude(altitudeValue);
|
||||
if (altitudeValue != null) {
|
||||
location.setAltitude(altitudeValue);
|
||||
} else {
|
||||
location.removeAltitude();
|
||||
}
|
||||
location.setTime(timeValue);
|
||||
location.removeAccuracy();
|
||||
location.removeBearing();
|
||||
|
||||
@@ -123,10 +123,10 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
waypoint.getDescription(),
|
||||
Double.toString(location.getLatitude()),
|
||||
Double.toString(location.getLongitude()),
|
||||
Double.toString(location.getAltitude()),
|
||||
Double.toString(location.getBearing()),
|
||||
SHORT_FORMAT.format(location.getAccuracy()),
|
||||
SHORT_FORMAT.format(location.getSpeed()),
|
||||
getAltitude(location),
|
||||
getBearing(location),
|
||||
getAccuracy(location),
|
||||
getSpeed(location),
|
||||
StringUtils.formatDateTimeIso8601(location.getTime()));
|
||||
}
|
||||
|
||||
@@ -196,16 +196,32 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
Integer.toString(pointIndex),
|
||||
Double.toString(location.getLatitude()),
|
||||
Double.toString(location.getLongitude()),
|
||||
Double.toString(location.getAltitude()),
|
||||
Double.toString(location.getBearing()),
|
||||
SHORT_FORMAT.format(location.getAccuracy()),
|
||||
SHORT_FORMAT.format(location.getSpeed()),
|
||||
getAltitude(location),
|
||||
getBearing(location),
|
||||
getAccuracy(location),
|
||||
getSpeed(location),
|
||||
StringUtils.formatDateTimeIso8601(location.getTime()),
|
||||
power,
|
||||
cadence,
|
||||
heartRate);
|
||||
}
|
||||
|
||||
|
||||
private String getAltitude(Location location) {
|
||||
return location.hasAltitude() ? Double.toString(location.getAltitude()) : null;
|
||||
}
|
||||
|
||||
private String getBearing(Location location) {
|
||||
return location.hasBearing() ? Double.toString(location.getBearing()) : null;
|
||||
}
|
||||
|
||||
private String getAccuracy(Location location) {
|
||||
return location.hasAccuracy() ? SHORT_FORMAT.format(location.getAccuracy()) : null;
|
||||
}
|
||||
|
||||
private String getSpeed(Location location) {
|
||||
return location.hasSpeed() ? SHORT_FORMAT.format(location.getSpeed()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single line of a CSV file.
|
||||
*
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
|
||||
private static final String ATTRIBUTE_LAT = "lat";
|
||||
private static final String ATTRIBUTE_LON = "lon";
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -133,7 +133,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
private void onTrackPointStart(Attributes attributes) {
|
||||
latitude = attributes.getValue(ATTRIBUTE_LAT);
|
||||
longitude = attributes.getValue(ATTRIBUTE_LON);
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
category = null;
|
||||
latitude = attributes.getValue(ATTRIBUTE_LAT);
|
||||
longitude = attributes.getValue(ATTRIBUTE_LON);
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
waypointType = null;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
||||
public void writeLocation(Location location) {
|
||||
if (printWriter != null) {
|
||||
printWriter.println("<trkpt " + formatLocation(location) + ">");
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
}
|
||||
printWriter.println(
|
||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||
printWriter.println("</trkpt>");
|
||||
@@ -161,7 +163,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
||||
Location location = waypoint.getLocation();
|
||||
if (location != null) {
|
||||
printWriter.println("<wpt " + formatLocation(location) + ">");
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
}
|
||||
printWriter.println(
|
||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
|
||||
|
||||
@@ -148,7 +148,7 @@ public class KmlImporter extends AbstractImporter {
|
||||
category = null;
|
||||
latitude = null;
|
||||
longitude = null;
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
waypointType = null;
|
||||
}
|
||||
@@ -181,9 +181,7 @@ public class KmlImporter extends AbstractImporter {
|
||||
}
|
||||
longitude = parts[0];
|
||||
latitude = parts[1];
|
||||
if (parts.length == 3) {
|
||||
altitude = parts[2];
|
||||
}
|
||||
altitude = parts.length == 3 ? parts[2] : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,12 +238,13 @@ public class KmlImporter extends AbstractImporter {
|
||||
return;
|
||||
}
|
||||
String parts[] = content.trim().split(" ");
|
||||
if (parts.length != 3) {
|
||||
if (parts.length != 2 && parts.length != 3) {
|
||||
return;
|
||||
}
|
||||
longitude = parts[0];
|
||||
latitude = parts[1];
|
||||
altitude = parts[2];
|
||||
altitude = parts.length == 3 ? parts[2] : null;
|
||||
|
||||
Location location = getTrackPoint();
|
||||
if (location == null) {
|
||||
return;
|
||||
|
||||
@@ -229,8 +229,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
||||
if (printWriter != null) {
|
||||
printWriter.println(
|
||||
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
|
||||
printWriter.println("<gx:coord>" + location.getLongitude() + " " + location.getLatitude()
|
||||
+ " " + location.getAltitude() + "</gx:coord>");
|
||||
printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
|
||||
if (location instanceof MyTracksLocation) {
|
||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||
int power = -1;
|
||||
@@ -302,12 +301,20 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
||||
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
|
||||
writeCategory(category);
|
||||
printWriter.println("<Point>");
|
||||
printWriter.println("<coordinates>" + location.getLongitude() + "," + location.getLatitude()
|
||||
+ "," + location.getAltitude() + "</coordinates>");
|
||||
printWriter.println("<coordinates>" + getCoordinates(location, ",") + "</coordinates>");
|
||||
printWriter.println("</Point>");
|
||||
printWriter.println("</Placemark>");
|
||||
}
|
||||
}
|
||||
|
||||
private String getCoordinates(Location location, String separator) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(location.getLongitude() + separator + location.getLatitude());
|
||||
if (location.hasAltitude()) {
|
||||
buffer.append(separator + location.getAltitude());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the category.
|
||||
|
||||
@@ -204,7 +204,9 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
||||
printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>");
|
||||
printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>");
|
||||
printWriter.println("</Position>");
|
||||
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
||||
}
|
||||
|
||||
if (location instanceof MyTracksLocation) {
|
||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||
|
||||
Reference in New Issue
Block a user