forked from upstream-mirrors/OpenTracks
Use TrackPoint instead of Location (and omit casting).
This commit is contained in:
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
@@ -49,7 +47,7 @@ public class TrackStubUtils {
|
|||||||
public static Track createTrack(int numberOfLocations) {
|
public static Track createTrack(int numberOfLocations) {
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
for (int i = 0; i < numberOfLocations; i++) {
|
for (int i = 0; i < numberOfLocations; i++) {
|
||||||
track.addLocation(createSensorDataSetLocation(INITIAL_LATITUDE + i * DIFFERENCE, INITIAL_LONGITUDE + i * DIFFERENCE, INITIAL_ALTITUDE + i * DIFFERENCE));
|
track.addTrackPoint(createSensorDataSetLocation(INITIAL_LATITUDE + i * DIFFERENCE, INITIAL_LONGITUDE + i * DIFFERENCE, INITIAL_ALTITUDE + i * DIFFERENCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return track;
|
return track;
|
||||||
@@ -70,17 +68,16 @@ public class TrackStubUtils {
|
|||||||
* @return a SensorDataSetLocation stub.
|
* @return a SensorDataSetLocation stub.
|
||||||
*/
|
*/
|
||||||
private static TrackPoint createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
private static TrackPoint createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
||||||
// Initial Location
|
TrackPoint trackPoint = new TrackPoint(LOCATION_PROVIDER);
|
||||||
Location loc = new Location(LOCATION_PROVIDER);
|
trackPoint.setLatitude(latitude);
|
||||||
loc.setLatitude(latitude);
|
trackPoint.setLongitude(longitude);
|
||||||
loc.setLongitude(longitude);
|
trackPoint.setAltitude(altitude);
|
||||||
loc.setAltitude(altitude);
|
trackPoint.setAccuracy(INITIAL_ACCURACY);
|
||||||
loc.setAccuracy(INITIAL_ACCURACY);
|
trackPoint.setSpeed(INITIAL_SPEED);
|
||||||
loc.setSpeed(INITIAL_SPEED);
|
trackPoint.setTime(INITIAL_TIME);
|
||||||
loc.setTime(INITIAL_TIME);
|
trackPoint.setBearing(INITIAL_BEARING);
|
||||||
loc.setBearing(INITIAL_BEARING);
|
trackPoint.setSensorDataSet(new SensorDataSet(Float.NaN, Float.NaN));
|
||||||
SensorDataSet sd = new SensorDataSet(Float.NaN, Float.NaN);
|
|
||||||
|
|
||||||
return new TrackPoint(loc, sd);
|
return trackPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package de.dennisguse.opentracks.content.data;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
public class TestDataUtil {
|
public class TestDataUtil {
|
||||||
|
|
||||||
public static final double INITIAL_LATITUDE = 37.0;
|
public static final double INITIAL_LATITUDE = 37.0;
|
||||||
@@ -20,7 +18,7 @@ public class TestDataUtil {
|
|||||||
track.setId(id);
|
track.setId(id);
|
||||||
track.setName("Test: " + id);
|
track.setName("Test: " + id);
|
||||||
for (int i = 0; i < numPoints; i++) {
|
for (int i = 0; i < numPoints; i++) {
|
||||||
track.addLocation(createLocation(i));
|
track.addTrackPoint(createTrackPoint(i));
|
||||||
}
|
}
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
@@ -31,13 +29,13 @@ public class TestDataUtil {
|
|||||||
* @param i the index to set the value of location.
|
* @param i the index to set the value of location.
|
||||||
* @return created location
|
* @return created location
|
||||||
*/
|
*/
|
||||||
public static Location createLocation(int i) {
|
public static TrackPoint createTrackPoint(int i) {
|
||||||
Location loc = new Location("test");
|
TrackPoint trackpoint = new TrackPoint("test");
|
||||||
loc.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
trackpoint.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
||||||
loc.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
trackpoint.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
||||||
loc.setAccuracy((float) i / 100.0f);
|
trackpoint.setAccuracy((float) i / 100.0f);
|
||||||
loc.setAltitude(i * ALTITUDE_INTERVAL);
|
trackpoint.setAltitude(i * ALTITUDE_INTERVAL);
|
||||||
loc.setTime(i + 1);
|
trackpoint.setTime(i + 1);
|
||||||
return loc;
|
return trackpoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-32
@@ -85,7 +85,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
final AtomicInteger counter = new AtomicInteger();
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
testIterator(1, 15, 4, false, new TrackPointFactory() {
|
testIterator(1, 15, 4, false, new TrackPointFactory() {
|
||||||
@Override
|
@Override
|
||||||
public TrackPoint createLocation() {
|
public TrackPoint create() {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
@@ -133,13 +133,13 @@ public class CustomContentProviderUtilsTest {
|
|||||||
testIterator(1, 20000, 2000, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 20000, 2000, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Location> testIterator(long trackId, int numPoints, int batchSize, boolean descending, TrackPointFactory trackPointFactory) {
|
private List<TrackPoint> testIterator(long trackId, int numPoints, int batchSize, boolean descending, TrackPointFactory trackPointFactory) {
|
||||||
long lastPointId = initializeTrack(trackId, numPoints);
|
long lastPointId = initializeTrack(trackId, numPoints);
|
||||||
contentProviderUtils.setDefaultCursorBatchSize(batchSize);
|
contentProviderUtils.setDefaultCursorBatchSize(batchSize);
|
||||||
List<Location> locations = new ArrayList<Location>(numPoints);
|
List<TrackPoint> locations = new ArrayList<>(numPoints);
|
||||||
try (TrackPointIterator it = contentProviderUtils.getTrackPointLocationIterator(trackId, -1L, descending, trackPointFactory)) {
|
try (TrackPointIterator it = contentProviderUtils.getTrackPointLocationIterator(trackId, -1L, descending, trackPointFactory)) {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Location loc = it.next();
|
TrackPoint loc = it.next();
|
||||||
Assert.assertNotNull(loc);
|
Assert.assertNotNull(loc);
|
||||||
locations.add(loc);
|
locations.add(loc);
|
||||||
// Make sure the IDs are returned in the right order.
|
// Make sure the IDs are returned in the right order.
|
||||||
@@ -159,18 +159,18 @@ public class CustomContentProviderUtilsTest {
|
|||||||
track = contentProviderUtils.getTrack(id);
|
track = contentProviderUtils.getTrack(id);
|
||||||
Assert.assertNotNull(track);
|
Assert.assertNotNull(track);
|
||||||
|
|
||||||
Location[] locations = new Location[numPoints];
|
TrackPoint[] trackPoints = new TrackPoint[numPoints];
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
Location loc = new Location("test");
|
TrackPoint loc = new TrackPoint("test");
|
||||||
loc.setLatitude(37.0 + (double) i / 10000.0);
|
loc.setLatitude(37.0 + (double) i / 10000.0);
|
||||||
loc.setLongitude(57.0 - (double) i / 10000.0);
|
loc.setLongitude(57.0 - (double) i / 10000.0);
|
||||||
loc.setAccuracy((float) i / 100.0f);
|
loc.setAccuracy((float) i / 100.0f);
|
||||||
loc.setAltitude(i * 2.5);
|
loc.setAltitude(i * 2.5);
|
||||||
locations[i] = loc;
|
trackPoints[i] = loc;
|
||||||
}
|
}
|
||||||
contentProviderUtils.bulkInsertTrackPoint(locations, numPoints, id);
|
contentProviderUtils.bulkInsertTrackPoint(trackPoints, numPoints, id);
|
||||||
|
|
||||||
// Load all inserted locations.
|
// Load all inserted trackPoints.
|
||||||
long lastPointId = -1;
|
long lastPointId = -1;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
try (TrackPointIterator it = contentProviderUtils.getTrackPointLocationIterator(id, -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
try (TrackPointIterator it = contentProviderUtils.getTrackPointLocationIterator(id, -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
@@ -546,7 +546,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtils#bulkInsertTrackPoint(Location[], int, long)}.
|
* Tests the method {@link ContentProviderUtils#bulkInsertTrackPoint(TrackPoint[], int, long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBulkInsertTrackPoint() {
|
public void testBulkInsertTrackPoint() {
|
||||||
@@ -555,9 +555,9 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId);
|
contentProviderUtils.bulkInsertTrackPoint(track.getTrackPoints().toArray(new TrackPoint[0]), -1, trackId);
|
||||||
Assert.assertEquals(20, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(20, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId);
|
contentProviderUtils.bulkInsertTrackPoint(track.getTrackPoints().toArray(new TrackPoint[0]), 8, trackId);
|
||||||
Assert.assertEquals(28, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(28, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,7 +613,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
byte[] sensor = "Sensor state".getBytes();
|
byte[] sensor = "Sensor state".getBytes();
|
||||||
when(cursorMock.getBlob(index++)).thenReturn(sensor);
|
when(cursorMock.getBlob(index++)).thenReturn(sensor);
|
||||||
|
|
||||||
Location location = contentProviderUtils.createTrackPoint(cursorMock);
|
TrackPoint location = contentProviderUtils.createTrackPoint(cursorMock);
|
||||||
Assert.assertEquals(longitude, location.getLongitude(), 0.01);
|
Assert.assertEquals(longitude, location.getLongitude(), 0.01);
|
||||||
Assert.assertEquals(latitude, location.getLatitude(), 0.01);
|
Assert.assertEquals(latitude, location.getLatitude(), 0.01);
|
||||||
Assert.assertEquals(time, location.getTime(), 0.01);
|
Assert.assertEquals(time, location.getTime(), 0.01);
|
||||||
@@ -622,7 +622,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtils#insertTrackPoint(Location, long)}.
|
* {@link ContentProviderUtils#insertTrackPoint(TrackPoint, long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInsertTrackPoint() {
|
public void testInsertTrackPoint() {
|
||||||
@@ -631,7 +631,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
contentProviderUtils.insertTrackPoint(TestDataUtil.createLocation(22), trackId);
|
contentProviderUtils.insertTrackPoint(TestDataUtil.createTrackPoint(22), trackId);
|
||||||
Assert.assertEquals(11, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(11, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,8 +645,8 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
Location lastLocation = contentProviderUtils.getLastValidTrackPoint(trackId);
|
TrackPoint lastTrackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
|
||||||
checkLocation(9, lastLocation);
|
checkLocation(9, lastTrackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -659,9 +659,9 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getLocations().size()];
|
long[] trackpointIds = new long[track.getTrackPoints().size()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getTrackPoints().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true);
|
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true);
|
||||||
@@ -678,9 +678,9 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getLocations().size()];
|
long[] trackpointIds = new long[track.getTrackPoints().size()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getTrackPoints().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false);
|
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false);
|
||||||
@@ -697,21 +697,21 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getLocations().size()];
|
long[] trackpointIds = new long[track.getTrackPoints().size()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getTrackPoints().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long startTrackPointId = trackpointIds[9];
|
long startTrackPointId = trackpointIds[9];
|
||||||
|
|
||||||
TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, TrackPointFactory.DEFAULT_LOCATION_FACTORY);
|
TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, TrackPointFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
Assert.assertTrue(locationIterator.hasNext());
|
Assert.assertTrue(trackPointIterator.hasNext());
|
||||||
Location location = locationIterator.next();
|
TrackPoint trackPoint = trackPointIterator.next();
|
||||||
Assert.assertEquals(startTrackPointId - i, locationIterator.getTrackPointId());
|
Assert.assertEquals(startTrackPointId - i, trackPointIterator.getTrackPointId());
|
||||||
checkLocation((trackpointIds.length - 1) - i, location);
|
checkLocation((trackpointIds.length - 1) - i, trackPoint);
|
||||||
}
|
}
|
||||||
Assert.assertFalse(locationIterator.hasNext());
|
Assert.assertFalse(trackPointIterator.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -724,9 +724,9 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Track track = TestDataUtil.getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getLocations().size()];
|
long[] trackpointIds = new long[track.getTrackPoints().size()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getTrackPoints().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long startTrackPointId = trackpointIds[0];
|
long startTrackPointId = trackpointIds[0];
|
||||||
@@ -762,7 +762,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
*/
|
*/
|
||||||
private void insertTrackWithLocations(Track track) {
|
private void insertTrackWithLocations(Track track) {
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId());
|
contentProviderUtils.bulkInsertTrackPoint(track.getTrackPoints().toArray(new TrackPoint[0]), track.getTrackPoints().size(), track.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the incorrect values of sensor in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the incorrect values of sensor in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_sensorIncorrect() {
|
public void testFillDataPoint_sensorIncorrect() {
|
||||||
@@ -91,7 +91,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the correct values of sensor in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the correct values of sensor in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_sensorCorrect() {
|
public void testFillDataPoint_sensorCorrect() {
|
||||||
@@ -115,7 +115,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of metric Distance in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the value of metric Distance in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_distanceMetric() {
|
public void testFillDataPoint_distanceMetric() {
|
||||||
@@ -156,7 +156,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of imperial Distance in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the value of imperial Distance in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_distanceImperial() {
|
public void testFillDataPoint_distanceImperial() {
|
||||||
@@ -199,7 +199,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the values of time in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the values of time in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_time() {
|
public void testFillDataPoint_time() {
|
||||||
@@ -216,7 +216,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of elevation in {@link ChartFragment#fillDataPoint(Location, double[])} by one and two points.
|
* Tests the logic to get the value of elevation in {@link ChartFragment#fillDataPoint(TrackPoint, double[])} by one and two points.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_elevation() {
|
public void testFillDataPoint_elevation() {
|
||||||
@@ -240,7 +240,7 @@ public class ChartFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of speed in {@link ChartFragment#fillDataPoint(Location, double[])}.
|
* Tests the logic to get the value of speed in {@link ChartFragment#fillDataPoint(TrackPoint, double[])}.
|
||||||
* In this test, firstly remove all points in memory, and then fill in two points one by one.
|
* In this test, firstly remove all points in memory, and then fill in two points one by one.
|
||||||
* The speed values of these points are 129, 130.
|
* The speed values of these points are 129, 130.
|
||||||
*/
|
*/
|
||||||
@@ -338,12 +338,12 @@ public class ChartFragmentTest {
|
|||||||
/**
|
/**
|
||||||
* Helper method to test fillDataPoint.
|
* Helper method to test fillDataPoint.
|
||||||
*
|
*
|
||||||
* @param location location to fill
|
* @param trackPoint trackPoint to fill
|
||||||
* @return data of this location
|
* @return data of this trackPoint
|
||||||
*/
|
*/
|
||||||
private double[] fillDataPointTestHelper(Location location) {
|
private double[] fillDataPointTestHelper(TrackPoint trackPoint) {
|
||||||
double[] point = new double[ChartView.NUM_SERIES + 1];
|
double[] point = new double[ChartView.NUM_SERIES + 1];
|
||||||
chartFragment.fillDataPoint(location, point);
|
chartFragment.fillDataPoint(trackPoint, point);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -18,7 +18,6 @@ package de.dennisguse.opentracks.io.file.importer;
|
|||||||
|
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
@@ -33,6 +32,7 @@ import java.util.Locale;
|
|||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.data.TracksColumns;
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
@@ -83,24 +83,24 @@ public abstract class AbstractTestFileTrackImporter {
|
|||||||
@Mock
|
@Mock
|
||||||
public ContentProviderUtils contentProviderUtils;
|
public ContentProviderUtils contentProviderUtils;
|
||||||
|
|
||||||
Location createLocation(int index, long time) {
|
TrackPoint createTrackPoint(int index, long time) {
|
||||||
Location location = new Location(LocationManager.GPS_PROVIDER);
|
TrackPoint trackPoint = new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
location.setLatitude(TRACK_LATITUDE + index);
|
trackPoint.setLatitude(TRACK_LATITUDE + index);
|
||||||
location.setLongitude(TRACK_LONGITUDE + index);
|
trackPoint.setLongitude(TRACK_LONGITUDE + index);
|
||||||
location.setAltitude(TRACK_ELEVATION + index);
|
trackPoint.setAltitude(TRACK_ELEVATION + index);
|
||||||
location.setTime(time);
|
trackPoint.setTime(time);
|
||||||
return location;
|
return trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expects the first track point to be added.
|
* Expects the first track point to be added.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
* @param trackPointId the track point id
|
* @param trackPointId the track point id
|
||||||
*/
|
*/
|
||||||
protected void expectFirstTrackPoint(Location location, long trackId, long trackPointId) {
|
protected void expectFirstTrackPoint(TrackPoint trackPoint, long trackId, long trackPointId) {
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint(location != null ? (Location[]) any() : (Location[]) any(), eq(1), eq(trackId))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint(trackPoint != null ? (TrackPoint[]) any() : (TrackPoint[]) any(), eq(1), eq(trackId))).thenReturn(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,6 @@
|
|||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -21,6 +20,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
@@ -57,7 +57,7 @@ public class ExportImportTest {
|
|||||||
track.setCategory(TRACK_CATEGORY);
|
track.setCategory(TRACK_CATEGORY);
|
||||||
track.setDescription(TRACK_DESCRIPTION);
|
track.setDescription(TRACK_DESCRIPTION);
|
||||||
contentProviderUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().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();
|
||||||
@@ -67,7 +67,7 @@ public class ExportImportTest {
|
|||||||
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.getLocations().get(i));
|
waypoint.setLocation(track.getTrackPoints().get(i));
|
||||||
contentProviderUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
waypoints.add(waypoint);
|
waypoints.add(waypoint);
|
||||||
@@ -114,7 +114,7 @@ public class ExportImportTest {
|
|||||||
// 1. track
|
// 1. track
|
||||||
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
||||||
assertNotNull(importedTrack);
|
assertNotNull(importedTrack);
|
||||||
assertEquals(track.getLocations(), importedTrack.getLocations());
|
assertEquals(track.getTrackPoints(), importedTrack.getTrackPoints());
|
||||||
assertEquals(track.getCategory(), importedTrack.getCategory());
|
assertEquals(track.getCategory(), importedTrack.getCategory());
|
||||||
assertEquals(track.getDescription(), importedTrack.getDescription());
|
assertEquals(track.getDescription(), importedTrack.getDescription());
|
||||||
assertEquals(track.getName(), importedTrack.getName());
|
assertEquals(track.getName(), importedTrack.getName());
|
||||||
@@ -184,7 +184,7 @@ public class ExportImportTest {
|
|||||||
// 1. track
|
// 1. track
|
||||||
Track trackImported = contentProviderUtils.getTrack(importTrackId);
|
Track trackImported = contentProviderUtils.getTrack(importTrackId);
|
||||||
assertNotNull(trackImported);
|
assertNotNull(trackImported);
|
||||||
assertEquals(track.getLocations(), trackImported.getLocations());
|
assertEquals(track.getTrackPoints(), trackImported.getTrackPoints());
|
||||||
assertEquals(track.getCategory(), trackImported.getCategory());
|
assertEquals(track.getCategory(), trackImported.getCategory());
|
||||||
assertEquals(track.getDescription(), trackImported.getDescription());
|
assertEquals(track.getDescription(), trackImported.getDescription());
|
||||||
assertEquals(track.getName(), trackImported.getName());
|
assertEquals(track.getName(), trackImported.getName());
|
||||||
|
|||||||
+10
-11
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -28,6 +26,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
@@ -85,14 +84,14 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
@Test
|
@Test
|
||||||
public void testOneTrackOneSegment() throws Exception {
|
public void testOneTrackOneSegment() throws Exception {
|
||||||
// given
|
// given
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
TrackPoint trackPoint0 = createTrackPoint(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
TrackPoint trackPoint1 = createTrackPoint(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||||
|
|
||||||
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(trackPoint0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
@@ -116,12 +115,12 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
@Test
|
@Test
|
||||||
public void testOneTrackTwoSegments() throws Exception {
|
public void testOneTrackTwoSegments() throws Exception {
|
||||||
// given
|
// given
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
TrackPoint trackPoint0 = createTrackPoint(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
|
|
||||||
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(trackPoint0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
|
|
||||||
@@ -207,7 +206,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
||||||
|
|
||||||
// For the following, use StubReturn since we don't care whether they are invoked or not.
|
// For the following, use StubReturn since we don't care whether they are invoked or not.
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), anyInt(), anyLong())).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), anyInt(), anyLong())).thenReturn(1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
contentProviderUtils.deleteTrack(context, TRACK_ID_0);
|
contentProviderUtils.deleteTrack(context, TRACK_ID_0);
|
||||||
|
|
||||||
|
|||||||
+8
-9
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -28,6 +26,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
@@ -69,14 +68,14 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
@Test
|
@Test
|
||||||
public void testOneTrackOneSegment() throws Exception {
|
public void testOneTrackOneSegment() throws Exception {
|
||||||
// given
|
// given
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
TrackPoint trackPoint0 = createTrackPoint(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
TrackPoint trackPointl1 = createTrackPoint(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||||
|
|
||||||
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(trackPoint0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
|
|
||||||
@@ -101,13 +100,13 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
@Test
|
@Test
|
||||||
public void testOneTrackTwoSegments() throws Exception {
|
public void testOneTrackTwoSegments() throws Exception {
|
||||||
// given
|
// given
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
TrackPoint trackPoint0 = createTrackPoint(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
|
|
||||||
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(trackPoint0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((TrackPoint[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -2,7 +2,6 @@ package de.dennisguse.opentracks.services;
|
|||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -12,6 +11,8 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -24,7 +25,7 @@ public class TrackRecordingServiceNotificationManagerTest {
|
|||||||
private Context context = ApplicationProvider.getApplicationContext();
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Location locationMock;
|
private TrackPoint locationMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationCompat.Builder notificationCompatBuilder;
|
private NotificationCompat.Builder notificationCompatBuilder;
|
||||||
|
|||||||
+11
-11
@@ -19,7 +19,6 @@ import android.content.ContentProvider;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -43,6 +42,7 @@ import java.util.concurrent.TimeoutException;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||||
@@ -210,15 +210,15 @@ public class TrackRecordingServiceTest {
|
|||||||
/**
|
/**
|
||||||
* Inserts a location and waits for 200ms.
|
* Inserts a location and waits for 200ms.
|
||||||
*/
|
*/
|
||||||
private void insertLocation(TrackRecordingServiceInterface trackRecordingService) throws InterruptedException {
|
private void insertTrackPoint(TrackRecordingServiceInterface trackRecordingService) throws InterruptedException {
|
||||||
Location location = new Location("gps");
|
TrackPoint trackPoint = new TrackPoint("gps");
|
||||||
location.setLongitude(35.0f);
|
trackPoint.setLongitude(35.0f);
|
||||||
location.setLatitude(45.0f);
|
trackPoint.setLatitude(45.0f);
|
||||||
location.setAccuracy(5);
|
trackPoint.setAccuracy(5);
|
||||||
location.setSpeed(10);
|
trackPoint.setSpeed(10);
|
||||||
location.setTime(System.currentTimeMillis());
|
trackPoint.setTime(System.currentTimeMillis());
|
||||||
location.setBearing(3.0f);
|
trackPoint.setBearing(3.0f);
|
||||||
trackRecordingService.insertTrackPoint(location);
|
trackRecordingService.insertTrackPoint(trackPoint);
|
||||||
|
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ public class TrackRecordingServiceTest {
|
|||||||
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
|
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
|
||||||
service.startNewTrack();
|
service.startNewTrack();
|
||||||
Assert.assertTrue(service.isRecording());
|
Assert.assertTrue(service.isRecording());
|
||||||
insertLocation(service);
|
insertTrackPoint(service);
|
||||||
|
|
||||||
long trackId = service.getRecordingTrackId();
|
long trackId = service.getRecordingTrackId();
|
||||||
long waypointId = service.insertWaypoint(null, null, null, null);
|
long waypointId = service.insertWaypoint(null, null, null, null);
|
||||||
|
|||||||
+9
-9
@@ -3,7 +3,6 @@ package de.dennisguse.opentracks.services;
|
|||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -26,6 +25,7 @@ import java.util.concurrent.TimeoutException;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
@@ -208,14 +208,14 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
// Insert a few points, markers and statistics.
|
// Insert a few points, markers and statistics.
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
for (int i = 0; i < 30; i++) {
|
for (int i = 0; i < 30; i++) {
|
||||||
Location location = new Location("gps");
|
TrackPoint trackPoint = new TrackPoint("gps");
|
||||||
location.setLongitude(35.0f + i / 10.0f);
|
trackPoint.setLongitude(35.0f + i / 10.0f);
|
||||||
location.setLatitude(45.0f - i / 5.0f);
|
trackPoint.setLatitude(45.0f - i / 5.0f);
|
||||||
location.setAccuracy(5);
|
trackPoint.setAccuracy(5);
|
||||||
location.setSpeed(10);
|
trackPoint.setSpeed(10);
|
||||||
location.setTime(startTime + i * 10000);
|
trackPoint.setTime(startTime + i * 10000);
|
||||||
location.setBearing(3.0f);
|
trackPoint.setBearing(3.0f);
|
||||||
service.insertTrackPoint(location);
|
service.insertTrackPoint(trackPoint);
|
||||||
|
|
||||||
if (i % 7 == 0) {
|
if (i % 7 == 0) {
|
||||||
service.insertWaypoint(null, null, null, null);
|
service.insertWaypoint(null, null, null, null);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package de.dennisguse.opentracks.content;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -32,6 +31,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.provider.TrackPointFactory;
|
import de.dennisguse.opentracks.content.provider.TrackPointFactory;
|
||||||
@@ -395,7 +395,7 @@ public class TrackDataHub implements DataSourceListener, SharedPreferences.OnSha
|
|||||||
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, localLastSeenLocationId + 1, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, localLastSeenLocationId + 1, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (locationIterator.hasNext()) {
|
||||||
Location location = locationIterator.next();
|
TrackPoint trackPoint = locationIterator.next();
|
||||||
long locationId = locationIterator.getTrackPointId();
|
long locationId = locationIterator.getTrackPointId();
|
||||||
|
|
||||||
// Stop if past the last wanted point
|
// Stop if past the last wanted point
|
||||||
@@ -412,18 +412,18 @@ public class TrackDataHub implements DataSourceListener, SharedPreferences.OnSha
|
|||||||
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) { //This can be split markers (not anymore supported feature)
|
if (!LocationUtils.isValidLocation(trackPoint)) { //This can be split markers (not anymore supported feature)
|
||||||
includeNextPoint = true;
|
includeNextPoint = true;
|
||||||
} else {
|
} else {
|
||||||
// Also include the last point if the selected track is not recording.
|
// Also include the last point if the selected track is not recording.
|
||||||
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0) || (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0) || (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
||||||
includeNextPoint = false;
|
includeNextPoint = false;
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
for (TrackDataListener trackDataListener : sampledInListeners) {
|
||||||
trackDataListener.onSampledInTrackPoint(location);
|
trackDataListener.onSampledInTrackPoint(trackPoint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (TrackDataListener trackDataListener : sampledOutListeners) {
|
for (TrackDataListener trackDataListener : sampledOutListeners) {
|
||||||
trackDataListener.onSampledOutTrackPoint(location);
|
trackDataListener.onSampledOutTrackPoint(trackPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,20 +42,20 @@ public interface TrackDataListener {
|
|||||||
/**
|
/**
|
||||||
* Called when a sampled in track point is read.
|
* Called when a sampled in track point is read.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
*/
|
*/
|
||||||
void onSampledInTrackPoint(Location location);
|
void onSampledInTrackPoint(TrackPoint trackPoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a sampled out track point is read.
|
* Called when a sampled out track point is read.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
*/
|
*/
|
||||||
void onSampledOutTrackPoint(Location location);
|
void onSampledOutTrackPoint(TrackPoint trackPoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when finish sending new track points.
|
* Called when finish sending new track points.
|
||||||
* This gets called after every batch of calls to {@link #onSampledInTrackPoint(Location)} and {@link #onSampledOutTrackPoint(Location)}.
|
* This gets called after every batch of calls to {@link #onSampledInTrackPoint(TrackPoint)} and {@link #onSampledOutTrackPoint(TrackPoint)}.
|
||||||
*/
|
*/
|
||||||
void onNewTrackPointsDone();
|
void onNewTrackPointsDone();
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.content.data;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -43,7 +41,7 @@ public class Track {
|
|||||||
private TripStatistics tripStatistics = new TripStatistics();
|
private TripStatistics tripStatistics = new TripStatistics();
|
||||||
|
|
||||||
// Location points (which may not have been loaded)
|
// Location points (which may not have been loaded)
|
||||||
private List<Location> locations = new ArrayList<>();
|
private List<TrackPoint> trackPoints = new ArrayList<>();
|
||||||
|
|
||||||
public Track() {
|
public Track() {
|
||||||
}
|
}
|
||||||
@@ -97,15 +95,15 @@ public class Track {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void addLocation(Location location) {
|
public void addTrackPoint(TrackPoint location) {
|
||||||
locations.add(location);
|
trackPoints.add(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Location> getLocations() {
|
public List<TrackPoint> getTrackPoints() {
|
||||||
return locations;
|
return trackPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocations(ArrayList<Location> locations) {
|
public void setTrackPoints(ArrayList<TrackPoint> trackPoints) {
|
||||||
this.locations = locations;
|
this.trackPoints = trackPoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package de.dennisguse.opentracks.content.data;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
|
||||||
@@ -24,8 +25,25 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
|||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
|
//TODO Check if we can drop inheritance from Location and use attributes instead.
|
||||||
public class TrackPoint extends Location {
|
public class TrackPoint extends Location {
|
||||||
|
|
||||||
|
public static TrackPoint createPause() {
|
||||||
|
TrackPoint pause = new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
|
pause.setLongitude(0);
|
||||||
|
pause.setLatitude(TrackPointsColumns.PAUSE_LATITUDE);
|
||||||
|
pause.setTime(System.currentTimeMillis());
|
||||||
|
return pause;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TrackPoint createResume() {
|
||||||
|
TrackPoint resume = new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
|
resume.setLongitude(0);
|
||||||
|
resume.setLatitude(TrackPointsColumns.RESUME_LATITUDE);
|
||||||
|
resume.setTime(System.currentTimeMillis());
|
||||||
|
return resume;
|
||||||
|
}
|
||||||
|
|
||||||
private SensorDataSet sensorDataSet = null;
|
private SensorDataSet sensorDataSet = null;
|
||||||
|
|
||||||
public TrackPoint(Location location, SensorDataSet sensorDataSet) {
|
public TrackPoint(Location location, SensorDataSet sensorDataSet) {
|
||||||
|
|||||||
+93
-100
@@ -622,34 +622,62 @@ public class ContentProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts multiple track points.
|
* Fills a {@link TrackPoint} from a cursor.
|
||||||
*
|
*
|
||||||
* @param locations an array of locations
|
* @param cursor the cursor pointing to a trackPoint.
|
||||||
* @param length the number of locations (from the beginning of the array) to
|
* @param indexes the cached track points indexes
|
||||||
* insert, or -1 for all of them
|
* @param trackPoint the track point
|
||||||
* @param trackId the track id
|
|
||||||
* @return the number of points inserted
|
|
||||||
*/
|
*/
|
||||||
public int bulkInsertTrackPoint(Location[] locations, int length, long trackId) {
|
static void fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes, TrackPoint trackPoint) {
|
||||||
if (length == -1) {
|
trackPoint.reset();
|
||||||
length = locations.length;
|
|
||||||
|
if (!cursor.isNull(indexes.longitudeIndex)) {
|
||||||
|
trackPoint.setLongitude(((double) cursor.getInt(indexes.longitudeIndex)) / 1E6);
|
||||||
}
|
}
|
||||||
ContentValues[] values = new ContentValues[length];
|
if (!cursor.isNull(indexes.latitudeIndex)) {
|
||||||
for (int i = 0; i < length; i++) {
|
trackPoint.setLatitude(((double) cursor.getInt(indexes.latitudeIndex)) / 1E6);
|
||||||
values[i] = createContentValues(locations[i], trackId);
|
|
||||||
}
|
}
|
||||||
return contentResolver.bulkInsert(TrackPointsColumns.CONTENT_URI_BY_ID, values);
|
if (!cursor.isNull(indexes.timeIndex)) {
|
||||||
|
trackPoint.setTime(cursor.getLong(indexes.timeIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(indexes.altitudeIndex)) {
|
||||||
|
trackPoint.setAltitude(cursor.getFloat(indexes.altitudeIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(indexes.accuracyIndex)) {
|
||||||
|
trackPoint.setAccuracy(cursor.getFloat(indexes.accuracyIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(indexes.speedIndex)) {
|
||||||
|
trackPoint.setSpeed(cursor.getFloat(indexes.speedIndex));
|
||||||
|
}
|
||||||
|
if (!cursor.isNull(indexes.bearingIndex)) {
|
||||||
|
trackPoint.setBearing(cursor.getFloat(indexes.bearingIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
float heartRate = cursor.isNull(indexes.sensorHeartRateIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorHeartRateIndex);
|
||||||
|
float cadence = cursor.isNull(indexes.sensorCadenceIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorCadenceIndex);
|
||||||
|
float power = cursor.isNull(indexes.sensorPowerIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorPowerIndex);
|
||||||
|
|
||||||
|
trackPoint.setSensorDataSet(new SensorDataSet(heartRate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, trackPoint.getTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a location object from a cursor.
|
* Inserts multiple trackPoints points.
|
||||||
*
|
*
|
||||||
* @param cursor the cursor pointing to the location
|
* @param trackPoints an array of trackPoints
|
||||||
|
* @param length the number of trackPoints (from the beginning of the array) to
|
||||||
|
* insert, or -1 for all of them
|
||||||
|
* @param trackId the trackPoints id
|
||||||
|
* @return the number of points inserted
|
||||||
*/
|
*/
|
||||||
public Location createTrackPoint(Cursor cursor) {
|
public int bulkInsertTrackPoint(TrackPoint[] trackPoints, int length, long trackId) {
|
||||||
Location location = new TrackPoint("");
|
if (length == -1) {
|
||||||
fillTrackPoint(cursor, new CachedTrackPointsIndexes(cursor), location);
|
length = trackPoints.length;
|
||||||
return location;
|
}
|
||||||
|
ContentValues[] values = new ContentValues[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
values[i] = createContentValues(trackPoints[i], trackId);
|
||||||
|
}
|
||||||
|
return contentResolver.bulkInsert(TrackPointsColumns.CONTENT_URI_BY_ID, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -722,21 +750,14 @@ public class ContentProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last valid location for a track.
|
* Creates a location object from a cursor.
|
||||||
* Returns null if it doesn't exist.
|
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param cursor the cursor pointing to the location
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public TrackPoint createTrackPoint(Cursor cursor) {
|
||||||
public Location getLastValidTrackPoint(long trackId) {
|
TrackPoint location = new TrackPoint("");
|
||||||
if (trackId < 0) {
|
fillTrackPoint(cursor, new CachedTrackPointsIndexes(cursor), location);
|
||||||
return null;
|
return location;
|
||||||
}
|
|
||||||
String selection = TrackPointsColumns._ID + "=(select max(" + 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -774,99 +795,71 @@ public class ContentProviderUtils {
|
|||||||
return getTrackPointCursor(null, selection, selectionArgs, sortOrder);
|
return getTrackPointCursor(null, selection, selectionArgs, sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills a track point from a cursor.
|
* Gets the last valid location for a track.
|
||||||
|
* Returns null if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @param cursor the cursor pointing to a location.
|
* @param trackId the track id
|
||||||
* @param indexes the cached track points indexes
|
|
||||||
* @param location the track point
|
|
||||||
*/
|
*/
|
||||||
static void fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes, Location location) {
|
@Deprecated
|
||||||
location.reset();
|
public TrackPoint getLastValidTrackPoint(long trackId) {
|
||||||
|
if (trackId < 0) {
|
||||||
if (!cursor.isNull(indexes.longitudeIndex)) {
|
return null;
|
||||||
location.setLongitude(((double) cursor.getInt(indexes.longitudeIndex)) / 1E6);
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.latitudeIndex)) {
|
|
||||||
location.setLatitude(((double) cursor.getInt(indexes.latitudeIndex)) / 1E6);
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.timeIndex)) {
|
|
||||||
location.setTime(cursor.getLong(indexes.timeIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.altitudeIndex)) {
|
|
||||||
location.setAltitude(cursor.getFloat(indexes.altitudeIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.accuracyIndex)) {
|
|
||||||
location.setAccuracy(cursor.getFloat(indexes.accuracyIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.speedIndex)) {
|
|
||||||
location.setSpeed(cursor.getFloat(indexes.speedIndex));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(indexes.bearingIndex)) {
|
|
||||||
location.setBearing(cursor.getFloat(indexes.bearingIndex));
|
|
||||||
}
|
|
||||||
if (location instanceof TrackPoint) {
|
|
||||||
TrackPoint sensorDataSetLocation = (TrackPoint) location;
|
|
||||||
|
|
||||||
float heartRate = cursor.isNull(indexes.sensorHeartRateIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorHeartRateIndex);
|
|
||||||
float cadence = cursor.isNull(indexes.sensorCadenceIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorCadenceIndex);
|
|
||||||
float power = cursor.isNull(indexes.sensorPowerIndex) ? SensorDataSet.DATA_UNAVAILABLE : cursor.getFloat(indexes.sensorPowerIndex);
|
|
||||||
|
|
||||||
sensorDataSetLocation.setSensorDataSet(new SensorDataSet(heartRate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime()));
|
|
||||||
}
|
}
|
||||||
|
String selection = TrackPointsColumns._ID + "=(select max(" + 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a track point.
|
* Inserts a track point.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
* @return the content provider URI of the inserted track point
|
* @return the content provider URI of the inserted track point
|
||||||
*/
|
*/
|
||||||
public Uri insertTrackPoint(Location location, long trackId) {
|
public Uri insertTrackPoint(TrackPoint trackPoint, long trackId) {
|
||||||
return contentResolver.insert(TrackPointsColumns.CONTENT_URI_BY_ID, createContentValues(location, trackId));
|
return contentResolver.insert(TrackPointsColumns.CONTENT_URI_BY_ID, createContentValues(trackPoint, trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the {@link ContentValues} for a {@link Location}.
|
* Creates the {@link ContentValues} for a {@link TrackPoint}.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
private ContentValues createContentValues(Location location, long trackId) {
|
private ContentValues createContentValues(TrackPoint trackPoint, long trackId) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(TrackPointsColumns.TRACKID, trackId);
|
values.put(TrackPointsColumns.TRACKID, trackId);
|
||||||
values.put(TrackPointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6));
|
values.put(TrackPointsColumns.LONGITUDE, (int) (trackPoint.getLongitude() * 1E6));
|
||||||
values.put(TrackPointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6));
|
values.put(TrackPointsColumns.LATITUDE, (int) (trackPoint.getLatitude() * 1E6));
|
||||||
|
|
||||||
values.put(TrackPointsColumns.TIME, location.getTime());
|
values.put(TrackPointsColumns.TIME, trackPoint.getTime());
|
||||||
if (location.hasAltitude()) {
|
if (trackPoint.hasAltitude()) {
|
||||||
values.put(TrackPointsColumns.ALTITUDE, location.getAltitude());
|
values.put(TrackPointsColumns.ALTITUDE, trackPoint.getAltitude());
|
||||||
}
|
}
|
||||||
if (location.hasAccuracy()) {
|
if (trackPoint.hasAccuracy()) {
|
||||||
values.put(TrackPointsColumns.ACCURACY, location.getAccuracy());
|
values.put(TrackPointsColumns.ACCURACY, trackPoint.getAccuracy());
|
||||||
}
|
}
|
||||||
if (location.hasSpeed()) {
|
if (trackPoint.hasSpeed()) {
|
||||||
values.put(TrackPointsColumns.SPEED, location.getSpeed());
|
values.put(TrackPointsColumns.SPEED, trackPoint.getSpeed());
|
||||||
}
|
}
|
||||||
if (location.hasBearing()) {
|
if (trackPoint.hasBearing()) {
|
||||||
values.put(TrackPointsColumns.BEARING, location.getBearing());
|
values.put(TrackPointsColumns.BEARING, trackPoint.getBearing());
|
||||||
}
|
}
|
||||||
|
|
||||||
//SensorData
|
//SensorData
|
||||||
if (location instanceof TrackPoint) {
|
SensorDataSet sensorDataSet = trackPoint.getSensorDataSet();
|
||||||
TrackPoint sensorDataSetLocation = (TrackPoint) location;
|
if (sensorDataSet != null && sensorDataSet.hasHeartRate()) {
|
||||||
SensorDataSet sensorDataSet = sensorDataSetLocation.getSensorDataSet();
|
values.put(TrackPointsColumns.SENSOR_HEARTRATE, trackPoint.getSensorDataSet().getHeartRate());
|
||||||
if (sensorDataSet != null && sensorDataSet.hasHeartRate()) {
|
}
|
||||||
values.put(TrackPointsColumns.SENSOR_HEARTRATE, sensorDataSetLocation.getSensorDataSet().getHeartRate());
|
if (sensorDataSet != null && sensorDataSet.hasCadence()) {
|
||||||
}
|
values.put(TrackPointsColumns.SENSOR_CADENCE, trackPoint.getSensorDataSet().getCadence());
|
||||||
if (sensorDataSet != null && sensorDataSet.hasCadence()) {
|
}
|
||||||
values.put(TrackPointsColumns.SENSOR_CADENCE, sensorDataSetLocation.getSensorDataSet().getCadence());
|
if (sensorDataSet != null && sensorDataSet.hasPower()) {
|
||||||
}
|
values.put(TrackPointsColumns.SENSOR_POWER, trackPoint.getSensorDataSet().getPower());
|
||||||
if (sensorDataSet != null && sensorDataSet.hasPower()) {
|
|
||||||
values.put(TrackPointsColumns.SENSOR_POWER, sensorDataSetLocation.getSensorDataSet().getPower());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
@@ -875,7 +868,7 @@ public class ContentProviderUtils {
|
|||||||
* Creates a new read-only iterator over a given track's points.
|
* Creates a new read-only iterator over a given track's points.
|
||||||
* It provides a lightweight way of iterating over long tracks without failing due to the underlying cursor limitations.
|
* It provides a lightweight way of iterating over long tracks without failing due to the underlying cursor limitations.
|
||||||
* Since it's a read-only iterator, {@link Iterator#remove()} always throws {@link UnsupportedOperationException}.
|
* Since it's a read-only iterator, {@link Iterator#remove()} always throws {@link UnsupportedOperationException}.
|
||||||
* Each call to {@link TrackPointIterator#next()} may advance to the next DB record, and if so, the iterator calls {@link TrackPointFactory#createLocation()} and populates it with information retrieved from the record.
|
* Each call to {@link TrackPointIterator#next()} may advance to the next DB record, and if so, the iterator calls {@link TrackPointFactory#create()} and populates it with information retrieved from the record.
|
||||||
* When done with iteration, {@link TrackPointIterator#close()} must be called.
|
* When done with iteration, {@link TrackPointIterator#close()} must be called.
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
@@ -887,7 +880,7 @@ public class ContentProviderUtils {
|
|||||||
return new TrackPointIterator(this, trackId, startTrackPointId, descending, trackPointFactory);
|
return new TrackPointIterator(this, trackId, startTrackPointId, descending, trackPointFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location findTrackPointBy(String selection, String[] selectionArgs) {
|
private TrackPoint findTrackPointBy(String selection, String[] selectionArgs) {
|
||||||
try (Cursor cursor = getTrackPointCursor(null, selection, selectionArgs, TrackPointsColumns._ID)) {
|
try (Cursor cursor = getTrackPointCursor(null, selection, selectionArgs, TrackPointsColumns._ID)) {
|
||||||
if (cursor != null && cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
return createTrackPoint(cursor);
|
return createTrackPoint(cursor);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class TrackPointFactory {
|
|||||||
*/
|
*/
|
||||||
public static final TrackPointFactory DEFAULT_LOCATION_FACTORY = new TrackPointFactory();
|
public static final TrackPointFactory DEFAULT_LOCATION_FACTORY = new TrackPointFactory();
|
||||||
|
|
||||||
public TrackPoint createLocation() {
|
public TrackPoint create() {
|
||||||
return new TrackPoint(LocationManager.GPS_PROVIDER);
|
return new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class TrackPointIterator implements Iterator<TrackPoint>, AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastTrackPointId = cursor.getLong(indexes.idIndex);
|
lastTrackPointId = cursor.getLong(indexes.idIndex);
|
||||||
TrackPoint trackPoint = trackPointFactory.createLocation();
|
TrackPoint trackPoint = trackPointFactory.create();
|
||||||
ContentProviderUtils.fillTrackPoint(cursor, indexes, trackPoint);
|
ContentProviderUtils.fillTrackPoint(cursor, indexes, trackPoint);
|
||||||
return trackPoint;
|
return trackPoint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package de.dennisguse.opentracks.fragments;
|
package de.dennisguse.opentracks.fragments;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -220,18 +219,18 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledInTrackPoint(Location location) {
|
public void onSampledInTrackPoint(TrackPoint trackPoint) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
double[] data = new double[ChartView.NUM_SERIES + 1];
|
double[] data = new double[ChartView.NUM_SERIES + 1];
|
||||||
fillDataPoint(location, data);
|
fillDataPoint(trackPoint, data);
|
||||||
pendingPoints.add(data);
|
pendingPoints.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledOutTrackPoint(Location location) {
|
public void onSampledOutTrackPoint(TrackPoint trackPoint) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
fillDataPoint(location, null);
|
fillDataPoint(trackPoint, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +350,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a location, fill in a data point, an array of double[]. <br>
|
* Given a trackPoint, fill in a data point, an array of double[]. <br>
|
||||||
* data[0] = time/distance <br>
|
* data[0] = time/distance <br>
|
||||||
* data[1] = elevation <br>
|
* data[1] = elevation <br>
|
||||||
* data[2] = speed <br>
|
* data[2] = speed <br>
|
||||||
@@ -360,18 +359,18 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
* data[5] = cadence <br>
|
* data[5] = cadence <br>
|
||||||
* data[6] = power <br>
|
* data[6] = power <br>
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param data the data point to fill in, can be null
|
* @param data the data point to fill in, can be null
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void fillDataPoint(Location location, double[] data) {
|
void fillDataPoint(@NonNull TrackPoint trackPoint, double[] data) {
|
||||||
double timeOrDistance = Double.NaN;
|
double timeOrDistance = Double.NaN;
|
||||||
double elevation = Double.NaN;
|
double elevation = Double.NaN;
|
||||||
double speed = Double.NaN;
|
double speed = Double.NaN;
|
||||||
double pace = Double.NaN;
|
double pace = Double.NaN;
|
||||||
|
|
||||||
if (tripStatisticsUpdater != null) {
|
if (tripStatisticsUpdater != null) {
|
||||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
tripStatisticsUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
|
||||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
if (chartByDistance) {
|
if (chartByDistance) {
|
||||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||||
@@ -398,8 +397,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
double heartRate = Double.NaN;
|
double heartRate = Double.NaN;
|
||||||
double cadence = Double.NaN;
|
double cadence = Double.NaN;
|
||||||
double power = Double.NaN;
|
double power = Double.NaN;
|
||||||
if (location instanceof TrackPoint && ((TrackPoint) location).getSensorDataSet() != null) {
|
if (trackPoint.getSensorDataSet() != null) {
|
||||||
SensorDataSet sensorDataSet = ((TrackPoint) location).getSensorDataSet();
|
SensorDataSet sensorDataSet = trackPoint.getSensorDataSet();
|
||||||
if (sensorDataSet.hasHeartRate()) {
|
if (sensorDataSet.hasHeartRate()) {
|
||||||
heartRate = sensorDataSet.getHeartRate();
|
heartRate = sensorDataSet.getHeartRate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package de.dennisguse.opentracks.fragments;
|
package de.dennisguse.opentracks.fragments;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -42,6 +41,7 @@ import de.dennisguse.opentracks.content.TrackDataHub;
|
|||||||
import de.dennisguse.opentracks.content.TrackDataListener;
|
import de.dennisguse.opentracks.content.TrackDataListener;
|
||||||
import de.dennisguse.opentracks.content.TrackDataType;
|
import de.dennisguse.opentracks.content.TrackDataType;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
@@ -72,7 +72,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
//TODO Initialize immediately and remove in onDestroy()
|
//TODO Initialize immediately and remove in onDestroy()
|
||||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||||
|
|
||||||
private Location lastLocation = null;
|
private TrackPoint lastTrackPoint = null;
|
||||||
private TripStatistics lastTripStatistics = null;
|
private TripStatistics lastTripStatistics = null;
|
||||||
|
|
||||||
private String category = "";
|
private String category = "";
|
||||||
@@ -333,17 +333,17 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrackPoints() {
|
public void clearTrackPoints() {
|
||||||
lastLocation = null;
|
lastTrackPoint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledInTrackPoint(Location location) {
|
public void onSampledInTrackPoint(TrackPoint trackPoint) {
|
||||||
lastLocation = location;
|
lastTrackPoint = trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledOutTrackPoint(Location location) {
|
public void onSampledOutTrackPoint(TrackPoint trackPoint) {
|
||||||
lastLocation = location;
|
lastTrackPoint = trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -354,15 +354,15 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
if (!isSelectedTrackRecording() || isSelectedTrackPaused()) {
|
if (!isSelectedTrackRecording() || isSelectedTrackPaused()) {
|
||||||
lastLocation = null;
|
lastTrackPoint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastLocation != null) {
|
if (lastTrackPoint != null) {
|
||||||
boolean hasFix = !LocationUtils.isLocationOld(lastLocation);
|
boolean hasFix = !LocationUtils.isLocationOld(lastTrackPoint);
|
||||||
boolean hasGoodFix = lastLocation.hasAccuracy() && lastLocation.getAccuracy() < recordingGpsAccuracy;
|
boolean hasGoodFix = lastTrackPoint.hasAccuracy() && lastTrackPoint.getAccuracy() < recordingGpsAccuracy;
|
||||||
|
|
||||||
if (!hasFix || !hasGoodFix) {
|
if (!hasFix || !hasGoodFix) {
|
||||||
lastLocation = null;
|
lastTrackPoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setLocationValues();
|
setLocationValues();
|
||||||
@@ -573,7 +573,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
if (isRecording) {
|
if (isRecording) {
|
||||||
speedLabel.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
speedLabel.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
||||||
|
|
||||||
double speed = lastLocation != null && lastLocation.hasSpeed() ? lastLocation.getSpeed() : Double.NaN;
|
double speed = lastTrackPoint != null && lastTrackPoint.hasSpeed() ? lastTrackPoint.getSpeed() : Double.NaN;
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedValue.setText(parts.first);
|
speedValue.setText(parts.first);
|
||||||
speedUnit.setText(parts.second);
|
speedUnit.setText(parts.second);
|
||||||
@@ -584,7 +584,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
gradeElevationContainer.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE);
|
gradeElevationContainer.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
if (showGradeElevation) {
|
if (showGradeElevation) {
|
||||||
double altitude = lastLocation != null && lastLocation.hasAltitude() ? lastLocation.getAltitude() : Double.NaN;
|
double altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? lastTrackPoint.getAltitude() : Double.NaN;
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
||||||
|
|
||||||
elevationValue.setText(parts.first);
|
elevationValue.setText(parts.first);
|
||||||
@@ -597,11 +597,11 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
coordinateSeparator.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
coordinateSeparator.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
||||||
coordinateContainer.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
coordinateContainer.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
||||||
if (showCoordinate) {
|
if (showCoordinate) {
|
||||||
double latitude = lastLocation != null ? lastLocation.getLatitude() : Double.NaN;
|
double latitude = lastTrackPoint != null ? lastTrackPoint.getLatitude() : Double.NaN;
|
||||||
String latitudeText = Double.isNaN(latitude) || Double.isInfinite(latitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(latitude);
|
String latitudeText = Double.isNaN(latitude) || Double.isInfinite(latitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(latitude);
|
||||||
latitudeValue.setText(latitudeText);
|
latitudeValue.setText(latitudeText);
|
||||||
|
|
||||||
double longitude = lastLocation != null ? lastLocation.getLongitude() : Double.NaN;
|
double longitude = lastTrackPoint != null ? lastTrackPoint.getLongitude() : Double.NaN;
|
||||||
String longitudeText = Double.isNaN(longitude) || Double.isInfinite(longitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(longitude);
|
String longitudeText = Double.isNaN(longitude) || Double.isInfinite(longitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(longitude);
|
||||||
longitudeValue.setText(longitudeText);
|
longitudeValue.setText(longitudeText);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package de.dennisguse.opentracks.io.file.exporter;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -129,22 +128,22 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
TrackWriterTrackPointFactory trackPointFactory = new TrackWriterTrackPointFactory();
|
TrackWriterTrackPointFactory trackPointFactory = new TrackWriterTrackPointFactory();
|
||||||
int locationNumber = 0;
|
int locationNumber = 0;
|
||||||
|
|
||||||
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, trackPointFactory)) {
|
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, trackPointFactory)) {
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (trackPointIterator.hasNext()) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
throw new InterruptedException();
|
throw new InterruptedException();
|
||||||
}
|
}
|
||||||
Location location = locationIterator.next();
|
TrackPoint trackPoint = trackPointIterator.next();
|
||||||
|
|
||||||
setLocationTime(location, offset);
|
setLocationTime(trackPoint, offset);
|
||||||
locationNumber++;
|
locationNumber++;
|
||||||
|
|
||||||
boolean isLocationValid = LocationUtils.isValidLocation(location);
|
boolean isLocationValid = LocationUtils.isValidLocation(trackPoint);
|
||||||
boolean isSegmentValid = isLocationValid && isLastLocationValid;
|
boolean isSegmentValid = isLocationValid && isLastLocationValid;
|
||||||
if (!wroteTrack && isSegmentValid) {
|
if (!wroteTrack && isSegmentValid) {
|
||||||
// Found the first two consecutive locations that are valid
|
// Found the first two consecutive locations that are valid
|
||||||
trackWriter.writeBeginTrack(track, trackPointFactory.lastLocation);
|
trackWriter.writeBeginTrack(track, trackPointFactory.lastTrackPoint);
|
||||||
wroteTrack = true;
|
wroteTrack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,14 +153,14 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
trackWriter.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
wroteSegment = true;
|
wroteSegment = true;
|
||||||
|
|
||||||
// Write the previous location, which we had previously skipped
|
// Write the previous trackPoint, which we had previously skipped
|
||||||
trackWriter.writeLocation(trackPointFactory.lastLocation);
|
trackWriter.writeTrackPoint(trackPointFactory.lastTrackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the current location
|
// Write the current trackPoint
|
||||||
trackWriter.writeLocation(location);
|
trackWriter.writeTrackPoint(trackPoint);
|
||||||
if (trackExporterListener != null) {
|
if (trackExporterListener != null) {
|
||||||
trackExporterListener.onProgressUpdate(locationNumber, locationIterator.getCount());
|
trackExporterListener.onProgressUpdate(locationNumber, trackPointIterator.getCount());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wroteSegment) {
|
if (wroteSegment) {
|
||||||
@@ -179,7 +178,7 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wroteTrack) {
|
if (wroteTrack) {
|
||||||
Location lastValidTrackPoint = contentProviderUtils.getLastValidTrackPoint(track.getId());
|
TrackPoint lastValidTrackPoint = contentProviderUtils.getLastValidTrackPoint(track.getId());
|
||||||
setLocationTime(lastValidTrackPoint, offset);
|
setLocationTime(lastValidTrackPoint, offset);
|
||||||
trackWriter.writeEndTrack(track, lastValidTrackPoint);
|
trackWriter.writeEndTrack(track, lastValidTrackPoint);
|
||||||
} else {
|
} else {
|
||||||
@@ -191,40 +190,40 @@ public class FileTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a location time.
|
* Sets a trackPoint time.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param offset the time offset
|
* @param offset the time offset
|
||||||
*/
|
*/
|
||||||
private void setLocationTime(Location location, long offset) {
|
private void setLocationTime(TrackPoint trackPoint, long offset) {
|
||||||
if (location != null) {
|
if (trackPoint != null) {
|
||||||
location.setTime(location.getTime() - offset);
|
trackPoint.setTime(trackPoint.getTime() - offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track writer location factory. Keeping the last two locations.
|
* Keeping the last two locations.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
private class TrackWriterTrackPointFactory extends TrackPointFactory {
|
private class TrackWriterTrackPointFactory extends TrackPointFactory {
|
||||||
TrackPoint currentLocation;
|
TrackPoint currentTrackPoint;
|
||||||
TrackPoint lastLocation;
|
TrackPoint lastTrackPoint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrackPoint createLocation() {
|
public TrackPoint create() {
|
||||||
if (currentLocation == null) {
|
if (currentTrackPoint == null) {
|
||||||
currentLocation = new TrackPoint("");
|
currentTrackPoint = new TrackPoint("");
|
||||||
}
|
}
|
||||||
return currentLocation;
|
return currentTrackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swapLocations() {
|
void swapLocations() {
|
||||||
TrackPoint tempLocation = lastLocation;
|
TrackPoint tempTrackPoint = lastTrackPoint;
|
||||||
lastLocation = currentLocation;
|
lastTrackPoint = currentTrackPoint;
|
||||||
currentLocation = tempLocation;
|
currentTrackPoint = tempTrackPoint;
|
||||||
if (currentLocation != null) {
|
if (currentTrackPoint != null) {
|
||||||
currentLocation.reset();
|
currentTrackPoint.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.text.NumberFormat;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ public class GpxTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeBeginTrack(Track track, Location startLocation) {
|
public void writeBeginTrack(Track track, TrackPoint startTrackPoint) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println("<trk>");
|
printWriter.println("<trk>");
|
||||||
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
||||||
@@ -150,7 +151,7 @@ public class GpxTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeEndTrack(Track track, Location endLocation) {
|
public void writeEndTrack(Track track, TrackPoint endTrackPoint) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println("</trk>");
|
printWriter.println("</trk>");
|
||||||
}
|
}
|
||||||
@@ -167,14 +168,14 @@ public class GpxTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLocation(Location location) {
|
public void writeTrackPoint(TrackPoint trackPoint) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println("<trkpt " + formatLocation(location) + ">");
|
printWriter.println("<trkpt " + formatLocation(trackPoint) + ">");
|
||||||
if (location.hasAltitude()) {
|
if (trackPoint.hasAltitude()) {
|
||||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
printWriter.println("<ele>" + ELEVATION_FORMAT.format(trackPoint.getAltitude()) + "</ele>");
|
||||||
}
|
}
|
||||||
printWriter.println(
|
printWriter.println(
|
||||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
"<time>" + StringUtils.formatDateTimeIso8601(trackPoint.getTime()) + "</time>");
|
||||||
printWriter.println("</trkpt>");
|
printWriter.println("</trkpt>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
private final List<Float> cadenceList = new ArrayList<>();
|
private final List<Float> cadenceList = new ArrayList<>();
|
||||||
private final List<Float> heartRateList = new ArrayList<>();
|
private final List<Float> heartRateList = new ArrayList<>();
|
||||||
|
|
||||||
private Location startLocation;
|
private TrackPoint startTrackPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context the context
|
* @param context the context
|
||||||
@@ -188,11 +188,11 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeBeginTrack(Track track, Location startLocation) {
|
public void writeBeginTrack(Track track, TrackPoint startTrackPoint) {
|
||||||
this.startLocation = startLocation;
|
this.startTrackPoint = startTrackPoint;
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
String name = context.getString(R.string.marker_label_start, track.getName());
|
String name = context.getString(R.string.marker_label_start, track.getName());
|
||||||
writePlacemark(name, "", "", START_STYLE, startLocation);
|
writePlacemark(name, "", "", START_STYLE, startTrackPoint);
|
||||||
printWriter.println("<Placemark>");
|
printWriter.println("<Placemark>");
|
||||||
|
|
||||||
if (exportTrackDetail) {
|
if (exportTrackDetail) {
|
||||||
@@ -210,7 +210,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeEndTrack(Track track, Location endLocation) {
|
public void writeEndTrack(Track track, TrackPoint endTrackPoint) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println("</gx:MultiTrack>");
|
printWriter.println("</gx:MultiTrack>");
|
||||||
printWriter.println("</Placemark>");
|
printWriter.println("</Placemark>");
|
||||||
@@ -218,7 +218,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
if (exportTrackDetail) {
|
if (exportTrackDetail) {
|
||||||
String name = context.getString(R.string.marker_label_end, track.getName());
|
String name = context.getString(R.string.marker_label_end, track.getName());
|
||||||
String description = descriptionGenerator.generateTrackDescription(track, false);
|
String description = descriptionGenerator.generateTrackDescription(track, false);
|
||||||
writePlacemark(name, "", description, END_STYLE, endLocation);
|
writePlacemark(name, "", description, END_STYLE, endTrackPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,16 +256,16 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLocation(Location location) {
|
public void writeTrackPoint(TrackPoint trackPoint) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
if (exportTrackDetail) {
|
if (exportTrackDetail) {
|
||||||
printWriter.println("<when>" + getTime(location) + "</when>");
|
printWriter.println("<when>" + getTime(trackPoint) + "</when>");
|
||||||
}
|
}
|
||||||
|
|
||||||
printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
|
printWriter.println("<gx:coord>" + getCoordinates(trackPoint, " ") + "</gx:coord>");
|
||||||
|
|
||||||
if (exportSensorData && location instanceof TrackPoint) {
|
if (exportSensorData) {
|
||||||
SensorDataSet sensorDataSet = ((TrackPoint) location).getSensorDataSet();
|
SensorDataSet sensorDataSet = trackPoint.getSensorDataSet();
|
||||||
if (sensorDataSet != null) {
|
if (sensorDataSet != null) {
|
||||||
if (sensorDataSet.hasHeartRate()) {
|
if (sensorDataSet.hasHeartRate()) {
|
||||||
heartRateList.add(sensorDataSet.getHeartRate());
|
heartRateList.add(sensorDataSet.getHeartRate());
|
||||||
@@ -371,7 +371,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
if (exportTrackDetail) {
|
if (exportTrackDetail) {
|
||||||
return StringUtils.formatDateTimeIso8601(location.getTime());
|
return StringUtils.formatDateTimeIso8601(location.getTime());
|
||||||
} else {
|
} else {
|
||||||
return StringUtils.formatDateTimeIso8601(location.getTime() - startLocation.getTime());
|
return StringUtils.formatDateTimeIso8601(location.getTime() - startTrackPoint.getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public interface TrackExporterListener {
|
|||||||
/**
|
/**
|
||||||
* Called to update progress.
|
* Called to update progress.
|
||||||
*
|
*
|
||||||
* @param number the number of locations written
|
* @param number the number of {@link de.dennisguse.opentracks.content.data.TrackPoint}s written
|
||||||
* @param max the maximum number of locations in a track, for calculation of
|
* @param max the maximum number of {@link de.dennisguse.opentracks.content.data.TrackPoint}s in a {@link de.dennisguse.opentracks.content.data.Track}, for calculation of
|
||||||
* completion percentage
|
* completion percentage
|
||||||
*/
|
*/
|
||||||
void onProgressUpdate(int number, int max);
|
void onProgressUpdate(int number, int max);
|
||||||
|
|||||||
@@ -15,11 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.io.file.exporter;
|
package de.dennisguse.opentracks.io.file.exporter;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
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.data.Waypoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,13 +34,13 @@ import de.dennisguse.opentracks.content.data.Waypoint;
|
|||||||
* {@link #writeEndWaypoints()}
|
* {@link #writeEndWaypoints()}
|
||||||
* {@link #writeBeginTracks()}
|
* {@link #writeBeginTracks()}
|
||||||
* For each track:
|
* For each track:
|
||||||
* {@link #writeBeginTrack(Track, Location)}
|
* {@link #writeBeginTrack(Track, TrackPoint)}
|
||||||
* For each segment:
|
* For each segment:
|
||||||
* {@link #writeOpenSegment()}
|
* {@link #writeOpenSegment()}
|
||||||
* For each location in the segment:
|
* For each trackPoint in the segment:
|
||||||
* {@link #writeLocation(Location)}
|
* {@link #writeTrackPoint(TrackPoint)}
|
||||||
* {@link #writeCloseSegment()}
|
* {@link #writeCloseSegment()}
|
||||||
* {@link #writeEndTrack(Track, Location)}
|
* {@link #writeEndTrack(Track, TrackPoint)}
|
||||||
* {@link #writeEndTracks()}
|
* {@link #writeEndTracks()}
|
||||||
* {@link #writeFooter()}
|
* {@link #writeFooter()}
|
||||||
* {@link #close()}
|
* {@link #close()}
|
||||||
@@ -107,18 +106,18 @@ public interface TrackWriter {
|
|||||||
/**
|
/**
|
||||||
* Writes the beginning of a track.
|
* Writes the beginning of a track.
|
||||||
*
|
*
|
||||||
* @param track the track
|
* @param track the track
|
||||||
* @param startLocation the start location
|
* @param startTrackPoint the start location
|
||||||
*/
|
*/
|
||||||
void writeBeginTrack(Track track, Location startLocation);
|
void writeBeginTrack(Track track, TrackPoint startTrackPoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the end of a track.
|
* Writes the end of a track.
|
||||||
*
|
*
|
||||||
* @param track the track
|
* @param track the track
|
||||||
* @param endLocation the end location
|
* @param endTrackPoint the end location
|
||||||
*/
|
*/
|
||||||
void writeEndTrack(Track track, Location endLocation);
|
void writeEndTrack(Track track, TrackPoint endTrackPoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes open segment.
|
* Writes open segment.
|
||||||
@@ -131,9 +130,9 @@ public interface TrackWriter {
|
|||||||
void writeCloseSegment();
|
void writeCloseSegment();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a location.
|
* Writes a trackPoint.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
*/
|
*/
|
||||||
void writeLocation(Location location);
|
void writeTrackPoint(TrackPoint trackPoint);
|
||||||
}
|
}
|
||||||
+39
-38
@@ -39,6 +39,7 @@ import javax.xml.parsers.SAXParserFactory;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
@@ -158,12 +159,12 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
|
|
||||||
int waypointPosition = -1;
|
int waypointPosition = -1;
|
||||||
Waypoint waypoint = null;
|
Waypoint waypoint = null;
|
||||||
Location location = null;
|
TrackPoint trackPoint = null;
|
||||||
TripStatisticsUpdater trackTripStatisticstrackUpdater = new TripStatisticsUpdater(track.getTripStatistics().getStartTime());
|
TripStatisticsUpdater trackTripStatisticstrackUpdater = new TripStatisticsUpdater(track.getTripStatistics().getStartTime());
|
||||||
@Deprecated // TODO Should not be necessary anymore?
|
@Deprecated // TODO Should not be necessary anymore?
|
||||||
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(track.getTripStatistics().getStartTime());
|
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(track.getTripStatistics().getStartTime());
|
||||||
|
|
||||||
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
@@ -175,38 +176,38 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == null) {
|
if (trackPoint == null) {
|
||||||
if (!locationIterator.hasNext()) {
|
if (!trackPointIterator.hasNext()) {
|
||||||
// No more track points. Ignore the rest of the waypoints.
|
// No more track points. Ignore the rest of the waypoints.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
location = locationIterator.next();
|
trackPoint = trackPointIterator.next();
|
||||||
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval);
|
trackTripStatisticstrackUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
|
||||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
markerTripStatisticsUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waypoint.getLocation().getTime() > location.getTime()) {
|
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
|
||||||
location = null;
|
trackPoint = null;
|
||||||
} else if (waypoint.getLocation().getTime() < location.getTime()) {
|
} else if (waypoint.getLocation().getTime() < trackPoint.getTime()) {
|
||||||
Log.w(TAG, "Ignoring waypoint: current location was after waypoint.");
|
Log.w(TAG, "Ignoring waypoint: current trackPoint was after waypoint.");
|
||||||
waypoint = null;
|
waypoint = null;
|
||||||
} else {
|
} else {
|
||||||
// The waypoint location time matches the track point time
|
// The waypoint trackPoint time matches the track point time
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(trackPoint)) {
|
||||||
// Invalid location, load the next location
|
// Invalid trackPoint, load the next trackPoint
|
||||||
location = null;
|
trackPoint = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid location
|
// Valid trackPoint
|
||||||
if (location.getLatitude() == waypoint.getLocation().getLatitude() && location.getLongitude() == waypoint.getLocation().getLongitude()) {
|
if (trackPoint.getLatitude() == waypoint.getLocation().getLatitude() && trackPoint.getLongitude() == waypoint.getLocation().getLongitude()) {
|
||||||
String waypointDescription = waypoint.getDescription();
|
String waypointDescription = waypoint.getDescription();
|
||||||
String icon = context.getString(R.string.marker_waypoint_icon_url);
|
String icon = context.getString(R.string.marker_waypoint_icon_url);
|
||||||
double length = trackTripStatisticstrackUpdater.getTripStatistics().getTotalDistance();
|
double length = trackTripStatisticstrackUpdater.getTripStatistics().getTotalDistance();
|
||||||
long duration = trackTripStatisticstrackUpdater.getTripStatistics().getTotalTime();
|
long duration = trackTripStatisticstrackUpdater.getTripStatistics().getTotalTime();
|
||||||
|
|
||||||
// Insert waypoint
|
// Insert waypoint
|
||||||
Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, location, waypoint.getPhotoUrl());
|
Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, trackPoint, waypoint.getPhotoUrl());
|
||||||
contentProviderUtils.insertWaypoint(newWaypoint);
|
contentProviderUtils.insertWaypoint(newWaypoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +274,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
|
|
||||||
//If not the first segment, add a pause separator if there is at least one location in the last segment.
|
//If not the first segment, add a pause separator if there is at least one location in the last segment.
|
||||||
if (trackData.numberOfSegments > 1 && trackData.lastLocationInCurrentSegment != null) {
|
if (trackData.numberOfSegments > 1 && trackData.lastLocationInCurrentSegment != null) {
|
||||||
insertLocation(createLocation(TrackPointsColumns.PAUSE_LATITUDE, 0.0, 0.0, trackData.lastLocationInCurrentSegment.getTime()));
|
insertLocation(createTrackPoint(TrackPointsColumns.PAUSE_LATITUDE, 0.0, 0.0, trackData.lastLocationInCurrentSegment.getTime()));
|
||||||
}
|
}
|
||||||
trackData.lastLocationInCurrentSegment = null;
|
trackData.lastLocationInCurrentSegment = null;
|
||||||
}
|
}
|
||||||
@@ -288,7 +289,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
}
|
}
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
Location location = createLocation();
|
TrackPoint location = createTrackPoint();
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
throw new SAXException(createErrorMessage("Invalid location detected: " + location));
|
throw new SAXException(createErrorMessage("Invalid location detected: " + location));
|
||||||
@@ -314,8 +315,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
/**
|
/**
|
||||||
* Gets a track point.
|
* Gets a track point.
|
||||||
*/
|
*/
|
||||||
protected Location getTrackPoint() throws SAXException {
|
protected TrackPoint getTrackPoint() throws SAXException {
|
||||||
Location location = createLocation();
|
TrackPoint location = createTrackPoint();
|
||||||
|
|
||||||
// Calculate derived attributes from the previous point
|
// Calculate derived attributes from the previous point
|
||||||
if (trackData.lastLocationInCurrentSegment != null && trackData.lastLocationInCurrentSegment.getTime() != 0) {
|
if (trackData.lastLocationInCurrentSegment != null && trackData.lastLocationInCurrentSegment.getTime() != 0) {
|
||||||
@@ -343,7 +344,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
|
|
||||||
if (trackData.numberOfSegments > 1 && trackData.lastLocationInCurrentSegment == null) {
|
if (trackData.numberOfSegments > 1 && trackData.lastLocationInCurrentSegment == null) {
|
||||||
// If not the first segment, add a resume separator before adding the first location.
|
// If not the first segment, add a resume separator before adding the first location.
|
||||||
insertLocation(createLocation(TrackPointsColumns.RESUME_LATITUDE, 0.0, 0.0, location.getTime()));
|
insertLocation(createTrackPoint(TrackPointsColumns.RESUME_LATITUDE, 0.0, 0.0, location.getTime()));
|
||||||
}
|
}
|
||||||
trackData.lastLocationInCurrentSegment = location;
|
trackData.lastLocationInCurrentSegment = location;
|
||||||
return location;
|
return location;
|
||||||
@@ -352,10 +353,10 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
/**
|
/**
|
||||||
* Inserts a track point.
|
* Inserts a track point.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
*/
|
*/
|
||||||
protected void insertTrackPoint(Location location) {
|
protected void insertTrackPoint(TrackPoint trackPoint) {
|
||||||
insertLocation(location);
|
insertLocation(trackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,7 +385,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
/**
|
/**
|
||||||
* Creates a location.
|
* Creates a location.
|
||||||
*/
|
*/
|
||||||
private Location createLocation() throws SAXException {
|
private TrackPoint createTrackPoint() throws SAXException {
|
||||||
if (latitude == null || longitude == null) {
|
if (latitude == null || longitude == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -415,7 +416,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
throw new SAXException(createErrorMessage(String.format(Locale.US, "Unable to parse time: %s", time)), e);
|
throw new SAXException(createErrorMessage(String.format(Locale.US, "Unable to parse time: %s", time)), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createLocation(latitudeValue, longitudeValue, altitudeValue, timeValue);
|
return createTrackPoint(latitudeValue, longitudeValue, altitudeValue, timeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -426,8 +427,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
* @param altitudeValue the altitude value
|
* @param altitudeValue the altitude value
|
||||||
* @param timeValue the time value
|
* @param timeValue the time value
|
||||||
*/
|
*/
|
||||||
private Location createLocation(double latitudeValue, double longitudeValue, Double altitudeValue, long timeValue) {
|
private TrackPoint createTrackPoint(double latitudeValue, double longitudeValue, Double altitudeValue, long timeValue) {
|
||||||
Location location = new Location(LocationManager.GPS_PROVIDER);
|
TrackPoint location = new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
location.setLatitude(latitudeValue);
|
location.setLatitude(latitudeValue);
|
||||||
location.setLongitude(longitudeValue);
|
location.setLongitude(longitudeValue);
|
||||||
if (altitudeValue != null) {
|
if (altitudeValue != null) {
|
||||||
@@ -443,17 +444,17 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a location.
|
* Inserts a trackPoint.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
*/
|
*/
|
||||||
private void insertLocation(Location location) {
|
private void insertLocation(TrackPoint trackPoint) {
|
||||||
if (trackData.tripStatisticsUpdater == null) {
|
if (trackData.tripStatisticsUpdater == null) {
|
||||||
trackData.tripStatisticsUpdater = new TripStatisticsUpdater(location.getTime() != -1L ? location.getTime() : trackData.importTime);
|
trackData.tripStatisticsUpdater = new TripStatisticsUpdater(trackPoint.getTime() != -1L ? trackPoint.getTime() : trackData.importTime);
|
||||||
}
|
}
|
||||||
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
trackData.tripStatisticsUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
|
||||||
|
|
||||||
trackData.bufferedLocations[trackData.numBufferedLocations] = location;
|
trackData.bufferedTrackPoints[trackData.numBufferedLocations] = trackPoint;
|
||||||
trackData.numBufferedLocations++;
|
trackData.numBufferedLocations++;
|
||||||
trackData.numberOfLocations++;
|
trackData.numberOfLocations++;
|
||||||
|
|
||||||
@@ -471,7 +472,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
if (data.numBufferedLocations <= 0) {
|
if (data.numBufferedLocations <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
contentProviderUtils.bulkInsertTrackPoint(data.bufferedLocations, data.numBufferedLocations, data.track.getId());
|
contentProviderUtils.bulkInsertTrackPoint(data.bufferedTrackPoints, data.numBufferedLocations, data.track.getId());
|
||||||
data.numBufferedLocations = 0;
|
data.numBufferedLocations = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +511,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
final long importTime = System.currentTimeMillis();
|
final long importTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// The buffered locations
|
// The buffered locations
|
||||||
final Location[] bufferedLocations = new Location[MAX_BUFFERED_LOCATIONS];
|
final TrackPoint[] bufferedTrackPoints = new TrackPoint[MAX_BUFFERED_LOCATIONS];
|
||||||
|
|
||||||
// The number of buffered locations
|
// The number of buffered locations
|
||||||
int numBufferedLocations = 0;
|
int numBufferedLocations = 0;
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,11 +155,11 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
* On track point end.
|
* On track point end.
|
||||||
*/
|
*/
|
||||||
private void onTrackPointEnd() throws SAXException {
|
private void onTrackPointEnd() throws SAXException {
|
||||||
Location location = getTrackPoint();
|
TrackPoint trackPoint = getTrackPoint();
|
||||||
if (location == null) {
|
if (trackPoint == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
insertTrackPoint(location);
|
insertTrackPoint(trackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package de.dennisguse.opentracks.io.file.importer;
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
|
|
||||||
private boolean trackStarted = false;
|
private boolean trackStarted = false;
|
||||||
private String sensorType;
|
private String sensorType;
|
||||||
private ArrayList<Location> locationList;
|
private ArrayList<TrackPoint> trackPoints;
|
||||||
private ArrayList<Float> cadenceList;
|
private ArrayList<Float> cadenceList;
|
||||||
private ArrayList<Float> heartRateList;
|
private ArrayList<Float> heartRateList;
|
||||||
private ArrayList<Float> powerList;
|
private ArrayList<Float> powerList;
|
||||||
@@ -213,7 +212,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
@Override
|
@Override
|
||||||
protected void onTrackSegmentStart() {
|
protected void onTrackSegmentStart() {
|
||||||
super.onTrackSegmentStart();
|
super.onTrackSegmentStart();
|
||||||
locationList = new ArrayList<>();
|
trackPoints = new ArrayList<>();
|
||||||
heartRateList = new ArrayList<>();
|
heartRateList = new ArrayList<>();
|
||||||
cadenceList = new ArrayList<>();
|
cadenceList = new ArrayList<>();
|
||||||
powerList = new ArrayList<>();
|
powerList = new ArrayList<>();
|
||||||
@@ -224,8 +223,8 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
*/
|
*/
|
||||||
private void onTrackSegmentEnd() {
|
private void onTrackSegmentEnd() {
|
||||||
// Close a track segment by inserting the segment locations
|
// Close a track segment by inserting the segment locations
|
||||||
for (int i = 0; i < locationList.size(); i++) {
|
for (int i = 0; i < trackPoints.size(); i++) {
|
||||||
Location location = locationList.get(i);
|
TrackPoint trackPoint = trackPoints.get(i);
|
||||||
|
|
||||||
boolean hasSensorData = false;
|
boolean hasSensorData = false;
|
||||||
float heartrate = SensorDataSet.DATA_UNAVAILABLE;
|
float heartrate = SensorDataSet.DATA_UNAVAILABLE;
|
||||||
@@ -246,9 +245,9 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hasSensorData) {
|
if (!hasSensorData) {
|
||||||
insertTrackPoint(location);
|
insertTrackPoint(trackPoint);
|
||||||
} else {
|
} else {
|
||||||
TrackPoint sensorDataSetLocation = new TrackPoint(location, new SensorDataSet(heartrate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, location.getTime()));
|
TrackPoint sensorDataSetLocation = new TrackPoint(trackPoint, new SensorDataSet(heartrate, cadence, power, SensorDataSet.DATA_UNAVAILABLE, trackPoint.getTime()));
|
||||||
insertTrackPoint(sensorDataSetLocation);
|
insertTrackPoint(sensorDataSetLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,11 +269,11 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
latitude = parts[1];
|
latitude = parts[1];
|
||||||
altitude = parts.length == 3 ? parts[2] : null;
|
altitude = parts.length == 3 ? parts[2] : null;
|
||||||
|
|
||||||
Location location = getTrackPoint();
|
TrackPoint location = getTrackPoint();
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
locationList.add(location);
|
trackPoints.add(location);
|
||||||
time = null;
|
time = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import de.dennisguse.opentracks.TrackDetailActivity;
|
|||||||
import de.dennisguse.opentracks.TrackListActivity;
|
import de.dennisguse.opentracks.TrackListActivity;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
|
||||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||||
@@ -140,7 +139,7 @@ public class TrackRecordingService extends Service {
|
|||||||
private BluetoothRemoteSensorManager remoteSensorManager;
|
private BluetoothRemoteSensorManager remoteSensorManager;
|
||||||
|
|
||||||
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
||||||
private Location lastLocation;
|
private TrackPoint lastTrackPoint;
|
||||||
private boolean currentSegmentHasLocation;
|
private boolean currentSegmentHasLocation;
|
||||||
private boolean isIdle;
|
private boolean isIdle;
|
||||||
|
|
||||||
@@ -296,9 +295,9 @@ public class TrackRecordingService extends Service {
|
|||||||
name = getString(R.string.marker_name_format, nextWaypointNumber + 1);
|
name = getString(R.string.marker_name_format, nextWaypointNumber + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = getLastValidTrackPointInCurrentSegment(recordingTrackId);
|
TrackPoint trackPoint = getLastValidTrackPointInCurrentSegment(recordingTrackId);
|
||||||
if (location == null) {
|
if (trackPoint == null) {
|
||||||
Log.i(TAG, "Could not create a waypoint as location is unknown.");
|
Log.i(TAG, "Could not create a waypoint as trackPoint is unknown.");
|
||||||
return -1L;
|
return -1L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +311,7 @@ public class TrackRecordingService extends Service {
|
|||||||
long duration = stats.getTotalTime();
|
long duration = stats.getTotalTime();
|
||||||
|
|
||||||
// Insert waypoint
|
// Insert waypoint
|
||||||
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, length, duration, location, photoUrl);
|
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, length, duration, trackPoint, photoUrl);
|
||||||
Uri uri = contentProviderUtils.insertWaypoint(waypoint);
|
Uri uri = contentProviderUtils.insertWaypoint(waypoint);
|
||||||
return ContentUris.parseId(uri);
|
return ContentUris.parseId(uri);
|
||||||
}
|
}
|
||||||
@@ -380,7 +379,7 @@ public class TrackRecordingService extends Service {
|
|||||||
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
|
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
|
||||||
|
|
||||||
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
trackTripStatisticsUpdater.addLocation(locationIterator, recordingDistanceInterval);
|
trackTripStatisticsUpdater.addTrackPoint(locationIterator, recordingDistanceInterval);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.e(TAG, "RuntimeException", e);
|
Log.e(TAG, "RuntimeException", e);
|
||||||
}
|
}
|
||||||
@@ -400,11 +399,7 @@ public class TrackRecordingService extends Service {
|
|||||||
// Update database
|
// Update database
|
||||||
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
Location resume = new Location(LocationManager.GPS_PROVIDER);
|
insertTrackPoint(track, TrackPoint.createResume(), null);
|
||||||
resume.setLongitude(0);
|
|
||||||
resume.setLatitude(TrackPointsColumns.RESUME_LATITUDE);
|
|
||||||
resume.setTime(System.currentTimeMillis());
|
|
||||||
insertLocation(track, resume, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startRecording();
|
startRecording();
|
||||||
@@ -417,7 +412,7 @@ public class TrackRecordingService extends Service {
|
|||||||
// Update instance variables
|
// Update instance variables
|
||||||
remoteSensorManager = new BluetoothRemoteSensorManager(this);
|
remoteSensorManager = new BluetoothRemoteSensorManager(this);
|
||||||
remoteSensorManager.start();
|
remoteSensorManager.start();
|
||||||
lastLocation = null;
|
lastTrackPoint = null;
|
||||||
currentSegmentHasLocation = false;
|
currentSegmentHasLocation = false;
|
||||||
isIdle = false;
|
isIdle = false;
|
||||||
|
|
||||||
@@ -457,7 +452,7 @@ public class TrackRecordingService extends Service {
|
|||||||
if (track != null) {
|
if (track != null) {
|
||||||
// If not paused, add the last location
|
// If not paused, add the last location
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
|
insertTrackPoint(track, lastTrackPoint, getLastValidTrackPointInCurrentSegment(trackId));
|
||||||
|
|
||||||
// Update the recording track time
|
// Update the recording track time
|
||||||
updateRecordingTrack(track);
|
updateRecordingTrack(track);
|
||||||
@@ -485,13 +480,9 @@ public class TrackRecordingService extends Service {
|
|||||||
// Update database
|
// Update database
|
||||||
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(track.getId()));
|
insertTrackPoint(track, lastTrackPoint, getLastValidTrackPointInCurrentSegment(track.getId()));
|
||||||
|
|
||||||
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
insertTrackPoint(track, TrackPoint.createPause(), null);
|
||||||
pause.setLongitude(0);
|
|
||||||
pause.setLatitude(TrackPointsColumns.PAUSE_LATITUDE);
|
|
||||||
pause.setTime(System.currentTimeMillis());
|
|
||||||
insertLocation(track, pause, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endRecording(false);
|
endRecording(false);
|
||||||
@@ -513,7 +504,7 @@ public class TrackRecordingService extends Service {
|
|||||||
remoteSensorManager.stop();
|
remoteSensorManager.stop();
|
||||||
remoteSensorManager = null;
|
remoteSensorManager = null;
|
||||||
}
|
}
|
||||||
lastLocation = null;
|
lastTrackPoint = null;
|
||||||
|
|
||||||
stopGps(trackStopped);
|
stopGps(trackStopped);
|
||||||
}
|
}
|
||||||
@@ -540,7 +531,7 @@ public class TrackRecordingService extends Service {
|
|||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
* @return the location or null
|
* @return the location or null
|
||||||
*/
|
*/
|
||||||
private Location getLastValidTrackPointInCurrentSegment(long trackId) {
|
private TrackPoint getLastValidTrackPointInCurrentSegment(long trackId) {
|
||||||
if (!currentSegmentHasLocation) {
|
if (!currentSegmentHasLocation) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -590,7 +581,7 @@ public class TrackRecordingService extends Service {
|
|||||||
location.setTime(System.currentTimeMillis());
|
location.setTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
Location lastValidTrackPoint = getLastValidTrackPointInCurrentSegment(track.getId());
|
TrackPoint lastValidTrackPoint = getLastValidTrackPointInCurrentSegment(track.getId());
|
||||||
long idleTime = 0L;
|
long idleTime = 0L;
|
||||||
if (lastValidTrackPoint != null && location.getTime() > lastValidTrackPoint.getTime()) {
|
if (lastValidTrackPoint != null && location.getTime() > lastValidTrackPoint.getTime()) {
|
||||||
idleTime = location.getTime() - lastValidTrackPoint.getTime();
|
idleTime = location.getTime() - lastValidTrackPoint.getTime();
|
||||||
@@ -600,77 +591,69 @@ public class TrackRecordingService extends Service {
|
|||||||
registerLocationListener();
|
registerLocationListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorDataSet sensorDataSet = getSensorDataSet();
|
TrackPoint trackPoint = new TrackPoint(location, getSensorDataSet());
|
||||||
if (sensorDataSet != null) {
|
|
||||||
location = new TrackPoint(location, sensorDataSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always insert the first segment location
|
// Always insert the first segment location
|
||||||
if (!currentSegmentHasLocation) {
|
if (!currentSegmentHasLocation) {
|
||||||
insertLocation(track, location, null);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
currentSegmentHasLocation = true;
|
currentSegmentHasLocation = true;
|
||||||
lastLocation = location;
|
lastTrackPoint = trackPoint;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(lastValidTrackPoint)) {
|
if (!LocationUtils.isValidLocation(lastValidTrackPoint)) {
|
||||||
// Should not happen. The current segment should have a location. Just insert the current location.
|
// Should not happen. The current segment should have a location. Just insert the current location.
|
||||||
insertLocation(track, location, null);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
lastLocation = location;
|
lastTrackPoint = trackPoint;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double distanceToLastTrackLocation = location.distanceTo(lastValidTrackPoint);
|
double distanceToLastTrackLocation = location.distanceTo(lastValidTrackPoint);
|
||||||
if (distanceToLastTrackLocation > maxRecordingDistance) {
|
if (distanceToLastTrackLocation > maxRecordingDistance) {
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertTrackPoint(track, lastTrackPoint, lastValidTrackPoint);
|
||||||
|
insertTrackPoint(track, TrackPoint.createPause(), null);
|
||||||
|
|
||||||
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
pause.setLongitude(0);
|
|
||||||
pause.setLatitude(TrackPointsColumns.PAUSE_LATITUDE);
|
|
||||||
pause.setTime(lastLocation.getTime());
|
|
||||||
insertLocation(track, pause, null);
|
|
||||||
|
|
||||||
insertLocation(track, location, null);
|
|
||||||
isIdle = false;
|
isIdle = false;
|
||||||
} else if (sensorDataSet != null || distanceToLastTrackLocation >= recordingDistanceInterval) {
|
} else if (trackPoint.getSensorDataSet() != null || distanceToLastTrackLocation >= recordingDistanceInterval) {
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertTrackPoint(track, lastTrackPoint, lastValidTrackPoint);
|
||||||
insertLocation(track, location, null);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
isIdle = false;
|
isIdle = false;
|
||||||
} else if (!isIdle && location.hasSpeed() && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
|
} else if (!isIdle && location.hasSpeed() && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertTrackPoint(track, lastTrackPoint, lastValidTrackPoint);
|
||||||
insertLocation(track, location, null);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
isIdle = true;
|
isIdle = true;
|
||||||
} else if (isIdle && location.hasSpeed() && location.getSpeed() >= MAX_NO_MOVEMENT_SPEED) {
|
} else if (isIdle && location.hasSpeed() && location.getSpeed() >= MAX_NO_MOVEMENT_SPEED) {
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertTrackPoint(track, lastTrackPoint, lastValidTrackPoint);
|
||||||
insertLocation(track, location, null);
|
insertTrackPoint(track, trackPoint, null);
|
||||||
isIdle = false;
|
isIdle = false;
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Not recording location, idle");
|
Log.d(TAG, "Not recording location, idle");
|
||||||
}
|
}
|
||||||
lastLocation = location;
|
lastTrackPoint = trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a location.
|
* Inserts a trackPoint.
|
||||||
*
|
*
|
||||||
* @param track the track
|
* @param track the track
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param lastValidTrackPoint the last valid track point, can be null
|
* @param lastValidTrackPoint the last valid track point, can be null
|
||||||
*/
|
*/
|
||||||
private void insertLocation(Track track, Location location, Location lastValidTrackPoint) {
|
private void insertTrackPoint(Track track, TrackPoint trackPoint, Location lastValidTrackPoint) {
|
||||||
if (location == null) {
|
if (trackPoint == null) {
|
||||||
Log.w(TAG, "Ignore insertLocation. location is null.");
|
Log.w(TAG, "Ignore insertLocation. trackPoint is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Do not insert if inserted already
|
// Do not insert if inserted already
|
||||||
if (lastValidTrackPoint != null && lastValidTrackPoint.getTime() == location.getTime()) {
|
if (lastValidTrackPoint != null && lastValidTrackPoint.getTime() == trackPoint.getTime()) {
|
||||||
Log.w(TAG, "Ignore insertLocation. location time same as last valid track point time.");
|
Log.w(TAG, "Ignore insertLocation. trackPoint time same as last valid track point time.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contentProviderUtils.insertTrackPoint(location, track.getId());
|
contentProviderUtils.insertTrackPoint(trackPoint, track.getId());
|
||||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
trackTripStatisticsUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
|
||||||
updateRecordingTrack(track);
|
updateRecordingTrack(track);
|
||||||
} catch (SQLiteException e) {
|
} catch (SQLiteException e) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,8 +82,8 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Override
|
@Override
|
||||||
public void insertTrackPoint(Location location) {
|
public void insertTrackPoint(TrackPoint trackPoint) {
|
||||||
trackRecordingService.onLocationChangedAsync(location);
|
trackRecordingService.onLocationChangedAsync(trackPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,10 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,10 +100,10 @@ public interface TrackRecordingServiceInterface {
|
|||||||
* When recording a track, GPS locations are automatically inserted. This is used for
|
* When recording a track, GPS locations are automatically inserted. This is used for
|
||||||
* inserting special track points or for testing.
|
* inserting special track points or for testing.
|
||||||
*
|
*
|
||||||
* @param location the track point to be inserted
|
* @param trackPoint the track point to be inserted
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void insertTrackPoint(Location location);
|
void insertTrackPoint(TrackPoint trackPoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current sensor data. Returns null if there is no data.
|
* Gets the current sensor data. Returns null if there is no data.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
||||||
import de.dennisguse.opentracks.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
@@ -122,24 +123,24 @@ public class TripStatisticsUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a location.
|
* Adds a trackPoint.
|
||||||
* TODO: This assume location has a valid time.
|
* TODO: This assume trackPoint has a valid time.
|
||||||
*
|
*
|
||||||
* @param location the location
|
* @param trackPoint the trackPoint
|
||||||
* @param minRecordingDistance the min recording distance
|
* @param minRecordingDistance the min recording distance
|
||||||
*/
|
*/
|
||||||
public void addLocation(Location location, int minRecordingDistance) {
|
public void addTrackPoint(TrackPoint trackPoint, int minRecordingDistance) {
|
||||||
// Always update time
|
// Always update time
|
||||||
updateTime(location.getTime());
|
updateTime(trackPoint.getTime());
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(trackPoint)) {
|
||||||
// Either pause or resume marker
|
// Either pause or resume marker
|
||||||
if (location.getLatitude() == TrackPointsColumns.PAUSE_LATITUDE) {
|
if (trackPoint.getLatitude() == TrackPointsColumns.PAUSE_LATITUDE) {
|
||||||
if (lastLocation != null && lastMovingLocation != null && lastLocation != lastMovingLocation) {
|
if (lastLocation != null && lastMovingLocation != null && lastLocation != lastMovingLocation) {
|
||||||
currentSegment.addTotalDistance(lastMovingLocation.distanceTo(lastLocation));
|
currentSegment.addTotalDistance(lastMovingLocation.distanceTo(lastLocation));
|
||||||
}
|
}
|
||||||
tripStatistics.merge(currentSegment);
|
tripStatistics.merge(currentSegment);
|
||||||
}
|
}
|
||||||
currentSegment = init(location.getTime());
|
currentSegment = init(trackPoint.getTime());
|
||||||
lastLocation = null;
|
lastLocation = null;
|
||||||
lastMovingLocation = null;
|
lastMovingLocation = null;
|
||||||
elevationBuffer.reset();
|
elevationBuffer.reset();
|
||||||
@@ -150,23 +151,23 @@ public class TripStatisticsUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Use Barometer to compute elevation gain.
|
//TODO Use Barometer to compute elevation gain.
|
||||||
double elevationDifference = location.hasAltitude() ? updateElevation(location.getAltitude()) : 0.0;
|
double elevationDifference = trackPoint.hasAltitude() ? updateElevation(trackPoint.getAltitude()) : 0.0;
|
||||||
|
|
||||||
if (lastLocation == null || lastMovingLocation == null) {
|
if (lastLocation == null || lastMovingLocation == null) {
|
||||||
lastLocation = location;
|
lastLocation = trackPoint;
|
||||||
lastMovingLocation = location;
|
lastMovingLocation = trackPoint;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double movingDistance = lastMovingLocation.distanceTo(location);
|
double movingDistance = lastMovingLocation.distanceTo(trackPoint);
|
||||||
if (movingDistance < minRecordingDistance && (!location.hasSpeed() || location.getSpeed() < MAX_NO_MOVEMENT_SPEED)) {
|
if (movingDistance < minRecordingDistance && (!trackPoint.hasSpeed() || trackPoint.getSpeed() < MAX_NO_MOVEMENT_SPEED)) {
|
||||||
speedBuffer.reset();
|
speedBuffer.reset();
|
||||||
lastLocation = location;
|
lastLocation = trackPoint;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long movingTime = location.getTime() - lastLocation.getTime();
|
long movingTime = trackPoint.getTime() - lastLocation.getTime();
|
||||||
if (movingTime < 0) {
|
if (movingTime < 0) {
|
||||||
lastLocation = location;
|
lastLocation = trackPoint;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,22 +178,22 @@ public class TripStatisticsUpdater {
|
|||||||
currentSegment.addMovingTime(movingTime);
|
currentSegment.addMovingTime(movingTime);
|
||||||
|
|
||||||
// Update grade
|
// Update grade
|
||||||
double run = lastLocation.distanceTo(location);
|
double run = lastLocation.distanceTo(trackPoint);
|
||||||
updateGrade(run, elevationDifference);
|
updateGrade(run, elevationDifference);
|
||||||
|
|
||||||
// Update max speed
|
// Update max speed
|
||||||
if (location.hasSpeed() && lastLocation.hasSpeed()) {
|
if (trackPoint.hasSpeed() && lastLocation.hasSpeed()) {
|
||||||
updateSpeed(location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
|
updateSpeed(trackPoint.getTime(), trackPoint.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
lastLocation = location;
|
lastLocation = trackPoint;
|
||||||
lastMovingLocation = location;
|
lastMovingLocation = trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLocation(TrackPointIterator iterator, int minRecordingDistance) {
|
public void addTrackPoint(TrackPointIterator iterator, int minRecordingDistance) {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Location location = iterator.next();
|
TrackPoint location = iterator.next();
|
||||||
addLocation(location, minRecordingDistance);
|
addTrackPoint(location, minRecordingDistance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for decimating tracks at a given level of precision.
|
* Utility class for decimating tracks at a given level of precision.
|
||||||
@@ -84,16 +85,16 @@ public class LocationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decimates the given locations for a given zoom level.
|
* Decimates the given trackPoints for a given zoom level.
|
||||||
* This uses a Douglas-Peucker decimation algorithm.
|
* This uses a Douglas-Peucker decimation algorithm.
|
||||||
*
|
*
|
||||||
* @param tolerance in meters
|
* @param tolerance in meters
|
||||||
* @param locations input
|
* @param trackPoints input
|
||||||
* @param decimated output
|
* @param decimated output
|
||||||
*/
|
*/
|
||||||
//TODO What was it used for? Sharing data with other apps?
|
//TODO What was it used for? Sharing data with other apps?
|
||||||
private static void decimate(double tolerance, List<Location> locations, List<Location> decimated) {
|
private static void decimate(double tolerance, List<TrackPoint> trackPoints, List<TrackPoint> decimated) {
|
||||||
final int n = locations.size();
|
final int n = trackPoints.size();
|
||||||
if (n < 1) {
|
if (n < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -115,7 +116,7 @@ public class LocationUtils {
|
|||||||
maxDist = 0;
|
maxDist = 0;
|
||||||
for (idx = current[0] + 1; idx < current[1]; ++idx) {
|
for (idx = current[0] + 1; idx < current[1]; ++idx) {
|
||||||
dist = LocationUtils.distance(
|
dist = LocationUtils.distance(
|
||||||
locations.get(idx), locations.get(current[0]), locations.get(current[1]));
|
trackPoints.get(idx), trackPoints.get(current[0]), trackPoints.get(current[1]));
|
||||||
if (dist > maxDist) {
|
if (dist > maxDist) {
|
||||||
maxDist = dist;
|
maxDist = dist;
|
||||||
maxIdx = idx;
|
maxIdx = idx;
|
||||||
@@ -134,7 +135,7 @@ public class LocationUtils {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
decimated.clear();
|
decimated.clear();
|
||||||
for (Location l : locations) {
|
for (TrackPoint l : trackPoints) {
|
||||||
if (dists[idx] != 0) {
|
if (dists[idx] != 0) {
|
||||||
decimated.add(l);
|
decimated.add(l);
|
||||||
i++;
|
i++;
|
||||||
@@ -151,9 +152,9 @@ public class LocationUtils {
|
|||||||
* @param precision desired precision in meters
|
* @param precision desired precision in meters
|
||||||
*/
|
*/
|
||||||
public static void decimate(Track track, double precision) {
|
public static void decimate(Track track, double precision) {
|
||||||
ArrayList<Location> decimated = new ArrayList<>();
|
ArrayList<TrackPoint> decimated = new ArrayList<>();
|
||||||
decimate(precision, track.getLocations(), decimated);
|
decimate(precision, track.getTrackPoints(), decimated);
|
||||||
track.setLocations(decimated);
|
track.setTrackPoints(decimated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user