Merge heads

This commit is contained in:
youtaol
2013-07-11 10:36:14 +08:00
parent 4debca0054
commit dad09f4a87
8 changed files with 96 additions and 59 deletions
@@ -192,7 +192,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
@Override @Override
public void run() { public void run() {
ApiAdapterFactory.getApiAdapter().invalidMenu(TrackListActivity.this); ApiAdapterFactory.getApiAdapter().invalidMenu(TrackListActivity.this);
sectionResourceCursorAdapter.notifyDataSetChanged(); getSupportLoaderManager().restartLoader(0, null, loaderCallbacks);
boolean isRecording = recordingTrackId boolean isRecording = recordingTrackId
!= PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
trackController.update(isRecording, recordingTrackPaused); 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 // The following are set in onCreate
private MyTracksProviderUtils myTracksProviderUtils; private MyTracksProviderUtils myTracksProviderUtils;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
@@ -371,24 +390,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
ApiAdapterFactory.getApiAdapter() ApiAdapterFactory.getApiAdapter()
.configureListViewContextualMenu(this, listView, contextualActionModeCallback); .configureListViewContextualMenu(this, listView, contextualActionModeCallback);
getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
@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);
}
});
showStartupDialogs(); showStartupDialogs();
} }
@@ -414,7 +416,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
// Update UI // Update UI
ApiAdapterFactory.getApiAdapter().invalidMenu(this); ApiAdapterFactory.getApiAdapter().invalidMenu(this);
sectionResourceCursorAdapter.notifyDataSetChanged(); getSupportLoaderManager().restartLoader(0, null, loaderCallbacks);
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
trackController.onResume(isRecording, recordingTrackPaused); trackController.onResume(isRecording, recordingTrackPaused);
} }
@@ -96,8 +96,6 @@ abstract class AbstractImporter extends DefaultHandler {
int numBufferedLocations = 0; int numBufferedLocations = 0;
} }
protected static final String DEFAULT_ALTITUDE = "0";
// The maximum number of buffered locations for bulk-insertion // The maximum number of buffered locations for bulk-insertion
private static final int MAX_BUFFERED_LOCATIONS = 512; private static final int MAX_BUFFERED_LOCATIONS = 512;
@@ -465,24 +463,29 @@ abstract class AbstractImporter extends DefaultHandler {
* Creates a location. * Creates a location.
*/ */
private Location createLocation() throws SAXException { private Location createLocation() throws SAXException {
if (latitude == null || longitude == null || altitude == null) { if (latitude == null || longitude == null) {
return null; return null;
} }
double longitudeValue;
double latitudeValue; double latitudeValue;
double altitudeValue; double longitudeValue;
try { try {
longitudeValue = Double.parseDouble(longitude);
latitudeValue = Double.parseDouble(latitude); latitudeValue = Double.parseDouble(latitude);
altitudeValue = Double.parseDouble(altitude); longitudeValue = Double.parseDouble(longitude);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new SAXException(createErrorMessage(String.format( throw new SAXException(createErrorMessage(
"Unable to parse longitude latitude altitude: %s %s %s", longitude, latitude, altitude)), String.format("Unable to parse latitude longitude: %s %s", latitude, longitude)), e);
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;
long timeValue;
if (time == null) { if (time == null) {
timeValue = trackData.importTime; timeValue = trackData.importTime;
} else { } else {
@@ -505,11 +508,15 @@ abstract class AbstractImporter extends DefaultHandler {
* @param timeValue the time value * @param timeValue the time value
*/ */
private Location createLocation( 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 location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(latitudeValue); location.setLatitude(latitudeValue);
location.setLongitude(longitudeValue); location.setLongitude(longitudeValue);
location.setAltitude(altitudeValue); if (altitudeValue != null) {
location.setAltitude(altitudeValue);
} else {
location.removeAltitude();
}
location.setTime(timeValue); location.setTime(timeValue);
location.removeAccuracy(); location.removeAccuracy();
location.removeBearing(); location.removeBearing();
@@ -123,10 +123,10 @@ public class CsvTrackWriter implements TrackFormatWriter {
waypoint.getDescription(), waypoint.getDescription(),
Double.toString(location.getLatitude()), Double.toString(location.getLatitude()),
Double.toString(location.getLongitude()), Double.toString(location.getLongitude()),
Double.toString(location.getAltitude()), getAltitude(location),
Double.toString(location.getBearing()), getBearing(location),
SHORT_FORMAT.format(location.getAccuracy()), getAccuracy(location),
SHORT_FORMAT.format(location.getSpeed()), getSpeed(location),
StringUtils.formatDateTimeIso8601(location.getTime())); StringUtils.formatDateTimeIso8601(location.getTime()));
} }
@@ -196,16 +196,32 @@ public class CsvTrackWriter implements TrackFormatWriter {
Integer.toString(pointIndex), Integer.toString(pointIndex),
Double.toString(location.getLatitude()), Double.toString(location.getLatitude()),
Double.toString(location.getLongitude()), Double.toString(location.getLongitude()),
Double.toString(location.getAltitude()), getAltitude(location),
Double.toString(location.getBearing()), getBearing(location),
SHORT_FORMAT.format(location.getAccuracy()), getAccuracy(location),
SHORT_FORMAT.format(location.getSpeed()), getSpeed(location),
StringUtils.formatDateTimeIso8601(location.getTime()), StringUtils.formatDateTimeIso8601(location.getTime()),
power, power,
cadence, cadence,
heartRate); 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. * Writes a single line of a CSV file.
* *
@@ -133,7 +133,7 @@ public class GpxImporter extends AbstractImporter {
private void onTrackPointStart(Attributes attributes) { private void onTrackPointStart(Attributes attributes) {
latitude = attributes.getValue(ATTRIBUTE_LAT); latitude = attributes.getValue(ATTRIBUTE_LAT);
longitude = attributes.getValue(ATTRIBUTE_LON); longitude = attributes.getValue(ATTRIBUTE_LON);
altitude = DEFAULT_ALTITUDE; altitude = null;
time = null; time = null;
} }
@@ -159,7 +159,7 @@ public class GpxImporter extends AbstractImporter {
category = null; category = null;
latitude = attributes.getValue(ATTRIBUTE_LAT); latitude = attributes.getValue(ATTRIBUTE_LAT);
longitude = attributes.getValue(ATTRIBUTE_LON); longitude = attributes.getValue(ATTRIBUTE_LON);
altitude = DEFAULT_ALTITUDE; altitude = null;
time = null; time = null;
waypointType = null; waypointType = null;
} }
@@ -138,7 +138,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
public void writeLocation(Location location) { public void writeLocation(Location location) {
if (printWriter != null) { if (printWriter != null) {
printWriter.println("<trkpt " + formatLocation(location) + ">"); 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( printWriter.println(
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>"); "<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("</trkpt>"); printWriter.println("</trkpt>");
@@ -161,7 +163,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
Location location = waypoint.getLocation(); Location location = waypoint.getLocation();
if (location != null) { if (location != null) {
printWriter.println("<wpt " + formatLocation(location) + ">"); 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( printWriter.println(
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>"); "<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>"); printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
@@ -148,7 +148,7 @@ public class KmlImporter extends AbstractImporter {
category = null; category = null;
latitude = null; latitude = null;
longitude = null; longitude = null;
altitude = DEFAULT_ALTITUDE; altitude = null;
time = null; time = null;
waypointType = null; waypointType = null;
} }
@@ -181,9 +181,7 @@ public class KmlImporter extends AbstractImporter {
} }
longitude = parts[0]; longitude = parts[0];
latitude = parts[1]; latitude = parts[1];
if (parts.length == 3) { altitude = parts.length == 3 ? parts[2] : null;
altitude = parts[2];
}
} }
} }
@@ -240,12 +238,13 @@ public class KmlImporter extends AbstractImporter {
return; return;
} }
String parts[] = content.trim().split(" "); String parts[] = content.trim().split(" ");
if (parts.length != 3) { if (parts.length != 2 && parts.length != 3) {
return; return;
} }
longitude = parts[0]; longitude = parts[0];
latitude = parts[1]; latitude = parts[1];
altitude = parts[2]; altitude = parts.length == 3 ? parts[2] : null;
Location location = getTrackPoint(); Location location = getTrackPoint();
if (location == null) { if (location == null) {
return; return;
@@ -229,8 +229,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
if (printWriter != null) { if (printWriter != null) {
printWriter.println( printWriter.println(
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>"); "<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
printWriter.println("<gx:coord>" + location.getLongitude() + " " + location.getLatitude() printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
+ " " + location.getAltitude() + "</gx:coord>");
if (location instanceof MyTracksLocation) { if (location instanceof MyTracksLocation) {
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet(); SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
int power = -1; int power = -1;
@@ -302,13 +301,21 @@ public class KmlTrackWriter implements TrackFormatWriter {
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>"); printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
writeCategory(category); writeCategory(category);
printWriter.println("<Point>"); printWriter.println("<Point>");
printWriter.println("<coordinates>" + location.getLongitude() + "," + location.getLatitude() printWriter.println("<coordinates>" + getCoordinates(location, ",") + "</coordinates>");
+ "," + location.getAltitude() + "</coordinates>");
printWriter.println("</Point>"); printWriter.println("</Point>");
printWriter.println("</Placemark>"); 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. * Writes the category.
* *
@@ -204,7 +204,9 @@ public class TcxTrackWriter implements TrackFormatWriter {
printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>"); printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>");
printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>"); printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>");
printWriter.println("</Position>"); printWriter.println("</Position>");
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>"); if (location.hasAltitude()) {
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
}
if (location instanceof MyTracksLocation) { if (location instanceof MyTracksLocation) {
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet(); SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();