Refactor: use marker instead of waypoint.

Fixes #389.
This commit is contained in:
Dennis Guse
2020-09-23 17:16:34 +02:00
parent 8643b50bd1
commit e939778beb
29 changed files with 349 additions and 472 deletions
@@ -64,8 +64,8 @@ public class FileTrackExporter implements TrackExporter {
try {
trackWriter.prepare(outputStream);
trackWriter.writeHeader(tracks);
for (Track track1 : tracks) {
writeWaypoints(track1);
for (Track track : tracks) {
writeMarkers(track);
}
boolean hasMultipleTracks = tracks.length > 1;
if (hasMultipleTracks) {
@@ -89,34 +89,31 @@ public class FileTrackExporter implements TrackExporter {
}
}
/**
* Writes the waypoints.
*/
private void writeWaypoints(Track track) throws InterruptedException {
private void writeMarkers(Track track) throws InterruptedException {
/*
* TODO: Stream through the waypoints in chunks.
* I am leaving the number of waypoints very high which should not be a problem, because we don't try to load them into objects all at the same time.
* TODO: Stream through the markers in chunks.
* I am leaving the number of markers very high which should not be a problem, because we don't try to load them into objects all at the same time.
*/
boolean hasWaypoints = false;
boolean hasMarkers = false;
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId(), null, ContentProviderUtils.MAX_LOADED_MARKERS)) {
if (cursor != null && cursor.moveToFirst()) {
for (int i = 0; i < cursor.getCount(); i++) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
if (!hasWaypoints) {
trackWriter.writeBeginWaypoints(track);
hasWaypoints = true;
if (!hasMarkers) {
trackWriter.writeBeginMarkers(track);
hasMarkers = true;
}
Marker waypoint = contentProviderUtils.createMarker(cursor);
trackWriter.writeWaypoint(waypoint);
Marker marker = contentProviderUtils.createMarker(cursor);
trackWriter.writeMarker(marker);
cursor.moveToNext();
}
}
}
if (hasWaypoints) {
trackWriter.writeEndWaypoints();
if (hasMarkers) {
trackWriter.writeEndMarkers();
}
}
@@ -33,7 +33,7 @@ import de.dennisguse.opentracks.util.StringUtils;
*
* @author Sandor Dornbush
*/
//TODO Export waypoints
//TODO Export markers
public class GpxTrackWriter implements TrackWriter {
private static final NumberFormat ELEVATION_FORMAT = NumberFormat.getInstance(Locale.US);
@@ -120,27 +120,27 @@ public class GpxTrackWriter implements TrackWriter {
}
@Override
public void writeBeginWaypoints(Track track) {
public void writeBeginMarkers(Track track) {
// Do nothing
}
@Override
public void writeEndWaypoints() {
public void writeEndMarkers() {
// Do nothing
}
@Override
public void writeWaypoint(Marker waypoint) {
public void writeMarker(Marker marker) {
if (printWriter != null) {
Location location = waypoint.getLocation();
Location location = marker.getLocation();
printWriter.println("<wpt " + formatLocation(location) + ">");
if (location.hasAltitude()) {
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
}
printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(waypoint.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(waypoint.getCategory()) + "</type>");
printWriter.println("<name>" + StringUtils.formatCData(marker.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(marker.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(marker.getCategory()) + "</type>");
printWriter.println("</wpt>");
}
}
@@ -40,7 +40,7 @@ import de.dennisguse.opentracks.util.StringUtils;
*/
public class KmlTrackWriter implements TrackWriter {
public static final String WAYPOINT_STYLE = "waypoint";
public static final String MARKER_STYLE = "waypoint";
private static final String START_STYLE = "start";
private static final String END_STYLE = "end";
private static final String TRACK_STYLE = "track";
@@ -52,7 +52,7 @@ public class KmlTrackWriter implements TrackWriter {
public static final String EXTENDED_DATA_TYPE_POWER = "power";
public static final String EXTENDED_DATA_TYPE_ELEVATION_GAIN = "elevation_gain";
private static final String WAYPOINT_ICON = "http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png";
private static final String MARKER_ICON = "http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.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 TRACK_ICON = "http://earth.google.com/images/kml-icons/track-directional/track-0.png";
@@ -75,7 +75,7 @@ public class KmlTrackWriter implements TrackWriter {
/**
* @param context the context
* @param exportTrackDetail should detailed information about the track be exported (e.g., title, description, waypoints, timing)?
* @param exportTrackDetail should detailed information about the track be exported (e.g., title, description, markers, timing)?
* @param exportSensorData should {@link TrackPoint}'s sensor data be exported?
* @param exportPhotos should pictures be exported (if true: exports to KMZ)?
*/
@@ -124,7 +124,7 @@ public class KmlTrackWriter implements TrackWriter {
writeTrackStyle();
writePlacemarkerStyle(START_STYLE, START_ICON, 32, 1);
writePlacemarkerStyle(END_STYLE, END_ICON, 32, 1);
writePlacemarkerStyle(WAYPOINT_STYLE, WAYPOINT_ICON, 20, 2);
writePlacemarkerStyle(MARKER_STYLE, MARKER_ICON, 20, 2);
printWriter.println("<Schema id=\"" + SCHEMA_ID + "\">");
writeSimpleArrayStyle(EXTENDED_DATA_TYPE_SPEED, context.getString(R.string.description_speed_ms));
@@ -147,7 +147,7 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeBeginWaypoints(Track track) {
public void writeBeginMarkers(Track track) {
if (printWriter != null) {
printWriter.println("<Folder>");
if (exportTrackDetail) {
@@ -158,21 +158,21 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeEndWaypoints() {
public void writeEndMarkers() {
if (printWriter != null) {
printWriter.println("</Folder>");
}
}
@Override
public void writeWaypoint(Marker waypoint) {
public void writeMarker(Marker marker) {
if (printWriter != null && exportTrackDetail) {
boolean existsPhoto = FileUtils.getPhotoFileIfExists(context, waypoint.getTrackId(), waypoint.getPhotoURI()) != null;
if (waypoint.hasPhoto() && exportPhotos && existsPhoto) {
float heading = getHeading(waypoint.getTrackId(), waypoint.getLocation());
writePhotoOverlay(waypoint, heading);
boolean existsPhoto = FileUtils.getPhotoFileIfExists(context, marker.getTrackId(), marker.getPhotoURI()) != null;
if (marker.hasPhoto() && exportPhotos && existsPhoto) {
float heading = getHeading(marker.getTrackId(), marker.getLocation());
writePhotoOverlay(marker, heading);
} else {
writePlacemark(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(), WAYPOINT_STYLE, waypoint.getLocation());
writePlacemark(marker.getName(), marker.getCategory(), marker.getDescription(), MARKER_STYLE, marker.getLocation());
}
}
}
@@ -337,30 +337,24 @@ public class KmlTrackWriter implements TrackWriter {
}
}
/**
* Writes a photo overlay from waypoint.
*
* @param waypoint Waypoint object.
* @param heading the heading.
*/
private void writePhotoOverlay(Marker waypoint, float heading) {
private void writePhotoOverlay(Marker marker, float heading) {
if (exportTrackDetail) {
printWriter.println("<PhotoOverlay>");
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
printWriter.println("<description>" + StringUtils.formatCData(waypoint.getDescription()) + "</description>");
printWriter.println("<name>" + StringUtils.formatCData(marker.getName()) + "</name>");
printWriter.println("<description>" + StringUtils.formatCData(marker.getDescription()) + "</description>");
printWriter.print("<Camera>");
printWriter.print("<longitude>" + waypoint.getLocation().getLongitude() + "</longitude>");
printWriter.print("<latitude>" + waypoint.getLocation().getLatitude() + "</latitude>");
printWriter.print("<longitude>" + marker.getLocation().getLongitude() + "</longitude>");
printWriter.print("<latitude>" + marker.getLocation().getLatitude() + "</latitude>");
printWriter.print("<altitude>20</altitude>");
printWriter.print("<heading>" + heading + "</heading>");
printWriter.print("<tilt>90</tilt>");
printWriter.println("</Camera>");
printWriter.println("<TimeStamp><when>" + getTime(waypoint.getLocation()) + "</when></TimeStamp>");
printWriter.println("<styleUrl>#" + KmlTrackWriter.WAYPOINT_STYLE + "</styleUrl>");
writeCategory(waypoint.getCategory());
printWriter.println("<TimeStamp><when>" + getTime(marker.getLocation()) + "</when></TimeStamp>");
printWriter.println("<styleUrl>#" + KmlTrackWriter.MARKER_STYLE + "</styleUrl>");
writeCategory(marker.getCategory());
if (exportPhotos) {
printWriter.println("<Icon><href>" + KmzTrackExporter.buildKmzImageFilePath(waypoint) + "</href></Icon>");
printWriter.println("<Icon><href>" + KmzTrackExporter.buildKmzImageFilePath(marker) + "</href></Icon>");
}
printWriter.print("<ViewVolume>");
@@ -371,7 +365,7 @@ public class KmlTrackWriter implements TrackWriter {
printWriter.print("<topFov>45</topFov>");
printWriter.println("</ViewVolume>");
printWriter.println("<Point>");
printWriter.println("<coordinates>" + getCoordinates(waypoint.getLocation(), ",") + "</coordinates>");
printWriter.println("<coordinates>" + getCoordinates(marker.getLocation(), ",") + "</coordinates>");
printWriter.println("</Point>");
printWriter.println("</PhotoOverlay>");
}
@@ -105,12 +105,12 @@ public class KmzTrackExporter implements TrackExporter {
if (Thread.interrupted()) {
throw new InterruptedException();
}
Marker waypoint = contentProviderUtils.createMarker(cursor);
if (waypoint.hasPhoto()) {
Uri uriPhoto = waypoint.getPhotoURI();
Marker marker = contentProviderUtils.createMarker(cursor);
if (marker.hasPhoto()) {
Uri uriPhoto = marker.getPhotoURI();
boolean existsPhoto = FileUtils.getPhotoFileIfExists(context, track.getId(), uriPhoto) != null;
if (existsPhoto) {
addImage(context, zipOutputStream, uriPhoto, waypoint);
addImage(context, zipOutputStream, uriPhoto, marker);
}
}
@@ -121,9 +121,9 @@ public class KmzTrackExporter implements TrackExporter {
}
}
private void addImage(Context context, ZipOutputStream zipOutputStream, Uri uri, Marker waypoint) throws IOException {
private void addImage(Context context, ZipOutputStream zipOutputStream, Uri uri, Marker marker) throws IOException {
try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
ZipEntry zipEntry = new ZipEntry(buildKmzImageFilePath(waypoint));
ZipEntry zipEntry = new ZipEntry(buildKmzImageFilePath(marker));
zipOutputStream.putNextEntry(zipEntry);
if (inputStream == null) throw new FileNotFoundException();
@@ -146,13 +146,11 @@ public class KmzTrackExporter implements TrackExporter {
}
/**
* Builds and returns the path for the image that will be saved inside KMZ_IMAGES_DIR for the waypoint.
*
* @param waypoint Waypoint object.
* Builds and returns the path for the image that will be saved inside KMZ_IMAGES_DIR for the marker.
*/
public static String buildKmzImageFilePath(Marker waypoint) {
String ext = FileUtils.getExtension(waypoint.getPhotoUrl());
public static String buildKmzImageFilePath(Marker marker) {
String ext = FileUtils.getExtension(marker.getPhotoUrl());
ext = ext == null ? "" : "." + ext;
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(waypoint.getId().getId() + ext);
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(marker.getId().getId() + ext);
}
}
@@ -28,10 +28,10 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
* {@link #prepare(OutputStream)}
* {@link #writeHeader(Track[])}
* For each track:
* {@link #writeBeginWaypoints(Track)}
* For each waypoint:
* {@link #writeWaypoint(Marker)}
* {@link #writeEndWaypoints()}
* {@link #writeBeginMarkers(Track)}
* For each marker:
* {@link #writeMarker(Marker)}
* {@link #writeEndMarkers()}
* {@link #writeMultiTrackBegin()}
* For each track:
* {@link #writeBeginTrack(Track, TrackPoint)}
@@ -50,11 +50,6 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
*/
public interface TrackWriter {
/**
* Prepares the output stream.
*
* @param outputStream the output stream
*/
void prepare(OutputStream outputStream);
/**
@@ -62,77 +57,27 @@ public interface TrackWriter {
*/
void close();
/**
* Writes the header
*
* @param tracks the tracks
*/
void writeHeader(Track[] tracks);
/**
* Writes the footer.
*/
void writeFooter();
/**
* Writes the beginning of the waypoints.
*
* @param track the track
*/
void writeBeginWaypoints(Track track);
void writeBeginMarkers(Track track);
/**
* Writes the end of the waypoints.
*/
void writeEndWaypoints();
void writeEndMarkers();
/**
* Writes a waypoint.
*
* @param waypoint the waypoint
*/
void writeWaypoint(Marker waypoint);
void writeMarker(Marker marker);
/**
* Writes the beginning of the tracks.
*/
void writeMultiTrackBegin();
/**
* Writes the end of the tracks,
*/
void writeMultiTrackEnd();
/**
* Writes the beginning of a track.
*
* @param track the track
* @param startTrackPoint the start location
*/
void writeBeginTrack(Track track, TrackPoint startTrackPoint);
/**
* Writes the end of a track.
*
* @param track the track
* @param endTrackPoint the end location
*/
void writeEndTrack(Track track, TrackPoint endTrackPoint);
/**
* Writes open segment.
*/
void writeOpenSegment();
/**
* Writes close segment.
*/
void writeCloseSegment();
/**
* Writes a trackPoint.
*
* @param trackPoint the trackPoint
*/
void writeTrackPoint(TrackPoint trackPoint);
}
@@ -70,7 +70,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
private Track.Id importTrackId;
private final List<Track.Id> trackIds = new ArrayList<>();
private final List<Marker> waypoints = new ArrayList<>();
private final List<Marker> markers = new ArrayList<>();
// The current element content
//TODO Should be made private and getter be used by child classes.
@@ -88,7 +88,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
protected String heartrate;
protected String cadence;
protected String power;
protected String waypointType;
protected String markerType;
protected String photoUrl;
protected String uuid;
@@ -148,7 +148,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
* On file end.
*/
protected void onFileEnd() {
// Add waypoints to the last imported track
// Add markers to the last imported track
int size = trackIds.size();
if (size == 0) {
return;
@@ -159,8 +159,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
return;
}
int waypointPosition = -1;
Marker waypoint = null;
int markerPosition = -1;
Marker marker = null;
TrackPoint trackPoint = null;
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics().getStartTime_ms());
// TODO Should not be necessary anymore?
@@ -169,18 +169,18 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false)) {
while (true) {
if (waypoint == null) {
waypointPosition++;
waypoint = waypointPosition < waypoints.size() ? waypoints.get(waypointPosition) : null;
if (waypoint == null) {
// No more waypoints
if (marker == null) {
markerPosition++;
marker = markerPosition < markers.size() ? markers.get(markerPosition) : null;
if (marker == null) {
// No more markers
return;
}
}
if (trackPoint == null) {
if (!trackPointIterator.hasNext()) {
// No more track points. Ignore the rest of the waypoints.
// No more track points. Ignore the rest of the markers.
return;
}
trackPoint = trackPointIterator.next();
@@ -188,13 +188,13 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
markerTrackStatisticsUpdater.addTrackPoint(trackPoint, recordingDistanceInterval);
}
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
if (marker.getLocation().getTime() > trackPoint.getTime()) {
trackPoint = null;
} else if (waypoint.getLocation().getTime() < trackPoint.getTime()) {
Log.w(TAG, "Ignoring waypoint: current trackPoint was after waypoint.");
waypoint = null;
} else if (marker.getLocation().getTime() < trackPoint.getTime()) {
Log.w(TAG, "Ignoring marker: current trackPoint was after marker.");
marker = null;
} else {
// The waypoint trackPoint time matches the track point time
// The marker trackPoint time matches the track point time
if (!LocationUtils.isValidLocation(trackPoint.getLocation())) {
// Invalid trackPoint, load the next trackPoint
trackPoint = null;
@@ -202,19 +202,19 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
}
// Valid trackPoint
if (trackPoint.getLatitude() == waypoint.getLocation().getLatitude() && trackPoint.getLongitude() == waypoint.getLocation().getLongitude()) {
String waypointDescription = waypoint.getDescription();
String icon = context.getString(R.string.marker_waypoint_icon_url);
if (trackPoint.getLatitude() == marker.getLocation().getLatitude() && trackPoint.getLongitude() == marker.getLocation().getLongitude()) {
String markerDescription = marker.getDescription();
String icon = context.getString(R.string.marker_icon_url);
double length = trackStatisticsUpdater.getTrackStatistics().getTotalDistance();
long duration = trackStatisticsUpdater.getTrackStatistics().getTotalTime();
// Insert waypoint
Marker newWaypoint = new Marker(waypoint.getName(), waypointDescription, waypoint.getCategory(), icon, track.getId(), length, duration, trackPoint.getLocation(), waypoint.getPhotoUrl());
contentProviderUtils.insertMarker(newWaypoint);
// Insert marker
Marker newMarker = new Marker(marker.getName(), markerDescription, marker.getCategory(), icon, track.getId(), length, duration, trackPoint.getLocation(), marker.getPhotoUrl());
contentProviderUtils.insertMarker(newMarker);
}
// Load the next waypoint
waypoint = null;
// Load the next marker
marker = null;
}
}
}
@@ -300,11 +300,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
trackData.lastLocationInCurrentSegment = null;
}
/**
* Adds a waypoint.
*/
protected void addWaypoint() throws SAXException {
// Waypoint must have a time, else cannot match to the track points
protected void addMarker() throws SAXException {
// Markers must have a time, else cannot match to the track points
if (time == null) {
return;
}
@@ -314,22 +311,22 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
if (!LocationUtils.isValidLocation(trackPoint.getLocation())) {
throw new SAXException(createErrorMessage("Invalid location detected: " + trackPoint));
}
Marker waypoint = new Marker(trackPoint.getLocation());
Marker marker = new Marker(trackPoint.getLocation());
if (name != null) {
waypoint.setName(name);
marker.setName(name);
}
if (description != null) {
waypoint.setDescription(description);
marker.setDescription(description);
}
if (category != null) {
waypoint.setCategory(category);
marker.setCategory(category);
}
if (photoUrl != null) {
waypoint.setPhotoUrl(photoUrl);
marker.setPhotoUrl(photoUrl);
}
waypoints.add(waypoint);
markers.add(marker);
}
/**
@@ -44,7 +44,7 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
private static final String TAG_TRACK_POINT = "trkpt";
private static final String TAG_TRACK_SEGMENT = "trkseg";
private static final String TAG_TYPE = "type";
private static final String TAG_WAYPOINT = "wpt";
private static final String TAG_MARKER = "wpt";
private static final String TAG_ID = "opentracks:trackid";
private static final String ATTRIBUTE_LAT = "lat";
@@ -71,8 +71,8 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
@Override
public void startElement(String uri, String localName, String tag, Attributes attributes) throws SAXException {
switch (tag) {
case TAG_WAYPOINT:
onWaypointStart(attributes);
case TAG_MARKER:
onMarkerStart(attributes);
break;
case TAG_TRACK:
onTrackStart();
@@ -92,8 +92,8 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
case TAG_GPX:
onFileEnd();
break;
case TAG_WAYPOINT:
onWaypointEnd();
case TAG_MARKER:
onMarkerEnd();
break;
case TAG_TRACK:
onTrackEnd();
@@ -128,7 +128,7 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
break;
case TAG_COMMENT:
if (content != null) {
waypointType = content.trim();
markerType = content.trim();
}
break;
case TAG_EXTENSION_SPEED:
@@ -187,12 +187,7 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
insertTrackPoint(trackPoint);
}
/**
* On waypoint start.
*
* @param attributes the attributes
*/
private void onWaypointStart(Attributes attributes) {
private void onMarkerStart(Attributes attributes) {
name = null;
description = null;
category = null;
@@ -201,13 +196,10 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
longitude = attributes.getValue(ATTRIBUTE_LON);
altitude = null;
time = null;
waypointType = null;
markerType = null;
}
/**
* On waypoint end.
*/
private void onWaypointEnd() throws SAXException {
addWaypoint();
private void onMarkerEnd() throws SAXException {
addMarker();
}
}
@@ -39,7 +39,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
private static final String TAG = KmlFileTrackImporter.class.getSimpleName();
private static final String WAYPOINT_STYLE = "#" + KmlTrackWriter.WAYPOINT_STYLE;
private static final String MARKER_STYLE = "#" + KmlTrackWriter.MARKER_STYLE;
private static final String TAG_COORDINATES = "coordinates";
private static final String TAG_DESCRIPTION = "description";
@@ -84,8 +84,8 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
switch (tag) {
case TAG_PLACEMARK:
case TAG_PHOTO_OVERLAY:
// Note that a track is contained in a Placemark, calling onWaypointStart will clear various track variables like name, category, and description.
onWaypointStart();
// Note that a track is contained in a Placemark, calling onMarkerStart will clear various track variables like name, category, and description.
onMarkerStart();
break;
case TAG_GX_MULTI_TRACK:
trackStarted = true;
@@ -111,11 +111,11 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
break;
case TAG_PLACEMARK:
case TAG_PHOTO_OVERLAY:
// Note that a track is contained in a Placemark, calling onWaypointend is save since waypointType is not set for a track.
onWaypointEnd();
// Note that a track is contained in a Placemark, calling onMarkerEnd is save since markerType is not set for a track.
onMarkerEnd();
break;
case TAG_COORDINATES:
onWaypointLocationEnd();
onMarkerLocationEnd();
break;
case TAG_GX_MULTI_TRACK:
onTrackEnd();
@@ -161,7 +161,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
break;
case TAG_STYLE_URL:
if (content != null) {
waypointType = content.trim();
markerType = content.trim();
}
break;
case TAG_HREF:
@@ -175,10 +175,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
content = null;
}
/**
* On waypoint start.
*/
private void onWaypointStart() {
private void onMarkerStart() {
// Reset all Placemark variables
name = null;
icon = null;
@@ -189,27 +186,21 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
longitude = null;
altitude = null;
time = null;
waypointType = null;
markerType = null;
}
/**
* On waypoint end.
*/
private void onWaypointEnd() throws SAXException {
if (!WAYPOINT_STYLE.equals(waypointType)) {
private void onMarkerEnd() throws SAXException {
if (!MARKER_STYLE.equals(markerType)) {
return;
}
// If there is photoUrl it has to be changed because that url in kml file is a relative path to the internal kmz file.
photoUrl = getInternalPhotoUrl(photoUrl);
addWaypoint();
addMarker();
}
/**
* On waypoint location end.
*/
private void onWaypointLocationEnd() {
private void onMarkerLocationEnd() {
if (content != null) {
String[] parts = content.trim().split(",");
if (parts.length != 2 && parts.length != 3) {
@@ -191,20 +191,20 @@ public class KmzTrackImporter implements TrackImporter {
}
/**
* Deletes all images that remained in external storage that doesn't have waypoint (marker) associated.
* Deletes all images that remained in external storage that doesn't have a marker associated.
*
* @param context the Context object.
* @param trackId the id of the Track.
*/
private void deleteOrphanImages(Context context, Track.Id trackId) {
if (!trackId.isValid()) {
// 1.- Gets all photo names in the waypoints of the track identified by id.
// 1.- Gets all photo names in the markers of the track identified by id.
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
List<Marker> waypoints = contentProviderUtils.getMarkers(trackId);
List<Marker> markers = contentProviderUtils.getMarkers(trackId);
List<String> photosName = new ArrayList<>();
for (Marker w : waypoints) {
if (w.hasPhoto()) {
String photoUrl = Uri.decode(w.getPhotoUrl());
for (Marker marker : markers) {
if (marker.hasPhoto()) {
String photoUrl = Uri.decode(marker.getPhotoUrl());
photosName.add(photoUrl.substring(photoUrl.lastIndexOf(File.separatorChar) + 1));
}
}