forked from upstream-mirrors/OpenTracks
Waypoint requires a non-null location.
Remove setLocation() from Waypoint and TrackPoint.
This commit is contained in:
@@ -100,19 +100,17 @@ public class SearchEngineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private long insertWaypoint(String title, String description, String category, double distance, long hoursAgo, long trackId) {
|
private long insertWaypoint(String title, String description, String category, double distance, long hoursAgo, long trackId) {
|
||||||
Waypoint waypoint = new Waypoint();
|
|
||||||
waypoint.setName(title);
|
|
||||||
waypoint.setDescription(description);
|
|
||||||
waypoint.setCategory(category);
|
|
||||||
waypoint.setTrackId(trackId);
|
|
||||||
|
|
||||||
Location location = new Location(HERE);
|
Location location = new Location(HERE);
|
||||||
location.setLatitude(location.getLatitude() + distance);
|
location.setLatitude(location.getLatitude() + distance);
|
||||||
location.setLongitude(location.getLongitude() + distance);
|
location.setLongitude(location.getLongitude() + distance);
|
||||||
if (hoursAgo >= 0) {
|
if (hoursAgo >= 0) {
|
||||||
location.setTime(NOW - hoursAgo * 1000L * 60L * 60L);
|
location.setTime(NOW - hoursAgo * 1000L * 60L * 60L);
|
||||||
}
|
}
|
||||||
waypoint.setLocation(location);
|
Waypoint waypoint = new Waypoint(location);
|
||||||
|
waypoint.setName(title);
|
||||||
|
waypoint.setDescription(description);
|
||||||
|
waypoint.setCategory(category);
|
||||||
|
waypoint.setTrackId(trackId);
|
||||||
|
|
||||||
Uri uri = providerUtils.insertWaypoint(waypoint);
|
Uri uri = providerUtils.insertWaypoint(waypoint);
|
||||||
return ContentUris.parseId(uri);
|
return ContentUris.parseId(uri);
|
||||||
|
|||||||
+3
-4
@@ -330,15 +330,14 @@ public class CustomContentProviderUtilsTest {
|
|||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
// Insert at first.
|
// Insert at first.
|
||||||
Waypoint waypoint = new Waypoint();
|
|
||||||
waypoint.setDescription(TEST_DESC);
|
|
||||||
|
|
||||||
Location location = new Location("test");
|
Location location = new Location("test");
|
||||||
location.setLatitude(22);
|
location.setLatitude(22);
|
||||||
location.setLongitude(22);
|
location.setLongitude(22);
|
||||||
location.setAccuracy((float) 1 / 100.0f);
|
location.setAccuracy((float) 1 / 100.0f);
|
||||||
location.setAltitude(2.5);
|
location.setAltitude(2.5);
|
||||||
waypoint.setLocation(location);
|
|
||||||
|
Waypoint waypoint = new Waypoint(location);
|
||||||
|
waypoint.setDescription(TEST_DESC);
|
||||||
contentProviderUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock);
|
||||||
|
|||||||
+1
-2
@@ -60,14 +60,13 @@ public class ExportImportTest {
|
|||||||
contentProviderUtils.bulkInsertTrackPoint(track.getTrackPoints().toArray(new TrackPoint[0]), track.getTrackPoints().size(), track.getId());
|
contentProviderUtils.bulkInsertTrackPoint(track.getTrackPoints().toArray(new TrackPoint[0]), track.getTrackPoints().size(), track.getId());
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint(track.getTrackPoints().get(i).getLocation());
|
||||||
waypoint.setName("the waypoint " + i);
|
waypoint.setName("the waypoint " + i);
|
||||||
waypoint.setDescription("the waypoint description " + i);
|
waypoint.setDescription("the waypoint description " + i);
|
||||||
waypoint.setCategory("the waypoint category" + i);
|
waypoint.setCategory("the waypoint category" + i);
|
||||||
waypoint.setIcon("the waypoing icon" + i);
|
waypoint.setIcon("the waypoing icon" + i);
|
||||||
waypoint.setPhotoUrl("the photo url" + i);
|
waypoint.setPhotoUrl("the photo url" + i);
|
||||||
waypoint.setTrackId(trackId);
|
waypoint.setTrackId(trackId);
|
||||||
waypoint.setLocation(track.getTrackPoints().get(i).getLocation());
|
|
||||||
contentProviderUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
waypoints.add(waypoint);
|
waypoints.add(waypoint);
|
||||||
|
|||||||
@@ -90,10 +90,6 @@ public class TrackPoint {
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(@NonNull Location location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SensorDataSet getSensorDataSet() {
|
public SensorDataSet getSensorDataSet() {
|
||||||
return sensorDataSet;
|
return sensorDataSet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.location.Location;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A waypoint.
|
* A waypoint.
|
||||||
@@ -40,10 +41,15 @@ public final class Waypoint {
|
|||||||
private Location location = null;
|
private Location location = null;
|
||||||
private String photoUrl = "";
|
private String photoUrl = "";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
public Waypoint() {
|
public Waypoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Waypoint(String name, String description, String category, String icon, long trackId, double length, long duration, Location location, String photoUrl) {
|
public Waypoint(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Waypoint(String name, String description, String category, String icon, long trackId, double length, long duration, @NonNull Location location, String photoUrl) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.category = category;
|
this.category = category;
|
||||||
@@ -124,10 +130,6 @@ public final class Waypoint {
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(@NonNull Location location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhotoUrl() {
|
public String getPhotoUrl() {
|
||||||
return photoUrl;
|
return photoUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,7 +356,25 @@ public class ContentProviderUtils {
|
|||||||
int bearingIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.BEARING);
|
int bearingIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.BEARING);
|
||||||
int photoUrlIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.PHOTOURL);
|
int photoUrlIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.PHOTOURL);
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
Location location = new Location("");
|
||||||
|
if (!cursor.isNull(longitudeIndex) && !cursor.isNull(latitudeIndex)) {
|
||||||
|
location.setLongitude(((double) cursor.getInt(longitudeIndex)) / 1E6);
|
||||||
|
location.setLatitude(((double) cursor.getInt(latitudeIndex)) / 1E6);
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(timeIndex)) {
|
||||||
|
location.setTime(cursor.getLong(timeIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(altitudeIndex)) {
|
||||||
|
location.setAltitude(cursor.getFloat(altitudeIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(accuracyIndex)) {
|
||||||
|
location.setAccuracy(cursor.getFloat(accuracyIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(bearingIndex)) {
|
||||||
|
location.setBearing(cursor.getFloat(bearingIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
Waypoint waypoint = new Waypoint(location);
|
||||||
|
|
||||||
if (!cursor.isNull(idIndex)) {
|
if (!cursor.isNull(idIndex)) {
|
||||||
waypoint.setId(cursor.getLong(idIndex));
|
waypoint.setId(cursor.getLong(idIndex));
|
||||||
@@ -383,25 +401,6 @@ public class ContentProviderUtils {
|
|||||||
waypoint.setDuration(cursor.getLong(durationIndex));
|
waypoint.setDuration(cursor.getLong(durationIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = new Location("");
|
|
||||||
if (!cursor.isNull(longitudeIndex) && !cursor.isNull(latitudeIndex)) {
|
|
||||||
location.setLongitude(((double) cursor.getInt(longitudeIndex)) / 1E6);
|
|
||||||
location.setLatitude(((double) cursor.getInt(latitudeIndex)) / 1E6);
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(timeIndex)) {
|
|
||||||
location.setTime(cursor.getLong(timeIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(altitudeIndex)) {
|
|
||||||
location.setAltitude(cursor.getFloat(altitudeIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(accuracyIndex)) {
|
|
||||||
location.setAccuracy(cursor.getFloat(accuracyIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(bearingIndex)) {
|
|
||||||
location.setBearing(cursor.getFloat(bearingIndex));
|
|
||||||
}
|
|
||||||
waypoint.setLocation(location);
|
|
||||||
|
|
||||||
if (!cursor.isNull(photoUrlIndex)) {
|
if (!cursor.isNull(photoUrlIndex)) {
|
||||||
waypoint.setPhotoUrl(cursor.getString(photoUrlIndex));
|
waypoint.setPhotoUrl(cursor.getString(photoUrlIndex));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -284,13 +284,12 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
|
||||||
TrackPoint trackPoint = createTrackPoint();
|
TrackPoint trackPoint = createTrackPoint();
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(trackPoint.getLocation())) {
|
if (!LocationUtils.isValidLocation(trackPoint.getLocation())) {
|
||||||
throw new SAXException(createErrorMessage("Invalid location detected: " + trackPoint));
|
throw new SAXException(createErrorMessage("Invalid location detected: " + trackPoint));
|
||||||
}
|
}
|
||||||
waypoint.setLocation(trackPoint.getLocation());
|
Waypoint waypoint = new Waypoint(trackPoint.getLocation());
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
waypoint.setName(name);
|
waypoint.setName(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user