forked from upstream-mirrors/OpenTracks
Test: export and import tracks via KML and GPX; now includes waypoints.
TripStatistics is not tested.
This commit is contained in:
@@ -126,17 +126,14 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||
|
||||
contentProviderUtils = new ContentProviderUtils(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
|
||||
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
track = trackId != -1L ? contentProviderUtils.getTrack(trackId) : null;
|
||||
final long trackFirstWaypointId = trackId != -1 ? contentProviderUtils.getFirstWaypointId(trackId) : -1;
|
||||
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
listView = findViewById(R.id.marker_list);
|
||||
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
||||
@@ -181,8 +178,8 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
if (track != null) {
|
||||
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
||||
WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?",
|
||||
new String[]{String.valueOf(track.getId()), String.valueOf(trackFirstWaypointId)}, null);
|
||||
WaypointsColumns.TRACKID + "=?",
|
||||
new String[]{String.valueOf(track.getId())}, null);
|
||||
} else {
|
||||
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
||||
WaypointsColumns.STARTTIME + " IS NULL", null, null);
|
||||
|
||||
@@ -539,7 +539,7 @@ public class ContentProviderUtils {
|
||||
* If deleting a statistics waypoint, this will also correct the next statistics waypoint after the deleted one to reflect the deletion.
|
||||
* The generator is used to update the next statistics waypoint.
|
||||
*
|
||||
* @param waypointId the waypoint id
|
||||
* @param waypointId the waypoint id
|
||||
*/
|
||||
|
||||
public void deleteWaypoint(Context context, long waypointId) {
|
||||
@@ -559,29 +559,10 @@ public class ContentProviderUtils {
|
||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns._ID + "=?", new String[]{Long.toString(waypointId)});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first waypoint id for a track.
|
||||
* The first waypoint is special as it contains the stats for the track.
|
||||
* Returns -1L if it doesn't exist.
|
||||
*
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public long getFirstWaypointId(long trackId) {
|
||||
if (trackId < 0) {
|
||||
return -1L;
|
||||
}
|
||||
try (Cursor cursor = getWaypointCursor(new String[]{WaypointsColumns._ID}, WaypointsColumns.TRACKID + "=?", new String[]{Long.toString(trackId)}, WaypointsColumns._ID, 1)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getLong(cursor.getColumnIndexOrThrow(WaypointsColumns._ID));
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last waypoint for a type. Returns null if it doesn't exist.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public Waypoint getLastWaypoint(long trackId) {
|
||||
if (trackId < 0) {
|
||||
@@ -602,7 +583,7 @@ public class ContentProviderUtils {
|
||||
* Gets the next waypoint number for a type.
|
||||
* Returns -1 if not able to get the next waypoint number.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public int getNextWaypointNumber(long trackId) {
|
||||
if (trackId < 0) {
|
||||
@@ -677,6 +658,19 @@ public class ContentProviderUtils {
|
||||
return getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, maxWaypoints);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public List<Waypoint> getWaypoints(long trackId) {
|
||||
ArrayList<Waypoint> waypoints = new ArrayList<>();
|
||||
try (Cursor cursor = getWaypointCursor(trackId, -1L, -1)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
waypoints.add(createWaypoint(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of waypoints for a track.
|
||||
*
|
||||
@@ -695,8 +689,7 @@ public class ContentProviderUtils {
|
||||
cursor.moveToFirst();
|
||||
int count = cursor.getInt(0);
|
||||
cursor.close();
|
||||
// not count the first waypoint
|
||||
return count > 0 ? count - 1 : 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -894,23 +887,6 @@ public class ContentProviderUtils {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first valid location for a track.
|
||||
* Returns null if it doesn't exist.
|
||||
*
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public Location getFirstValidTrackPoint(long trackId) {
|
||||
if (trackId < 0) {
|
||||
return null;
|
||||
}
|
||||
String selection = TrackPointsColumns._ID + "=(select min(" + TrackPointsColumns._ID + ") from "
|
||||
+ TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + "=? AND "
|
||||
+ TrackPointsColumns.LATITUDE + "<=" + MAX_LATITUDE + ")";
|
||||
String[] selectionArgs = new String[]{Long.toString(trackId)};
|
||||
return findTrackPointBy(selection, selectionArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last valid location for a track.
|
||||
* Returns null if it doesn't exist.
|
||||
@@ -1086,9 +1062,11 @@ public class ContentProviderUtils {
|
||||
values.put(TrackPointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6));
|
||||
|
||||
// Hack for Samsung phones that don't properly populate the time field
|
||||
long time = location.getTime();
|
||||
// TODO: Check if this is really necessary!
|
||||
// Hack for Samsung phones that don't properly populate the time field
|
||||
if (time == 0) {
|
||||
Log.w(TAG, "location has no timestamp; setting current time");
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
values.put(TrackPointsColumns.TIME, time);
|
||||
|
||||
@@ -99,7 +99,6 @@ public class FileTrackExporter implements TrackExporter {
|
||||
boolean hasWaypoints = false;
|
||||
try (Cursor cursor = contentProviderUtils.getWaypointCursor(track.getId(), -1L, ContentProviderUtils.MAX_LOADED_WAYPOINTS_POINTS)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
// Intentionally skip first waypoint (contains statistics).
|
||||
for (int i = 0; i < cursor.getCount(); i++) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
|
||||
@@ -174,6 +174,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (location == null) {
|
||||
if (!locationIterator.hasNext()) {
|
||||
// No more track points. Ignore the rest of the waypoints.
|
||||
@@ -183,9 +184,11 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
||||
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval);
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
}
|
||||
|
||||
if (waypoint.getLocation().getTime() > location.getTime()) {
|
||||
location = null;
|
||||
} else if (waypoint.getLocation().getTime() < location.getTime()) {
|
||||
Log.w(TAG, "Ignoring waypoint: current location was after waypoint.");
|
||||
waypoint = null;
|
||||
} else {
|
||||
// The waypoint location time matches the track point time
|
||||
|
||||
@@ -164,6 +164,7 @@ public class LocationUtils {
|
||||
* @param location the location to test
|
||||
* @return true if the location is a valid location.
|
||||
*/
|
||||
//TODO Still needed?
|
||||
public static boolean isValidLocation(Location location) {
|
||||
return location != null
|
||||
&& Math.abs(location.getLatitude()) <= 90
|
||||
|
||||
Reference in New Issue
Block a user