forked from upstream-mirrors/OpenTracks
@@ -153,25 +153,19 @@ public class CSVTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.flush();
|
printWriter.flush();
|
||||||
printWriter = null;
|
printWriter = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeHeader(List<Column> columns) {
|
public void writeHeader(List<Column> columns) {
|
||||||
if (printWriter != null) {
|
|
||||||
String columnNames = columns.stream().map(c -> c.columnName).reduce((s, s2) -> s + "," + s2).orElseThrow(() -> new RuntimeException("No columns defined"));
|
String columnNames = columns.stream().map(c -> c.columnName).reduce((s, s2) -> s + "," + s2).orElseThrow(() -> new RuntimeException("No columns defined"));
|
||||||
printWriter.println("#" + columnNames);
|
printWriter.println("#" + columnNames);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTrackPoint(List<Column> columns, TrackPoint trackPoint) {
|
public void writeTrackPoint(List<Column> columns, TrackPoint trackPoint) {
|
||||||
if (printWriter != null) {
|
|
||||||
String columnNames = columns.stream().map(c -> c.extractor.apply(trackPoint)).reduce((s, s2) -> s + "," + s2).orElseThrow(() -> new RuntimeException("No columns defined"));
|
String columnNames = columns.stream().map(c -> c.extractor.apply(trackPoint)).reduce((s, s2) -> s + "," + s2).orElseThrow(() -> new RuntimeException("No columns defined"));
|
||||||
printWriter.println(columnNames);
|
printWriter.println(columnNames);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static class Column {
|
private static class Column {
|
||||||
final String columnName;
|
final String columnName;
|
||||||
|
|||||||
@@ -199,15 +199,12 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.flush();
|
printWriter.flush();
|
||||||
printWriter = null;
|
printWriter = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void writeHeader() {
|
public void writeHeader() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
printWriter.println("<gpx");
|
printWriter.println("<gpx");
|
||||||
printWriter.println("version=\"1.1\"");
|
printWriter.println("version=\"1.1\"");
|
||||||
@@ -229,13 +226,10 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
+ " http://www.cluetrust.com/Schemas http://www.cluetrust.com/Schemas/gpxdata10.xsd"
|
+ " http://www.cluetrust.com/Schemas http://www.cluetrust.com/Schemas/gpxdata10.xsd"
|
||||||
+ " http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd\">");
|
+ " http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd\">");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeFooter() {
|
public void writeFooter() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</gpx>");
|
printWriter.println("</gpx>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeMarkers(Track track) throws InterruptedException {
|
private void writeMarkers(Track track) throws InterruptedException {
|
||||||
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId(), null, -1)) {
|
try (Cursor cursor = contentProviderUtils.getMarkerCursor(track.getId(), null, -1)) {
|
||||||
@@ -254,7 +248,6 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeMarker(ZoneOffset zoneOffset, Marker marker) {
|
public void writeMarker(ZoneOffset zoneOffset, Marker marker) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<wpt " + formatLocation(marker.getLatitude(), marker.getLongitude()) + ">");
|
printWriter.println("<wpt " + formatLocation(marker.getLatitude(), marker.getLongitude()) + ">");
|
||||||
if (marker.hasAltitude()) {
|
if (marker.hasAltitude()) {
|
||||||
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>");
|
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>");
|
||||||
@@ -265,10 +258,8 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
printWriter.println("<type>" + StringUtils.formatCData(marker.getCategory()) + "</type>");
|
printWriter.println("<type>" + StringUtils.formatCData(marker.getCategory()) + "</type>");
|
||||||
printWriter.println("</wpt>");
|
printWriter.println("</wpt>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeBeginTrack(Track track) {
|
public void writeBeginTrack(Track track) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<trk>");
|
printWriter.println("<trk>");
|
||||||
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
||||||
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
|
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
|
||||||
@@ -291,13 +282,10 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
|
|
||||||
printWriter.println("</extensions>");
|
printWriter.println("</extensions>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeEndTrack() {
|
public void writeEndTrack() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</trk>");
|
printWriter.println("</trk>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void writeOpenSegment() {
|
public void writeOpenSegment() {
|
||||||
printWriter.println("<trkseg>");
|
printWriter.println("<trkseg>");
|
||||||
@@ -310,8 +298,6 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
public Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) {
|
public Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) {
|
||||||
Distance cumulativeDistance = null;
|
Distance cumulativeDistance = null;
|
||||||
|
|
||||||
if (printWriter != null) {
|
|
||||||
|
|
||||||
printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">");
|
printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">");
|
||||||
|
|
||||||
if (trackPoint.hasAltitude()) {
|
if (trackPoint.hasAltitude()) {
|
||||||
@@ -370,7 +356,7 @@ public class GPXTrackExporter implements TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printWriter.println("</trkpt>");
|
printWriter.println("</trkpt>");
|
||||||
}
|
|
||||||
if (cumulativeDistance != null) {
|
if (cumulativeDistance != null) {
|
||||||
return cumulativeDistance;
|
return cumulativeDistance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,14 +212,11 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void close() {
|
void close() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.flush();
|
printWriter.flush();
|
||||||
printWriter = null;
|
printWriter = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeHeader(List<Track> tracks) {
|
private void writeHeader(List<Track> tracks) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println(
|
printWriter.println(
|
||||||
"""
|
"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -252,25 +249,19 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
|
|
||||||
printWriter.println("</Schema>");
|
printWriter.println("</Schema>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeFooter() {
|
private void writeFooter() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</Document>");
|
printWriter.println("</Document>");
|
||||||
printWriter.println("</kml>");
|
printWriter.println("</kml>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeBeginMarkers(Track track) {
|
private void writeBeginMarkers(Track track) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<Folder>");
|
printWriter.println("<Folder>");
|
||||||
printWriter.println("<name>" + StringUtils.formatCData(context.getString(R.string.track_markers, track.getName())) + "</name>");
|
printWriter.println("<name>" + StringUtils.formatCData(context.getString(R.string.track_markers, track.getName())) + "</name>");
|
||||||
printWriter.println("<open>1</open>");
|
printWriter.println("<open>1</open>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeMarker(Marker marker, ZoneOffset zoneOffset) {
|
private void writeMarker(Marker marker, ZoneOffset zoneOffset) {
|
||||||
if (printWriter != null) {
|
|
||||||
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, marker.getTrackId(), marker.getPhotoURI()) != null;
|
boolean existsPhoto = MarkerUtils.buildInternalPhotoFile(context, marker.getTrackId(), marker.getPhotoURI()) != null;
|
||||||
if (marker.hasPhoto() && exportPhotos && existsPhoto) {
|
if (marker.hasPhoto() && exportPhotos && existsPhoto) {
|
||||||
float heading = getHeading(marker.getTrackId(), marker.getLocation());
|
float heading = getHeading(marker.getTrackId(), marker.getLocation());
|
||||||
@@ -279,30 +270,22 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
writePlacemark(marker.getName(), marker.getCategory(), marker.getDescription(), marker.getLocation(), zoneOffset);
|
writePlacemark(marker.getName(), marker.getCategory(), marker.getDescription(), marker.getLocation(), zoneOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeEndMarkers() {
|
private void writeEndMarkers() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</Folder>");
|
printWriter.println("</Folder>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeMultiTrackBegin() {
|
private void writeMultiTrackBegin() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<Folder id=\"tracks\">");
|
printWriter.println("<Folder id=\"tracks\">");
|
||||||
printWriter.println("<name>" + context.getString(R.string.generic_tracks) + "</name>");
|
printWriter.println("<name>" + context.getString(R.string.generic_tracks) + "</name>");
|
||||||
printWriter.println("<open>1</open>");
|
printWriter.println("<open>1</open>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeMultiTrackEnd() {
|
private void writeMultiTrackEnd() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</Folder>");
|
printWriter.println("</Folder>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeBeginTrack(Track track) {
|
private void writeBeginTrack(Track track) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<Placemark>");
|
printWriter.println("<Placemark>");
|
||||||
|
|
||||||
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
|
||||||
@@ -316,19 +299,15 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
printWriter.println("<altitudeMode>absolute</altitudeMode>");
|
printWriter.println("<altitudeMode>absolute</altitudeMode>");
|
||||||
printWriter.println("<interpolate>1</interpolate>");
|
printWriter.println("<interpolate>1</interpolate>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void writeEndTrack() {
|
private void writeEndTrack() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("</MultiTrack>");
|
printWriter.println("</MultiTrack>");
|
||||||
printWriter.println("</Placemark>");
|
printWriter.println("</Placemark>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void writeOpenSegment() {
|
void writeOpenSegment() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<Track>");
|
printWriter.println("<Track>");
|
||||||
speedList.clear();
|
speedList.clear();
|
||||||
distanceList.clear();
|
distanceList.clear();
|
||||||
@@ -340,11 +319,9 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
accuracyHorizontal.clear();
|
accuracyHorizontal.clear();
|
||||||
accuracyVertical.clear();
|
accuracyVertical.clear();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void writeCloseSegment() {
|
void writeCloseSegment() {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<ExtendedData>");
|
printWriter.println("<ExtendedData>");
|
||||||
printWriter.println("<SchemaData schemaUrl=\"#" + SCHEMA_ID + "\">");
|
printWriter.println("<SchemaData schemaUrl=\"#" + SCHEMA_ID + "\">");
|
||||||
if (speedList.stream().anyMatch(Objects::nonNull)) {
|
if (speedList.stream().anyMatch(Objects::nonNull)) {
|
||||||
@@ -378,11 +355,9 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
printWriter.println("</ExtendedData>");
|
printWriter.println("</ExtendedData>");
|
||||||
printWriter.println("</Track>");
|
printWriter.println("</Track>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint) {
|
void writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint) {
|
||||||
if (printWriter != null) {
|
|
||||||
printWriter.println("<when>" + getTime(zoneOffset, trackPoint.getLocation()) + "</when>");
|
printWriter.println("<when>" + getTime(zoneOffset, trackPoint.getLocation()) + "</when>");
|
||||||
|
|
||||||
if (trackPoint.hasLocation()) {
|
if (trackPoint.hasLocation()) {
|
||||||
@@ -402,7 +377,6 @@ public class KMLTrackExporter implements TrackExporter {
|
|||||||
accuracyHorizontal.add(trackPoint.hasHorizontalAccuracy() ? (float) trackPoint.getHorizontalAccuracy().toM() : null);
|
accuracyHorizontal.add(trackPoint.hasHorizontalAccuracy() ? (float) trackPoint.getHorizontalAccuracy().toM() : null);
|
||||||
accuracyVertical.add(trackPoint.hasVerticalAccuracy() ? (float) trackPoint.getVerticalAccuracy().toM() : null);
|
accuracyVertical.add(trackPoint.hasVerticalAccuracy() ? (float) trackPoint.getVerticalAccuracy().toM() : null);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the simple array data.
|
* Writes the simple array data.
|
||||||
|
|||||||
Reference in New Issue
Block a user