Removed WaypointType.

This commit is contained in:
Dennis Guse
2019-12-21 16:23:25 +01:00
parent 013e56bef0
commit f37fe4a503
16 changed files with 144 additions and 292 deletions
@@ -35,7 +35,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.stats.TripStatistics; import de.dennisguse.opentracks.stats.TripStatistics;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -57,7 +56,7 @@ public class CustomContentProviderUtilsTest {
private static final double ALTITUDE_INTERVAL = 2.5; private static final double ALTITUDE_INTERVAL = 2.5;
private Context context = ApplicationProvider.getApplicationContext(); private Context context = ApplicationProvider.getApplicationContext();
private ContentProviderUtils providerUtils; private ContentProviderUtils contentProviderUtils;
@Mock @Mock
private Cursor cursorMock; private Cursor cursorMock;
@@ -67,8 +66,8 @@ public class CustomContentProviderUtilsTest {
@Before @Before
public void setUp() { public void setUp() {
providerUtils = new ContentProviderUtils(context); contentProviderUtils = new ContentProviderUtils(context);
providerUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
} }
@Test @Test
@@ -132,9 +131,9 @@ public class CustomContentProviderUtilsTest {
private List<Location> testIterator(long trackId, int numPoints, int batchSize, boolean descending, LocationFactory locationFactory) { private List<Location> testIterator(long trackId, int numPoints, int batchSize, boolean descending, LocationFactory locationFactory) {
long lastPointId = initializeTrack(trackId, numPoints); long lastPointId = initializeTrack(trackId, numPoints);
((ContentProviderUtils) providerUtils).setDefaultCursorBatchSize(batchSize); ((ContentProviderUtils) contentProviderUtils).setDefaultCursorBatchSize(batchSize);
List<Location> locations = new ArrayList<Location>(numPoints); List<Location> locations = new ArrayList<Location>(numPoints);
try (LocationIterator it = providerUtils.getTrackPointLocationIterator(trackId, -1L, descending, locationFactory)) { try (LocationIterator it = contentProviderUtils.getTrackPointLocationIterator(trackId, -1L, descending, locationFactory)) {
while (it.hasNext()) { while (it.hasNext()) {
Location loc = it.next(); Location loc = it.next();
Assert.assertNotNull(loc); Assert.assertNotNull(loc);
@@ -153,8 +152,8 @@ public class CustomContentProviderUtilsTest {
track.setId(id); track.setId(id);
track.setName("Test: " + id); track.setName("Test: " + id);
track.setNumberOfPoints(numPoints); track.setNumberOfPoints(numPoints);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
track = providerUtils.getTrack(id); track = contentProviderUtils.getTrack(id);
Assert.assertNotNull(track); Assert.assertNotNull(track);
Location[] locations = new Location[numPoints]; Location[] locations = new Location[numPoints];
@@ -166,12 +165,12 @@ public class CustomContentProviderUtilsTest {
loc.setAltitude(i * 2.5); loc.setAltitude(i * 2.5);
locations[i] = loc; locations[i] = loc;
} }
providerUtils.bulkInsertTrackPoint(locations, numPoints, id); contentProviderUtils.bulkInsertTrackPoint(locations, numPoints, id);
// Load all inserted locations. // Load all inserted locations.
long lastPointId = -1; long lastPointId = -1;
int counter = 0; int counter = 0;
try (LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1L, false, LocationFactory.DEFAULT_LOCATION_FACTORY)) { try (LocationIterator it = contentProviderUtils.getTrackPointLocationIterator(id, -1L, false, LocationFactory.DEFAULT_LOCATION_FACTORY)) {
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
lastPointId = it.getLocationId(); lastPointId = it.getLocationId();
@@ -208,7 +207,7 @@ public class CustomContentProviderUtilsTest {
String name = NAME_PREFIX + trackId; String name = NAME_PREFIX + trackId;
when(cursorMock.getString(columnIndex++)).thenReturn(name); when(cursorMock.getString(columnIndex++)).thenReturn(name);
Track track = providerUtils.createTrack(cursorMock); Track track = contentProviderUtils.createTrack(cursorMock);
Assert.assertEquals(trackId, track.getId()); Assert.assertEquals(trackId, track.getId());
Assert.assertEquals(name, track.getName()); Assert.assertEquals(name, track.getName());
} }
@@ -223,7 +222,7 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
Waypoint waypoint = new Waypoint(); Waypoint waypoint = new Waypoint();
providerUtils.insertWaypoint(waypoint); contentProviderUtils.insertWaypoint(waypoint);
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
Assert.assertEquals(1, tracksCursor.getCount()); Assert.assertEquals(1, tracksCursor.getCount());
@@ -232,7 +231,7 @@ public class CustomContentProviderUtilsTest {
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
Assert.assertEquals(1, waypointCursor.getCount()); Assert.assertEquals(1, waypointCursor.getCount());
// Delete all. // Delete all.
providerUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
// Check whether all have been deleted. // Check whether all have been deleted.
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
Assert.assertEquals(0, tracksCursor.getCount()); Assert.assertEquals(0, tracksCursor.getCount());
@@ -251,13 +250,13 @@ public class CustomContentProviderUtilsTest {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
insertTrackWithLocations(getTrack(trackId + 1, 10)); insertTrackWithLocations(getTrack(trackId + 1, 10));
insertTrackWithLocations(getTrack(trackId + 2, 10)); insertTrackWithLocations(getTrack(trackId + 2, 10));
Waypoint waypoint = new Waypoint(); Waypoint waypoint = new Waypoint();
waypoint.setTrackId(trackId); waypoint.setTrackId(trackId);
providerUtils.insertWaypoint(waypoint); contentProviderUtils.insertWaypoint(waypoint);
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
@@ -267,7 +266,7 @@ public class CustomContentProviderUtilsTest {
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID); Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
Assert.assertEquals(1, waypointCursor.getCount()); Assert.assertEquals(1, waypointCursor.getCount());
// Delete one track. // Delete one track.
providerUtils.deleteTrack(context, trackId); contentProviderUtils.deleteTrack(context, trackId);
// Check whether all data of a track has been deleted. // Check whether all data of a track has been deleted.
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
Assert.assertEquals(2, tracksCursor.getCount()); Assert.assertEquals(2, tracksCursor.getCount());
@@ -282,10 +281,10 @@ public class CustomContentProviderUtilsTest {
*/ */
@Test @Test
public void testGetAllTracks() { public void testGetAllTracks() {
int initialTrackNumber = providerUtils.getAllTracks().size(); int initialTrackNumber = contentProviderUtils.getAllTracks().size();
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
providerUtils.insertTrack(getTrack(trackId, 0)); contentProviderUtils.insertTrack(getTrack(trackId, 0));
List<Track> allTracks = providerUtils.getAllTracks(); List<Track> allTracks = contentProviderUtils.getAllTracks();
Assert.assertEquals(initialTrackNumber + 1, allTracks.size()); Assert.assertEquals(initialTrackNumber + 1, allTracks.size());
Assert.assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId()); Assert.assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId());
} }
@@ -296,8 +295,8 @@ public class CustomContentProviderUtilsTest {
@Test @Test
public void testGetLastTrack() { public void testGetLastTrack() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
providerUtils.insertTrack(getTrack(trackId, 0)); contentProviderUtils.insertTrack(getTrack(trackId, 0));
Assert.assertEquals(trackId, providerUtils.getLastTrack().getId()); Assert.assertEquals(trackId, contentProviderUtils.getLastTrack().getId());
} }
/** /**
@@ -306,8 +305,8 @@ public class CustomContentProviderUtilsTest {
@Test @Test
public void testGetTrack() { public void testGetTrack() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
providerUtils.insertTrack(getTrack(trackId, 0)); contentProviderUtils.insertTrack(getTrack(trackId, 0));
Assert.assertNotNull(providerUtils.getTrack(trackId)); Assert.assertNotNull(contentProviderUtils.getTrack(trackId));
} }
/** /**
@@ -320,11 +319,11 @@ public class CustomContentProviderUtilsTest {
String nameOld = "name1"; String nameOld = "name1";
String nameNew = "name2"; String nameNew = "name2";
track.setName(nameOld); track.setName(nameOld);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Assert.assertEquals(nameOld, providerUtils.getTrack(trackId).getName()); Assert.assertEquals(nameOld, contentProviderUtils.getTrack(trackId).getName());
track.setName(nameNew); track.setName(nameNew);
providerUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
Assert.assertEquals(nameNew, providerUtils.getTrack(trackId).getName()); Assert.assertEquals(nameNew, contentProviderUtils.getTrack(trackId).getName());
} }
/** /**
@@ -334,7 +333,7 @@ public class CustomContentProviderUtilsTest {
public void testCreateContentValues_waypoint() { public void testCreateContentValues_waypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
// Bottom // Bottom
long startTime = 1000L; long startTime = 1000L;
// AverageSpeed // AverageSpeed
@@ -355,7 +354,6 @@ public class CustomContentProviderUtilsTest {
// Insert at first. // Insert at first.
Waypoint waypoint = new Waypoint(); Waypoint waypoint = new Waypoint();
waypoint.setDescription(TEST_DESC); waypoint.setDescription(TEST_DESC);
waypoint.setType(WaypointType.STATISTICS);
waypoint.setTripStatistics(statistics); waypoint.setTripStatistics(statistics);
Location location = new Location("test"); Location location = new Location("test");
@@ -364,7 +362,7 @@ public class CustomContentProviderUtilsTest {
location.setAccuracy((float) 1 / 100.0f); location.setAccuracy((float) 1 / 100.0f);
location.setAltitude(2.5); location.setAltitude(2.5);
waypoint.setLocation(location); waypoint.setLocation(location);
providerUtils.insertWaypoint(waypoint); contentProviderUtils.insertWaypoint(waypoint);
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock); ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock);
@@ -406,7 +404,7 @@ public class CustomContentProviderUtilsTest {
long trackId = 11L; long trackId = 11L;
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId); when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
Waypoint waypoint = providerUtils.createWaypoint(cursorMock); Waypoint waypoint = contentProviderUtils.createWaypoint(cursorMock);
Assert.assertEquals(id, waypoint.getId()); Assert.assertEquals(id, waypoint.getId());
Assert.assertEquals(name, waypoint.getName()); Assert.assertEquals(name, waypoint.getName());
Assert.assertEquals(trackId, waypoint.getTrackId()); Assert.assertEquals(trackId, waypoint.getTrackId());
@@ -414,50 +412,37 @@ public class CustomContentProviderUtilsTest {
/** /**
* Tests the method * Tests the method
* {@link ContentProviderUtils#deleteWaypoint(Context, long, DescriptionGenerator)} * {@link ContentProviderUtils#deleteWaypoint(Context, long)}
* when there is only one waypoint in the track. * when there is only one waypoint in the track.
*/ */
@Test @Test
public void testDeleteWaypoint_onlyOneWayPoint() { public void testDeleteWaypoint_onlyOneWayPoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
// Insert at first. // Insert at first.
Waypoint waypoint1 = new Waypoint(); Waypoint waypoint1 = new Waypoint();
waypoint1.setDescription(TEST_DESC); waypoint1.setDescription(TEST_DESC);
waypoint1.setTrackId(trackId); waypoint1.setTrackId(trackId);
waypoint1.setType(WaypointType.STATISTICS); contentProviderUtils.insertWaypoint(waypoint1);
providerUtils.insertWaypoint(waypoint1);
// Delete // Delete
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { contentProviderUtils.deleteWaypoint(context, 1);
@Override Assert.assertNull(contentProviderUtils.getWaypoint(1));
public String generateWaypointDescription(TripStatistics tripStatistics) {
return CustomContentProviderUtilsTest.MOCK_DESC;
}
@Override
public String generateTrackDescription(Track aTrack, boolean html) {
return null;
}
};
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
Assert.assertNull(providerUtils.getWaypoint(1));
} }
/** /**
* Tests the method * Tests the method
* {@link ContentProviderUtils#deleteWaypoint(Context, long, DescriptionGenerator)} * {@link ContentProviderUtils#deleteWaypoint(Context, long)}
* when there is more than one waypoint in the track. * when there is more than one waypoint in the track.
*/ */
@Test @Test
public void testDeleteWaypoint_hasNextWayPoint() { public void testDeleteWaypoint_hasNextWayPoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
TripStatistics statistics = new TripStatistics(); TripStatistics statistics = new TripStatistics();
statistics.setStartTime(1000L); statistics.setStartTime(1000L);
@@ -475,39 +460,23 @@ public class CustomContentProviderUtilsTest {
// Insert at first. // Insert at first.
Waypoint waypoint1 = new Waypoint(); Waypoint waypoint1 = new Waypoint();
waypoint1.setDescription(Long.toString(trackId)); waypoint1.setDescription(MOCK_DESC);
waypoint1.setTrackId(trackId); waypoint1.setTrackId(trackId);
waypoint1.setType(WaypointType.STATISTICS);
waypoint1.setTripStatistics(statistics); waypoint1.setTripStatistics(statistics);
long waypoint1Id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint1)); long waypoint1Id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1));
Waypoint waypoint2 = new Waypoint(); Waypoint waypoint2 = new Waypoint();
waypoint2.setDescription(Long.toString(trackId)); waypoint2.setDescription(Long.toString(trackId));
waypoint2.setTrackId(trackId); waypoint2.setTrackId(trackId);
waypoint2.setType(WaypointType.STATISTICS);
waypoint2.setTripStatistics(statistics); waypoint2.setTripStatistics(statistics);
long waypoint2Id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint2)); long waypoint2Id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint2));
// Delete // Delete
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { Assert.assertNotNull(contentProviderUtils.getWaypoint(waypoint1Id));
@Override contentProviderUtils.deleteWaypoint(context, waypoint1Id);
public String generateWaypointDescription(TripStatistics tripStatistics) { Assert.assertNull(contentProviderUtils.getWaypoint(waypoint1Id));
return CustomContentProviderUtilsTest.MOCK_DESC;
}
@Override Assert.assertEquals(MOCK_DESC, contentProviderUtils.getWaypoint(waypoint2Id).getDescription());
public String generateTrackDescription(Track aTrack, boolean html) {
return null;
}
};
Assert.assertNotNull(providerUtils.getWaypoint(waypoint1Id));
providerUtils.deleteWaypoint(context, waypoint1Id, descriptionGenerator);
Assert.assertNull(providerUtils.getWaypoint(waypoint1Id));
Assert.assertEquals(CustomContentProviderUtilsTest.MOCK_DESC, providerUtils.getWaypoint(waypoint2Id)
.getDescription());
} }
/** /**
@@ -517,78 +486,70 @@ public class CustomContentProviderUtilsTest {
public void testGetFirstWaypointId() { public void testGetFirstWaypointId() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Waypoint waypoint1 = new Waypoint(); Waypoint waypoint1 = new Waypoint();
waypoint1.setTrackId(trackId); waypoint1.setTrackId(trackId);
long waypoint1id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint1)); long waypoint1id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1));
Waypoint waypoint2 = new Waypoint(); Waypoint waypoint2 = new Waypoint();
waypoint2.setTrackId(trackId); waypoint2.setTrackId(trackId);
long waypoint2id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint2)); long waypoint2id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint2));
Assert.assertEquals(-1L, providerUtils.getFirstWaypointId(-1)); Assert.assertEquals(-1L, contentProviderUtils.getFirstWaypointId(-1));
Assert.assertEquals(waypoint1id, providerUtils.getFirstWaypointId(trackId)); Assert.assertEquals(waypoint1id, contentProviderUtils.getFirstWaypointId(trackId));
Assert.assertEquals(waypoint2id, providerUtils.getLastWaypoint(trackId, WaypointType.WAYPOINT).getId()); Assert.assertEquals(waypoint2id, contentProviderUtils.getLastWaypoint(trackId).getId());
} }
/** /**
* Tests the method {@link ContentProviderUtils#getNextWaypointNumber(long, WaypointType)}. * Tests the method {@link ContentProviderUtils#getNextWaypointNumber(long)}.
*/ */
@Test @Test
public void testGetNextWaypointNumber() { public void testGetNextWaypointNumber() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Waypoint waypoint1 = new Waypoint(); Waypoint waypoint1 = new Waypoint();
waypoint1.setType(WaypointType.STATISTICS);
waypoint1.setTrackId(trackId); waypoint1.setTrackId(trackId);
Waypoint waypoint2 = new Waypoint(); Waypoint waypoint2 = new Waypoint();
waypoint2.setType(WaypointType.WAYPOINT);
waypoint2.setTrackId(trackId); waypoint2.setTrackId(trackId);
Waypoint waypoint3 = new Waypoint(); Waypoint waypoint3 = new Waypoint();
waypoint3.setType(WaypointType.STATISTICS);
waypoint3.setTrackId(trackId); waypoint3.setTrackId(trackId);
Waypoint waypoint4 = new Waypoint(); Waypoint waypoint4 = new Waypoint();
waypoint4.setType(WaypointType.WAYPOINT);
waypoint4.setTrackId(trackId); waypoint4.setTrackId(trackId);
providerUtils.insertWaypoint(waypoint1); contentProviderUtils.insertWaypoint(waypoint1);
providerUtils.insertWaypoint(waypoint2); contentProviderUtils.insertWaypoint(waypoint2);
providerUtils.insertWaypoint(waypoint3); contentProviderUtils.insertWaypoint(waypoint3);
providerUtils.insertWaypoint(waypoint4); contentProviderUtils.insertWaypoint(waypoint4);
Assert.assertEquals(2, providerUtils.getNextWaypointNumber(trackId, WaypointType.STATISTICS)); Assert.assertEquals(4, contentProviderUtils.getNextWaypointNumber(trackId));
Assert.assertEquals(3, providerUtils.getNextWaypointNumber(trackId, WaypointType.WAYPOINT));
} }
/** /**
* Tests the method * Tests the method
* {@link ContentProviderUtils#getLastWaypoint(long, WaypointType)}. * {@link ContentProviderUtils#getLastWaypoint(long)}.
*/ */
@Test @Test
public void testGetLastStatisticsWaypoint() { public void testGetLastWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Waypoint waypoint1 = new Waypoint(); Waypoint waypoint1 = new Waypoint();
waypoint1.setTrackId(trackId); waypoint1.setTrackId(trackId);
waypoint1.setType(WaypointType.STATISTICS);
waypoint1.setDescription("Desc1"); waypoint1.setDescription("Desc1");
Waypoint waypoint2 = new Waypoint(); Waypoint waypoint2 = new Waypoint();
waypoint2.setTrackId(trackId); waypoint2.setTrackId(trackId);
waypoint2.setType(WaypointType.STATISTICS);
waypoint2.setDescription("Desc2"); waypoint2.setDescription("Desc2");
Waypoint waypoint3 = new Waypoint(); Waypoint waypoint3 = new Waypoint();
waypoint3.setTrackId(trackId); waypoint3.setTrackId(trackId);
waypoint3.setType(WaypointType.WAYPOINT);
waypoint3.setDescription("Desc3"); waypoint3.setDescription("Desc3");
providerUtils.insertWaypoint(waypoint1); contentProviderUtils.insertWaypoint(waypoint1);
providerUtils.insertWaypoint(waypoint2); contentProviderUtils.insertWaypoint(waypoint2);
providerUtils.insertWaypoint(waypoint3); contentProviderUtils.insertWaypoint(waypoint3);
Assert.assertEquals("Desc2", providerUtils.getLastWaypoint(trackId, WaypointType.STATISTICS).getDescription()); Assert.assertEquals("Desc3", contentProviderUtils.getLastWaypoint(trackId).getDescription());
} }
/** /**
@@ -599,14 +560,14 @@ public class CustomContentProviderUtilsTest {
public void testInsertAndGetWaypoint() { public void testInsertAndGetWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Waypoint waypoint = new Waypoint(); Waypoint waypoint = new Waypoint();
waypoint.setDescription(TEST_DESC); waypoint.setDescription(TEST_DESC);
waypoint.setTrackId(trackId); waypoint.setTrackId(trackId);
long waypointId = ContentUris.parseId(providerUtils.insertWaypoint(waypoint)); long waypointId = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint));
Assert.assertEquals(TEST_DESC, providerUtils.getWaypoint(waypointId).getDescription()); Assert.assertEquals(TEST_DESC, contentProviderUtils.getWaypoint(waypointId).getDescription());
} }
/** /**
@@ -616,19 +577,19 @@ public class CustomContentProviderUtilsTest {
public void testUpdateWaypoint() { public void testUpdateWaypoint() {
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
// Insert at first. // Insert at first.
Waypoint waypoint = new Waypoint(); Waypoint waypoint = new Waypoint();
waypoint.setDescription(TEST_DESC); waypoint.setDescription(TEST_DESC);
waypoint.setTrackId(trackId); waypoint.setTrackId(trackId);
long waypointId = ContentUris.parseId(providerUtils.insertWaypoint(waypoint)); long waypointId = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint));
// Update // Update
waypoint = providerUtils.getWaypoint(waypointId); waypoint = contentProviderUtils.getWaypoint(waypointId);
waypoint.setDescription(TEST_DESC_NEW); waypoint.setDescription(TEST_DESC_NEW);
providerUtils.updateWaypoint(waypoint); contentProviderUtils.updateWaypoint(waypoint);
Assert.assertEquals(TEST_DESC_NEW, providerUtils.getWaypoint(waypointId).getDescription()); Assert.assertEquals(TEST_DESC_NEW, contentProviderUtils.getWaypoint(waypointId).getDescription());
} }
/** /**
@@ -641,10 +602,10 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId); contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId);
Assert.assertEquals(20, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount()); Assert.assertEquals(20, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId); contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId);
Assert.assertEquals(28, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount()); Assert.assertEquals(28, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
} }
/** /**
@@ -699,7 +660,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 = providerUtils.createTrackPoint(cursorMock); Location location = contentProviderUtils.createTrackPoint(cursorMock);
Assert.assertEquals((double) longitude, location.getLongitude(), 0.01); Assert.assertEquals((double) longitude, location.getLongitude(), 0.01);
Assert.assertEquals((double) latitude, location.getLatitude(), 0.01); Assert.assertEquals((double) latitude, location.getLatitude(), 0.01);
Assert.assertEquals(time, location.getTime(), 0.01); Assert.assertEquals(time, location.getTime(), 0.01);
@@ -717,8 +678,8 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
providerUtils.insertTrackPoint(createLocation(22), trackId); contentProviderUtils.insertTrackPoint(createLocation(22), trackId);
Assert.assertEquals(11, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount()); Assert.assertEquals(11, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
} }
/** /**
@@ -731,7 +692,7 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
Assert.assertNotEquals(-1L, providerUtils.getFirstTrackPointId(trackId)); Assert.assertNotEquals(-1L, contentProviderUtils.getFirstTrackPointId(trackId));
} }
/** /**
@@ -744,7 +705,7 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
Assert.assertTrue(providerUtils.getFirstTrackPointId(trackId) < providerUtils.getLastTrackPointId(trackId)); Assert.assertTrue(contentProviderUtils.getFirstTrackPointId(trackId) < contentProviderUtils.getLastTrackPointId(trackId));
} }
/** /**
@@ -757,7 +718,7 @@ public class CustomContentProviderUtilsTest {
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
insertTrackWithLocations(track); insertTrackWithLocations(track);
Location lastLocation = providerUtils.getLastValidTrackPoint(trackId); Location lastLocation = contentProviderUtils.getLastValidTrackPoint(trackId);
checkLocation(9, lastLocation); checkLocation(9, lastLocation);
} }
@@ -769,14 +730,14 @@ public class CustomContentProviderUtilsTest {
// Insert track, points at first. // Insert track, points at first.
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
long[] trackpointIds = new long[track.getNumberOfPoints()]; long[] trackpointIds = new long[track.getNumberOfPoints()];
for (int i = 0; i < trackpointIds.length; i++) { for (int i = 0; i < trackpointIds.length; i++) {
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId())); trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
} }
Cursor cursor = providerUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true); Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true);
Assert.assertEquals(2, cursor.getCount()); Assert.assertEquals(2, cursor.getCount());
} }
@@ -788,14 +749,14 @@ public class CustomContentProviderUtilsTest {
// Insert track, points at first. // Insert track, points at first.
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
long[] trackpointIds = new long[track.getNumberOfPoints()]; long[] trackpointIds = new long[track.getNumberOfPoints()];
for (int i = 0; i < trackpointIds.length; i++) { for (int i = 0; i < trackpointIds.length; i++) {
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId())); trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
} }
Cursor cursor = providerUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false); Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false);
Assert.assertEquals(2, cursor.getCount()); Assert.assertEquals(2, cursor.getCount());
} }
@@ -807,16 +768,16 @@ public class CustomContentProviderUtilsTest {
// Insert track, points at first. // Insert track, points at first.
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
long[] trackpointIds = new long[track.getNumberOfPoints()]; long[] trackpointIds = new long[track.getNumberOfPoints()];
for (int i = 0; i < trackpointIds.length; i++) { for (int i = 0; i < trackpointIds.length; i++) {
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId())); trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
} }
long startTrackPointId = trackpointIds[9]; long startTrackPointId = trackpointIds[9];
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, LocationFactory.DEFAULT_LOCATION_FACTORY); LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, LocationFactory.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(locationIterator.hasNext());
Location location = locationIterator.next(); Location location = locationIterator.next();
@@ -834,16 +795,16 @@ public class CustomContentProviderUtilsTest {
// Insert track, point at first. // Insert track, point at first.
long trackId = System.currentTimeMillis(); long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10); Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
long[] trackpointIds = new long[track.getNumberOfPoints()]; long[] trackpointIds = new long[track.getNumberOfPoints()];
for (int i = 0; i < trackpointIds.length; i++) { for (int i = 0; i < trackpointIds.length; i++) {
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId())); trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
} }
long startTrackPointId = trackpointIds[0]; long startTrackPointId = trackpointIds[0];
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, LocationFactory.DEFAULT_LOCATION_FACTORY); LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, LocationFactory.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(locationIterator.hasNext());
Location location = locationIterator.next(); Location location = locationIterator.next();
@@ -906,7 +867,7 @@ public class CustomContentProviderUtilsTest {
* @param track track to be inserted * @param track track to be inserted
*/ */
private void insertTrackWithLocations(Track track) { private void insertTrackWithLocations(Track track) {
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId()); contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId());
} }
} }
@@ -53,10 +53,8 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval()); assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval());
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the // First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the nearest second.
// nearest second. assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000, adocationListenerPolicy.getDesiredPollingInterval());
assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000,
adocationListenerPolicy.getDesiredPollingInterval());
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval()); assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
@@ -46,7 +46,6 @@ import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.CustomContentProvider; import de.dennisguse.opentracks.content.CustomContentProvider;
import de.dennisguse.opentracks.content.Track; import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.WaypointCreationRequest; import de.dennisguse.opentracks.content.WaypointCreationRequest;
import de.dennisguse.opentracks.stats.TripStatistics; import de.dennisguse.opentracks.stats.TripStatistics;
import de.dennisguse.opentracks.util.PreferencesUtils; import de.dennisguse.opentracks.util.PreferencesUtils;
@@ -69,7 +68,7 @@ public class TrackRecordingServiceTest {
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION); public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
private Context context = ApplicationProvider.getApplicationContext(); private Context context = ApplicationProvider.getApplicationContext();
private ContentProviderUtils providerUtils; private ContentProviderUtils contentProviderUtils;
private final long trackId = Math.abs(new Random().nextLong()); private final long trackId = Math.abs(new Random().nextLong());
@@ -84,14 +83,14 @@ public class TrackRecordingServiceTest {
}; };
customContentProvider.attachInfo(context, null); customContentProvider.attachInfo(context, null);
providerUtils = new ContentProviderUtils(context); contentProviderUtils = new ContentProviderUtils(context);
// Let's use default values. // Let's use default values.
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context); SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
sharedPreferences.edit().clear().apply(); sharedPreferences.edit().clear().apply();
// Ensure that the database is empty before every test // Ensure that the database is empty before every test
providerUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
} }
@After @After
@@ -103,7 +102,7 @@ public class TrackRecordingServiceTest {
} }
// Ensure that the database is empty after every test // Ensure that the database is empty after every test
providerUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
} }
@SmallTest @SmallTest
@@ -123,7 +122,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_noTracks() throws Exception { public void testRecording_noTracks() throws Exception {
List<Track> tracks = providerUtils.getAllTracks(); List<Track> tracks = contentProviderUtils.getAllTracks();
Assert.assertTrue(tracks.isEmpty()); Assert.assertTrue(tracks.isEmpty());
Intent startIntent = createStartIntent(context); Intent startIntent = createStartIntent(context);
@@ -203,8 +202,8 @@ public class TrackRecordingServiceTest {
private void addTrack(Track track, boolean isRecording) { private void addTrack(Track track, boolean isRecording) {
Assert.assertTrue(track.getId() >= 0); Assert.assertTrue(track.getId() >= 0);
providerUtils.insertTrack(track); contentProviderUtils.insertTrack(track);
Assert.assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId()); Assert.assertEquals(track.getId(), contentProviderUtils.getTrack(track.getId()).getId());
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT); PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording); PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording);
} }
@@ -231,7 +230,7 @@ public class TrackRecordingServiceTest {
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context))); ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
Assert.assertFalse(service.isRecording()); Assert.assertFalse(service.isRecording());
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT); long waypointId = service.insertWaypoint(new WaypointCreationRequest(null, null, null, null, null));
Assert.assertEquals(-1L, waypointId); Assert.assertEquals(-1L, waypointId);
} }
@@ -244,12 +243,11 @@ public class TrackRecordingServiceTest {
insertLocation(service); insertLocation(service);
long trackId = service.getRecordingTrackId(); long trackId = service.getRecordingTrackId();
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT); long waypointId = service.insertWaypoint(new WaypointCreationRequest(null, null, null, null, null));
Assert.assertNotEquals(-1L, waypointId); Assert.assertNotEquals(-1L, waypointId);
Waypoint wpt = providerUtils.getWaypoint(waypointId); Waypoint wpt = contentProviderUtils.getWaypoint(waypointId);
Assert.assertEquals(context.getString(R.string.marker_waypoint_icon_url), wpt.getIcon()); Assert.assertEquals(context.getString(R.string.marker_waypoint_icon_url), wpt.getIcon());
Assert.assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName()); Assert.assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName());
Assert.assertEquals(WaypointType.WAYPOINT, wpt.getType());
Assert.assertEquals(trackId, wpt.getTrackId()); Assert.assertEquals(trackId, wpt.getTrackId());
Assert.assertEquals(0.0, wpt.getLength(), 0.01); Assert.assertEquals(0.0, wpt.getLength(), 0.01);
Assert.assertNotNull(wpt.getLocation()); Assert.assertNotNull(wpt.getLocation());
@@ -219,7 +219,7 @@ public class TrackRecordingServiceTestLooper {
service.insertTrackPoint(location); service.insertTrackPoint(location);
if (i % 7 == 0) { if (i % 7 == 0) {
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT); service.insertWaypoint(new WaypointCreationRequest(null, null, null, null, null));
} }
} }
@@ -27,7 +27,6 @@ import android.widget.EditText;
import de.dennisguse.opentracks.content.ContentProviderUtils; import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.WaypointCreationRequest; import de.dennisguse.opentracks.content.WaypointCreationRequest;
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
@@ -126,7 +125,7 @@ public class MarkerEditActivity extends AbstractActivity {
if (newMarker) { if (newMarker) {
statisticsSection.setVisibility(View.GONE); statisticsSection.setVisibility(View.GONE);
waypointSection.setVisibility(View.VISIBLE); waypointSection.setVisibility(View.VISIBLE);
int nextWaypointNumber = trackId == -1L ? -1 : new ContentProviderUtils(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT); int nextWaypointNumber = trackId == -1L ? -1 : new ContentProviderUtils(this).getNextWaypointNumber(trackId);
if (nextWaypointNumber == -1) { if (nextWaypointNumber == -1) {
nextWaypointNumber = 0; nextWaypointNumber = 0;
} }
@@ -141,7 +140,7 @@ public class MarkerEditActivity extends AbstractActivity {
finish(); finish();
return; return;
} }
boolean statistics = waypoint.getType() == WaypointType.STATISTICS; boolean statistics = false; //TODO REMOVE
statisticsSection.setVisibility(statistics ? View.VISIBLE : View.GONE); statisticsSection.setVisibility(statistics ? View.VISIBLE : View.GONE);
waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE); waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE);
if (statistics) { if (statistics) {
@@ -159,7 +158,6 @@ public class MarkerEditActivity extends AbstractActivity {
*/ */
private void addMarker() { private void addMarker() {
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest( WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
WaypointType.WAYPOINT,
false, false,
waypointName.getText().toString(), waypointName.getText().toString(),
waypointMarkerType.getText().toString(), waypointMarkerType.getText().toString(),
@@ -173,7 +171,7 @@ public class MarkerEditActivity extends AbstractActivity {
* Saves a marker. * Saves a marker.
*/ */
private void saveMarker() { private void saveMarker() {
boolean statistics = waypoint.getType() == WaypointType.STATISTICS; boolean statistics = false; //TODO REMOVE
if (statistics) { if (statistics) {
waypoint.setName(statisticsName.getText().toString()); waypoint.setName(statisticsName.getText().toString());
} else { } else {
@@ -46,7 +46,6 @@ import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.Track; import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.TrackDataHub; import de.dennisguse.opentracks.content.TrackDataHub;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.WaypointCreationRequest; import de.dennisguse.opentracks.content.WaypointCreationRequest;
import de.dennisguse.opentracks.fragments.ChartDistanceFragment; import de.dennisguse.opentracks.fragments.ChartDistanceFragment;
import de.dennisguse.opentracks.fragments.ChartTimeFragment; import de.dennisguse.opentracks.fragments.ChartTimeFragment;
@@ -109,7 +108,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
trackController.update(isRecording(), recordingTrackPaused); trackController.update(isRecording(), recordingTrackPaused);
if (hasPhoto && photoUri != null) { if (hasPhoto && photoUri != null) {
hasPhoto = false; hasPhoto = false;
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(WaypointType.WAYPOINT, false, null, null, null, null, photoUri.toString()); WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(false, null, null, null, null, photoUri.toString());
long markerId = trackRecordingServiceConnection.addMarker(TrackDetailActivity.this, waypointCreationRequest); long markerId = trackRecordingServiceConnection.addMarker(TrackDetailActivity.this, waypointCreationRequest);
if (markerId != -1L) { if (markerId != -1L) {
//TODO: Make configurable. //TODO: Make configurable.
@@ -35,7 +35,6 @@ import java.util.NoSuchElementException;
import de.dennisguse.opentracks.BuildConfig; import de.dennisguse.opentracks.BuildConfig;
import de.dennisguse.opentracks.android.ContentResolverWrapper; import de.dennisguse.opentracks.android.ContentResolverWrapper;
import de.dennisguse.opentracks.android.IContentResolver; import de.dennisguse.opentracks.android.IContentResolver;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.stats.TripStatistics; import de.dennisguse.opentracks.stats.TripStatistics;
import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.FileUtils;
@@ -443,9 +442,6 @@ public class ContentProviderUtils {
if (!cursor.isNull(trackIdIndex)) { if (!cursor.isNull(trackIdIndex)) {
waypoint.setTrackId(cursor.getLong(trackIdIndex)); waypoint.setTrackId(cursor.getLong(trackIdIndex));
} }
if (!cursor.isNull(typeIndex)) {
waypoint.setType(WaypointType.values()[cursor.getInt(typeIndex)]);
}
if (!cursor.isNull(lengthIndex)) { if (!cursor.isNull(lengthIndex)) {
waypoint.setLength(cursor.getFloat(lengthIndex)); waypoint.setLength(cursor.getFloat(lengthIndex));
} }
@@ -539,25 +535,10 @@ public class ContentProviderUtils {
* The generator is used to update the next statistics waypoint. * The generator is used to update the next statistics waypoint.
* *
* @param waypointId the waypoint id * @param waypointId the waypoint id
* @param descriptionGenerator the description generator. Can be null for waypoint marker
*/ */
public void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator) { public void deleteWaypoint(Context context, long waypointId) {
final Waypoint waypoint = getWaypoint(waypointId); final Waypoint waypoint = getWaypoint(waypointId);
if (waypoint != null && waypoint.getType() == WaypointType.STATISTICS
&& descriptionGenerator != null) {
final Waypoint nextWaypoint = getNextStatisticsWaypointAfter(waypoint);
if (nextWaypoint == null) {
Log.d(TAG, "Unable to find the next statistics marker after deleting one.");
} else {
nextWaypoint.getTripStatistics().merge(waypoint.getTripStatistics());
nextWaypoint.setDescription(
descriptionGenerator.generateWaypointDescription(nextWaypoint.getTripStatistics()));
if (!updateWaypoint(nextWaypoint)) {
Log.e(TAG, "Unable to update the next statistics marker after deleting one.");
}
}
}
if (waypoint != null && waypoint.hasPhoto()) { if (waypoint != null && waypoint.hasPhoto()) {
Uri uri = waypoint.getPhotoURI(); Uri uri = waypoint.getPhotoURI();
File file = new File(uri.getPath()); File file = new File(uri.getPath());
@@ -596,14 +577,13 @@ public class ContentProviderUtils {
* Gets the last waypoint for a type. Returns null if it doesn't exist. * Gets the last waypoint for a type. Returns null if it doesn't exist.
* *
* @param trackId the track id * @param trackId the track id
* @param waypointType the waypoint type
*/ */
public Waypoint getLastWaypoint(long trackId, WaypointType waypointType) { public Waypoint getLastWaypoint(long trackId) {
if (trackId < 0) { if (trackId < 0) {
return null; return null;
} }
String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=?"; String selection = WaypointsColumns.TRACKID + "=?";
String[] selectionArgs = new String[]{Long.toString(trackId), Integer.toString(waypointType.ordinal())}; String[] selectionArgs = new String[]{Long.toString(trackId)};
try (Cursor cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID + " DESC", 1)) { try (Cursor cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID + " DESC", 1)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
@@ -618,20 +598,17 @@ public class ContentProviderUtils {
* Returns -1 if not able to get the next waypoint number. * Returns -1 if not able to get the next waypoint number.
* *
* @param trackId the track id * @param trackId the track id
* @param waypointType the waypoint type
*/ */
public int getNextWaypointNumber(long trackId, WaypointType waypointType) { public int getNextWaypointNumber(long trackId) {
if (trackId < 0) { if (trackId < 0) {
return -1; return -1;
} }
String[] projection = {WaypointsColumns._ID}; String[] projection = {WaypointsColumns._ID};
String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=?"; String selection = WaypointsColumns.TRACKID + "=?";
String[] selectionArgs = new String[]{Long.toString(trackId), Integer.toString(waypointType.ordinal())}; String[] selectionArgs = new String[]{Long.toString(trackId)};
try (Cursor cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, -1)) { try (Cursor cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, -1)) {
if (cursor != null) { if (cursor != null) {
int count = cursor.getCount(); return cursor.getCount();
// For statistics markers, the first marker is for the track statistics, so return the count as the next user visible number.
return waypointType == WaypointType.STATISTICS ? count : count + 1;
} }
} }
return -1; return -1;
@@ -751,7 +728,6 @@ public class ContentProviderUtils {
values.put(WaypointsColumns.CATEGORY, waypoint.getCategory()); values.put(WaypointsColumns.CATEGORY, waypoint.getCategory());
values.put(WaypointsColumns.ICON, waypoint.getIcon()); values.put(WaypointsColumns.ICON, waypoint.getIcon());
values.put(WaypointsColumns.TRACKID, waypoint.getTrackId()); values.put(WaypointsColumns.TRACKID, waypoint.getTrackId());
values.put(WaypointsColumns.TYPE, waypoint.getType().ordinal());
values.put(WaypointsColumns.LENGTH, waypoint.getLength()); values.put(WaypointsColumns.LENGTH, waypoint.getLength());
values.put(WaypointsColumns.DURATION, waypoint.getDuration()); values.put(WaypointsColumns.DURATION, waypoint.getDuration());
values.put(WaypointsColumns.STARTID, waypoint.getStartId()); values.put(WaypointsColumns.STARTID, waypoint.getStartId());
@@ -796,18 +772,6 @@ public class ContentProviderUtils {
return values; return values;
} }
private Waypoint getNextStatisticsWaypointAfter(Waypoint waypoint) {
String selection = WaypointsColumns._ID + ">? AND " + WaypointsColumns.TRACKID + "=? AND "
+ WaypointsColumns.TYPE + "=" + WaypointType.STATISTICS.ordinal();
String[] selectionArgs = new String[]{Long.toString(waypoint.getId()), Long.toString(waypoint.getTrackId())};
try (Cursor cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, 1)) {
if (cursor != null && cursor.moveToFirst()) {
return createWaypoint(cursor);
}
}
return null;
}
/** /**
* Gets a waypoint cursor. * Gets a waypoint cursor.
* *
@@ -35,7 +35,6 @@ public final class Waypoint {
private String category = ""; private String category = "";
private String icon = ""; private String icon = "";
private long trackId = -1L; private long trackId = -1L;
private WaypointType type = WaypointType.WAYPOINT;
private double length = 0.0; private double length = 0.0;
private long duration = 0; private long duration = 0;
private long startId = -1L; private long startId = -1L;
@@ -47,13 +46,12 @@ public final class Waypoint {
public Waypoint() { public Waypoint() {
} }
public Waypoint(String name, String description, String category, String icon, long trackId, WaypointType type, double length, long duration, long startId, long stopId, Location location, TripStatistics tripStatistics, String photoUrl) { public Waypoint(String name, String description, String category, String icon, long trackId, double length, long duration, long startId, long stopId, Location location, TripStatistics tripStatistics, String photoUrl) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.category = category; this.category = category;
this.icon = icon; this.icon = icon;
this.trackId = trackId; this.trackId = trackId;
this.type = type;
this.length = length; this.length = length;
this.duration = duration; this.duration = duration;
this.startId = startId; this.startId = startId;
@@ -111,14 +109,6 @@ public final class Waypoint {
this.trackId = trackId; this.trackId = trackId;
} }
public WaypointType getType() {
return type;
}
public void setType(WaypointType type) {
this.type = type;
}
public double getLength() { public double getLength() {
return length; return length;
} }
@@ -186,9 +176,4 @@ public final class Waypoint {
public boolean hasPhoto() { public boolean hasPhoto() {
return photoUrl != null && !"".equals(photoUrl); return photoUrl != null && !"".equals(photoUrl);
} }
public enum WaypointType {
WAYPOINT,
STATISTICS //Always the first waypoint; only one can exist.
}
} }
@@ -15,7 +15,6 @@
*/ */
package de.dennisguse.opentracks.content; package de.dennisguse.opentracks.content;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
/** /**
* A request for the service to create a waypoint at the current location. * A request for the service to create a waypoint at the current location.
@@ -24,12 +23,10 @@ import de.dennisguse.opentracks.content.Waypoint.WaypointType;
*/ */
public class WaypointCreationRequest { public class WaypointCreationRequest {
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false); public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(false);
@Deprecated // TODO Do not create per @Deprecated // TODO Do not create per
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true); public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(true);
private WaypointType type;
// true if this marker contains the track statistics // true if this marker contains the track statistics
private boolean isTrackStatistics; private boolean isTrackStatistics;
@@ -40,12 +37,11 @@ public class WaypointCreationRequest {
private String iconUrl; private String iconUrl;
private String photoUrl; private String photoUrl;
private WaypointCreationRequest(WaypointType type, boolean isTrackStatistics) { private WaypointCreationRequest(boolean isTrackStatistics) {
this(type, isTrackStatistics, null, null, null, null, null); this(isTrackStatistics, null, null, null, null, null);
} }
public WaypointCreationRequest(WaypointType type, boolean isTrackStatistics, String name, String category, String description, String iconUrl, String photoUrl) { public WaypointCreationRequest(boolean isTrackStatistics, String name, String category, String description, String iconUrl, String photoUrl) {
this.type = type;
this.isTrackStatistics = isTrackStatistics; this.isTrackStatistics = isTrackStatistics;
this.name = name; this.name = name;
this.category = category; this.category = category;
@@ -54,10 +50,6 @@ public class WaypointCreationRequest {
this.photoUrl = photoUrl; this.photoUrl = photoUrl;
} }
public WaypointType getType() {
return type;
}
public boolean isTrackStatistics() { public boolean isTrackStatistics() {
return isTrackStatistics; return isTrackStatistics;
} }
@@ -28,7 +28,6 @@ import androidx.fragment.app.FragmentManager;
import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.content.ContentProviderUtils; import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.DescriptionGeneratorImpl;
import de.dennisguse.opentracks.util.DialogUtils; import de.dennisguse.opentracks.util.DialogUtils;
/** /**
@@ -83,8 +82,7 @@ public class DeleteMarkerDialogFragment extends DialogFragment {
public void run() { public void run() {
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(fragmentActivity); ContentProviderUtils contentProviderUtils = new ContentProviderUtils(fragmentActivity);
for (long markerId : markerIds) { for (long markerId : markerIds) {
contentProviderUtils.deleteWaypoint(fragmentActivity, contentProviderUtils.deleteWaypoint(fragmentActivity, markerId);
markerId, new DescriptionGeneratorImpl(fragmentActivity));
} }
caller.onDeleteMarkerDone(); caller.onDeleteMarkerDone();
} }
@@ -119,12 +119,9 @@ public class GpxTrackWriter implements TrackWriter {
if (location.hasAltitude()) { if (location.hasAltitude()) {
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>"); printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
} }
printWriter.println( printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>"); printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
printWriter.println("<cmt>" + StringUtils.formatCData(waypoint.getType().name()) + "</cmt>"); printWriter.println("<desc>" + StringUtils.formatCData(waypoint.getDescription()) + "</desc>");
printWriter.println(
"<desc>" + StringUtils.formatCData(waypoint.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(waypoint.getCategory()) + "</type>"); printWriter.println("<type>" + StringUtils.formatCData(waypoint.getCategory()) + "</type>");
printWriter.println("</wpt>"); printWriter.println("</wpt>");
} }
@@ -32,7 +32,6 @@ import de.dennisguse.opentracks.content.DescriptionGeneratorImpl;
import de.dennisguse.opentracks.content.SensorDataSetLocation; import de.dennisguse.opentracks.content.SensorDataSetLocation;
import de.dennisguse.opentracks.content.Track; import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
@@ -44,7 +43,6 @@ import de.dennisguse.opentracks.util.StringUtils;
public class KmlTrackWriter implements TrackWriter { public class KmlTrackWriter implements TrackWriter {
private static final String WAYPOINT_STYLE = "waypoint"; private static final String WAYPOINT_STYLE = "waypoint";
private static final String STATISTICS_STYLE = "statistics";
private static final String START_STYLE = "start"; private static final String START_STYLE = "start";
private static final String END_STYLE = "end"; private static final String END_STYLE = "end";
private static final String TRACK_STYLE = "track"; private static final String TRACK_STYLE = "track";
@@ -55,7 +53,6 @@ public class KmlTrackWriter implements TrackWriter {
private static final String SENSOR_TYPE_POWER = "power"; private static final String SENSOR_TYPE_POWER = "power";
private static final String WAYPOINT_ICON = "http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png"; private static final String WAYPOINT_ICON = "http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png";
private static final String STATISTICS_ICON = "http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png";
private static final String START_ICON = "http://maps.google.com/mapfiles/kml/paddle/grn-circle.png"; private static final String START_ICON = "http://maps.google.com/mapfiles/kml/paddle/grn-circle.png";
private static final String END_ICON = "http://maps.google.com/mapfiles/kml/paddle/red-circle.png"; private static final String END_ICON = "http://maps.google.com/mapfiles/kml/paddle/red-circle.png";
private static final String TRACK_ICON = "http://earth.google.com/images/kml-icons/track-directional/track-0.png"; private static final String TRACK_ICON = "http://earth.google.com/images/kml-icons/track-directional/track-0.png";
@@ -125,7 +122,6 @@ public class KmlTrackWriter implements TrackWriter {
writeTrackStyle(); writeTrackStyle();
writePlacemarkerStyle(START_STYLE, START_ICON, 32, 1); writePlacemarkerStyle(START_STYLE, START_ICON, 32, 1);
writePlacemarkerStyle(END_STYLE, END_ICON, 32, 1); writePlacemarkerStyle(END_STYLE, END_ICON, 32, 1);
writePlacemarkerStyle(STATISTICS_STYLE, STATISTICS_ICON, 20, 2);
writePlacemarkerStyle(WAYPOINT_STYLE, WAYPOINT_ICON, 20, 2); writePlacemarkerStyle(WAYPOINT_STYLE, WAYPOINT_ICON, 20, 2);
printWriter.println("<Schema id=\"" + SCHEMA_ID + "\">"); printWriter.println("<Schema id=\"" + SCHEMA_ID + "\">");
@@ -167,13 +163,11 @@ public class KmlTrackWriter implements TrackWriter {
@Override @Override
public void writeWaypoint(Waypoint waypoint) { public void writeWaypoint(Waypoint waypoint) {
if (printWriter != null && exportTrackDetail) { if (printWriter != null && exportTrackDetail) {
String styleName = waypoint.getType() == WaypointType.STATISTICS ? STATISTICS_STYLE : WAYPOINT_STYLE;
if (waypoint.hasPhoto() && exportPhotos) { if (waypoint.hasPhoto() && exportPhotos) {
float heading = getHeading(waypoint.getTrackId(), waypoint.getLocation()); float heading = getHeading(waypoint.getTrackId(), waypoint.getLocation());
writePhotoOverlay(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(), styleName, waypoint.getLocation(), waypoint.getPhotoUrl(), heading); writePhotoOverlay(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(), WAYPOINT_STYLE, waypoint.getLocation(), waypoint.getPhotoUrl(), heading);
} else { } else {
writePlacemark(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(), styleName, waypoint.getLocation()); writePlacemark(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(), WAYPOINT_STYLE, waypoint.getLocation());
} }
} }
} }
@@ -44,7 +44,6 @@ import de.dennisguse.opentracks.content.LocationFactory;
import de.dennisguse.opentracks.content.LocationIterator; import de.dennisguse.opentracks.content.LocationIterator;
import de.dennisguse.opentracks.content.Track; import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.stats.TripStatistics; import de.dennisguse.opentracks.stats.TripStatistics;
import de.dennisguse.opentracks.stats.TripStatisticsUpdater; import de.dennisguse.opentracks.stats.TripStatisticsUpdater;
@@ -201,27 +200,14 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
// Valid location // Valid location
if (location.getLatitude() == waypoint.getLocation().getLatitude() && location.getLongitude() == waypoint.getLocation().getLongitude()) { if (location.getLatitude() == waypoint.getLocation().getLatitude() && location.getLongitude() == waypoint.getLocation().getLongitude()) {
// Get tripStatistics, description, and icon TripStatistics tripStatistics = null;
TripStatistics tripStatistics; String waypointDescription = waypoint.getDescription();
String waypointDescription; String icon = context.getString(R.string.marker_waypoint_icon_url);
String icon;
if (waypoint.getType() == WaypointType.STATISTICS) {
tripStatistics = markerTripStatisticsUpdater.getTripStatistics();
markerTripStatisticsUpdater = new TripStatisticsUpdater(location.getTime());
waypointDescription = new DescriptionGeneratorImpl(context).generateWaypointDescription(tripStatistics);
icon = context.getString(R.string.marker_statistics_icon_url);
} else {
tripStatistics = null;
waypointDescription = waypoint.getDescription();
icon = context.getString(R.string.marker_waypoint_icon_url);
}
// Get length and duration
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(), waypoint.getType(), length, duration, -1L, -1L, location, tripStatistics, waypoint.getPhotoUrl()); Waypoint newWaypoint = new Waypoint(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, -1L, -1L, location, tripStatistics, waypoint.getPhotoUrl());
contentProviderUtils.insertWaypoint(newWaypoint); contentProviderUtils.insertWaypoint(newWaypoint);
} }
@@ -292,10 +278,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
/** /**
* Adds a waypoint. * Adds a waypoint.
*
* @param type the waypoint type
*/ */
protected void addWaypoint(WaypointType type) throws SAXException { protected void addWaypoint() throws SAXException {
// Waypoint must have a time, else cannot match to the track points // Waypoint must have a time, else cannot match to the track points
if (time == null) { if (time == null) {
return; return;
@@ -318,7 +302,6 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
if (category != null) { if (category != null) {
waypoint.setCategory(category); waypoint.setCategory(category);
} }
waypoint.setType(type);
if (photoUrl != null) { if (photoUrl != null) {
waypoint.setPhotoUrl(photoUrl); waypoint.setPhotoUrl(photoUrl);
@@ -505,6 +488,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
* *
* @param track the track * @param track the track
*/ */
@Deprecated //TODO Store statistics for track in track rather than in waypoint.
private void insertFirstWaypoint(Track track) { private void insertFirstWaypoint(Track track) {
String waypointName = context.getString(R.string.marker_split_name_format, 0); String waypointName = context.getString(R.string.marker_split_name_format, 0);
String waypointCategory = ""; String waypointCategory = "";
@@ -517,7 +501,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
Location waypointLocation = new Location(""); Location waypointLocation = new Location("");
waypointLocation.setLatitude(100); waypointLocation.setLatitude(100);
waypointLocation.setLongitude(180); waypointLocation.setLongitude(180);
Waypoint waypoint = new Waypoint(waypointName, waypointDescription, waypointCategory, icon, track.getId(), WaypointType.STATISTICS, length, duration, -1L, -1L, waypointLocation, tripStatistics, ""); Waypoint waypoint = new Waypoint(waypointName, waypointDescription, waypointCategory, icon, track.getId(), length, duration, -1L, -1L, waypointLocation, tripStatistics, "");
contentProviderUtils.insertWaypoint(waypoint); contentProviderUtils.insertWaypoint(waypoint);
} }
@@ -25,7 +25,6 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import de.dennisguse.opentracks.content.ContentProviderUtils; import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
/** /**
* Imports a GPX file. * Imports a GPX file.
@@ -184,6 +183,6 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
* On waypoint end. * On waypoint end.
*/ */
private void onWaypointEnd() throws SAXException { private void onWaypointEnd() throws SAXException {
addWaypoint(WaypointType.STATISTICS.name().equals(waypointType) ? WaypointType.STATISTICS : WaypointType.WAYPOINT); addWaypoint();
} }
} }
@@ -30,7 +30,6 @@ import java.util.ArrayList;
import de.dennisguse.opentracks.content.ContentProviderUtils; import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.SensorDataSetLocation; import de.dennisguse.opentracks.content.SensorDataSetLocation;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.content.sensor.SensorDataSet;
/** /**
@@ -46,7 +45,6 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
private static final String HEART_RATE = "heart_rate"; private static final String HEART_RATE = "heart_rate";
private static final String POWER = "power"; private static final String POWER = "power";
private static final String STATISTICS_STYLE = "#statistics";
private static final String WAYPOINT_STYLE = "#waypoint"; private static final String WAYPOINT_STYLE = "#waypoint";
private static final String TAG_COORDINATES = "coordinates"; private static final String TAG_COORDINATES = "coordinates";
@@ -182,29 +180,16 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
* On waypoint end. * On waypoint end.
*/ */
private void onWaypointEnd() throws SAXException { private void onWaypointEnd() throws SAXException {
if (waypointType == null) { if (!WAYPOINT_STYLE.equals(waypointType)) {
return; return;
} }
// Add a waypoint if the waypointType matches
WaypointType type;
switch (waypointType) {
case WAYPOINT_STYLE:
type = WaypointType.WAYPOINT;
break;
case STATISTICS_STYLE:
type = WaypointType.STATISTICS;
break;
default:
return;
}
if (photoUrl != null) { if (photoUrl != null) {
Uri uri = Uri.parse(photoUrl); Uri uri = Uri.parse(photoUrl);
photoUrl = getPhotoUrl(uri.getLastPathSegment()); photoUrl = getPhotoUrl(uri.getLastPathSegment());
} }
addWaypoint(type); addWaypoint();
} }
/** /**
@@ -302,9 +302,9 @@ public class TrackRecordingService extends Service {
String name = waypointCreationRequest.getName(); String name = waypointCreationRequest.getName();
if (name == null) { if (name == null) {
int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId, waypointCreationRequest.getType()); int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId);
if (nextWaypointNumber == -1) { if (nextWaypointNumber == -1) {
nextWaypointNumber = 0; nextWaypointNumber = 1;
} }
name = getString(R.string.marker_name_format, nextWaypointNumber); name = getString(R.string.marker_name_format, nextWaypointNumber);
} }
@@ -335,7 +335,7 @@ public class TrackRecordingService extends Service {
String photoUrl = waypointCreationRequest.getPhotoUrl() != null ? waypointCreationRequest.getPhotoUrl() : ""; String photoUrl = waypointCreationRequest.getPhotoUrl() != null ? waypointCreationRequest.getPhotoUrl() : "";
// Insert waypoint // Insert waypoint
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointCreationRequest.getType(), length, duration, -1L, -1L, location, null, photoUrl); Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, length, duration, -1L, -1L, location, null, photoUrl);
Uri uri = contentProviderUtils.insertWaypoint(waypoint); Uri uri = contentProviderUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment()); return Long.parseLong(uri.getLastPathSegment());
} }