forked from upstream-mirrors/OpenTracks
TrackPoint has Location as delegate instead of inheritance.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package de.dennisguse.opentracks;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
@@ -68,16 +70,15 @@ public class TrackStubUtils {
|
||||
* @return a SensorDataSetLocation stub.
|
||||
*/
|
||||
private static TrackPoint createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
||||
TrackPoint trackPoint = new TrackPoint(LOCATION_PROVIDER);
|
||||
trackPoint.setLatitude(latitude);
|
||||
trackPoint.setLongitude(longitude);
|
||||
trackPoint.setAltitude(altitude);
|
||||
trackPoint.setAccuracy(INITIAL_ACCURACY);
|
||||
trackPoint.setSpeed(INITIAL_SPEED);
|
||||
trackPoint.setTime(INITIAL_TIME);
|
||||
trackPoint.setBearing(INITIAL_BEARING);
|
||||
trackPoint.setSensorDataSet(new SensorDataSet(Float.NaN, Float.NaN));
|
||||
Location location = new Location(LOCATION_PROVIDER);
|
||||
location.setLatitude(latitude);
|
||||
location.setLongitude(longitude);
|
||||
location.setAltitude(altitude);
|
||||
location.setAccuracy(INITIAL_ACCURACY);
|
||||
location.setSpeed(INITIAL_SPEED);
|
||||
location.setTime(INITIAL_TIME);
|
||||
location.setBearing(INITIAL_BEARING);
|
||||
|
||||
return trackPoint;
|
||||
return new TrackPoint(location, new SensorDataSet(Float.NaN, Float.NaN));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.dennisguse.opentracks.content.data;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
public class TestDataUtil {
|
||||
|
||||
public static final double INITIAL_LATITUDE = 37.0;
|
||||
@@ -30,12 +32,12 @@ public class TestDataUtil {
|
||||
* @return created location
|
||||
*/
|
||||
public static TrackPoint createTrackPoint(int i) {
|
||||
TrackPoint trackpoint = new TrackPoint("test");
|
||||
trackpoint.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
||||
trackpoint.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
||||
trackpoint.setAccuracy((float) i / 100.0f);
|
||||
trackpoint.setAltitude(i * ALTITUDE_INTERVAL);
|
||||
trackpoint.setTime(i + 1);
|
||||
return trackpoint;
|
||||
Location location = new Location("test");
|
||||
location.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
||||
location.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
||||
location.setAccuracy((float) i / 100.0f);
|
||||
location.setAltitude(i * ALTITUDE_INTERVAL);
|
||||
location.setTime(i + 1);
|
||||
return new TrackPoint(location);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -81,7 +81,7 @@ public class CustomContentProviderUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testLocationIterator_customFactory() {
|
||||
final TrackPoint location = new TrackPoint("test_location");
|
||||
final TrackPoint location = new TrackPoint(new Location("test_location"));
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
testIterator(1, 15, 4, false, new TrackPointFactory() {
|
||||
@Override
|
||||
@@ -161,12 +161,12 @@ public class CustomContentProviderUtilsTest {
|
||||
|
||||
TrackPoint[] trackPoints = new TrackPoint[numPoints];
|
||||
for (int i = 0; i < numPoints; ++i) {
|
||||
TrackPoint loc = new TrackPoint("test");
|
||||
Location loc = new Location("test");
|
||||
loc.setLatitude(37.0 + (double) i / 10000.0);
|
||||
loc.setLongitude(57.0 - (double) i / 10000.0);
|
||||
loc.setAccuracy((float) i / 100.0f);
|
||||
loc.setAltitude(i * 2.5);
|
||||
trackPoints[i] = loc;
|
||||
trackPoints[i] = new TrackPoint(loc);
|
||||
}
|
||||
contentProviderUtils.bulkInsertTrackPoint(trackPoints, numPoints, id);
|
||||
|
||||
@@ -646,7 +646,7 @@ public class CustomContentProviderUtilsTest {
|
||||
insertTrackWithLocations(track);
|
||||
|
||||
TrackPoint lastTrackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
|
||||
checkLocation(9, lastTrackPoint);
|
||||
checkLocation(9, lastTrackPoint.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -709,7 +709,7 @@ public class CustomContentProviderUtilsTest {
|
||||
Assert.assertTrue(trackPointIterator.hasNext());
|
||||
TrackPoint trackPoint = trackPointIterator.next();
|
||||
Assert.assertEquals(startTrackPointId - i, trackPointIterator.getTrackPointId());
|
||||
checkLocation((trackpointIds.length - 1) - i, trackPoint);
|
||||
checkLocation((trackpointIds.length - 1) - i, trackPoint.getLocation());
|
||||
}
|
||||
Assert.assertFalse(trackPointIterator.hasNext());
|
||||
}
|
||||
@@ -734,10 +734,10 @@ public class CustomContentProviderUtilsTest {
|
||||
TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY);
|
||||
for (int i = 0; i < trackpointIds.length; i++) {
|
||||
Assert.assertTrue(locationIterator.hasNext());
|
||||
Location location = locationIterator.next();
|
||||
TrackPoint trackPoint = locationIterator.next();
|
||||
Assert.assertEquals(startTrackPointId + i, locationIterator.getTrackPointId());
|
||||
|
||||
checkLocation(i, location);
|
||||
checkLocation(i, trackPoint.getLocation());
|
||||
}
|
||||
Assert.assertFalse(locationIterator.hasNext());
|
||||
}
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ package de.dennisguse.opentracks.io.file.importer;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
|
||||
@@ -84,12 +85,12 @@ public abstract class AbstractTestFileTrackImporter {
|
||||
public ContentProviderUtils contentProviderUtils;
|
||||
|
||||
TrackPoint createTrackPoint(int index, long time) {
|
||||
TrackPoint trackPoint = new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||
Location trackPoint = new Location(LocationManager.GPS_PROVIDER);
|
||||
trackPoint.setLatitude(TRACK_LATITUDE + index);
|
||||
trackPoint.setLongitude(TRACK_LONGITUDE + index);
|
||||
trackPoint.setAltitude(TRACK_ELEVATION + index);
|
||||
trackPoint.setTime(time);
|
||||
return trackPoint;
|
||||
return new TrackPoint(trackPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class ExportImportTest {
|
||||
waypoint.setIcon("the waypoing icon" + i);
|
||||
waypoint.setPhotoUrl("the photo url" + i);
|
||||
waypoint.setTrackId(trackId);
|
||||
waypoint.setLocation(track.getTrackPoints().get(i));
|
||||
waypoint.setLocation(track.getTrackPoints().get(i).getLocation());
|
||||
contentProviderUtils.insertWaypoint(waypoint);
|
||||
|
||||
waypoints.add(waypoint);
|
||||
|
||||
+4
-4
@@ -43,10 +43,10 @@ public class TrackRecordingServiceNotificationManagerTest {
|
||||
TrackRecordingServiceNotificationManager subject = new TrackRecordingServiceNotificationManager(notificationManager, notificationCompatBuilder);
|
||||
|
||||
// when
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
subject.updateLocation(context, locationMock, 1000);
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
subject.updateTrackPoint(context, locationMock, 100);
|
||||
subject.updateTrackPoint(context, locationMock, 100);
|
||||
subject.updateTrackPoint(context, locationMock, 1000);
|
||||
subject.updateTrackPoint(context, locationMock, 100);
|
||||
|
||||
// then
|
||||
verify(notificationCompatBuilder, times(6)).setOnlyAlertOnce(true);
|
||||
|
||||
+11
-11
@@ -19,6 +19,7 @@ import android.content.ContentProvider;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
@@ -42,7 +43,6 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||
@@ -210,15 +210,15 @@ public class TrackRecordingServiceTest {
|
||||
/**
|
||||
* Inserts a location and waits for 200ms.
|
||||
*/
|
||||
private void insertTrackPoint(TrackRecordingServiceInterface trackRecordingService) throws InterruptedException {
|
||||
TrackPoint trackPoint = new TrackPoint("gps");
|
||||
trackPoint.setLongitude(35.0f);
|
||||
trackPoint.setLatitude(45.0f);
|
||||
trackPoint.setAccuracy(5);
|
||||
trackPoint.setSpeed(10);
|
||||
trackPoint.setTime(System.currentTimeMillis());
|
||||
trackPoint.setBearing(3.0f);
|
||||
trackRecordingService.insertTrackPoint(trackPoint);
|
||||
private void insertLocation(TrackRecordingServiceInterface trackRecordingService) throws InterruptedException {
|
||||
Location location = new Location("gps");
|
||||
location.setLongitude(35.0f);
|
||||
location.setLatitude(45.0f);
|
||||
location.setAccuracy(5);
|
||||
location.setSpeed(10);
|
||||
location.setTime(System.currentTimeMillis());
|
||||
location.setBearing(3.0f);
|
||||
trackRecordingService.insertLocation(location);
|
||||
|
||||
Thread.sleep(200);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
|
||||
service.startNewTrack();
|
||||
Assert.assertTrue(service.isRecording());
|
||||
insertTrackPoint(service);
|
||||
insertLocation(service);
|
||||
|
||||
long trackId = service.getRecordingTrackId();
|
||||
long waypointId = service.insertWaypoint(null, null, null, null);
|
||||
|
||||
+9
-9
@@ -3,6 +3,7 @@ package de.dennisguse.opentracks.services;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
@@ -25,7 +26,6 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||
@@ -208,14 +208,14 @@ public class TrackRecordingServiceTestLooper {
|
||||
// Insert a few points, markers and statistics.
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
TrackPoint trackPoint = new TrackPoint("gps");
|
||||
trackPoint.setLongitude(35.0f + i / 10.0f);
|
||||
trackPoint.setLatitude(45.0f - i / 5.0f);
|
||||
trackPoint.setAccuracy(5);
|
||||
trackPoint.setSpeed(10);
|
||||
trackPoint.setTime(startTime + i * 10000);
|
||||
trackPoint.setBearing(3.0f);
|
||||
service.insertTrackPoint(trackPoint);
|
||||
Location location = new Location("gps");
|
||||
location.setLongitude(35.0f + i / 10.0f);
|
||||
location.setLatitude(45.0f - i / 5.0f);
|
||||
location.setAccuracy(5);
|
||||
location.setSpeed(10);
|
||||
location.setTime(startTime + i * 10000);
|
||||
location.setBearing(3.0f);
|
||||
service.insertLocation(location);
|
||||
|
||||
if (i % 7 == 0) {
|
||||
service.insertWaypoint(null, null, null, null);
|
||||
|
||||
Reference in New Issue
Block a user