move condition for writing multitrack begin and end outside of methods

This commit is contained in:
thrillfall
2020-08-11 13:51:19 +02:00
committed by Dennis Guse
parent 2655d3e773
commit 80208e3188
5 changed files with 26 additions and 26 deletions
@@ -22,7 +22,7 @@ public enum TrackFileFormat {
KML_ONLY_TRACK { KML_ONLY_TRACK {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, false, false, false); return new KmlTrackWriter(context,false, false, false);
} }
@Override @Override
@@ -37,7 +37,7 @@ public enum TrackFileFormat {
KML_WITH_TRACKDETAIL { KML_WITH_TRACKDETAIL {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, false, false); return new KmlTrackWriter(context,true, false, false);
} }
@Override @Override
@@ -52,7 +52,7 @@ public enum TrackFileFormat {
KML_WITH_TRACKDETAIL_AND_SENSORDATA { KML_WITH_TRACKDETAIL_AND_SENSORDATA {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, false); return new KmlTrackWriter(context,true, true, false);
} }
@Override @Override
@@ -70,7 +70,7 @@ public enum TrackFileFormat {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, false, false, exportPhotos); return new KmlTrackWriter(context,false, false, exportPhotos);
} }
public TrackExporter newTrackExporter(Context context, Track[] tracks) { public TrackExporter newTrackExporter(Context context, Track[] tracks) {
@@ -97,7 +97,7 @@ public enum TrackFileFormat {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, false, exportPhotos); return new KmlTrackWriter(context,true, false, exportPhotos);
} }
public TrackExporter newTrackExporter(Context context, Track[] tracks) { public TrackExporter newTrackExporter(Context context, Track[] tracks) {
@@ -125,7 +125,7 @@ public enum TrackFileFormat {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, exportPhotos); return new KmlTrackWriter(context,true, true, exportPhotos);
} }
@Override @Override
@@ -154,7 +154,7 @@ public enum TrackFileFormat {
@Override @Override
public TrackWriter newTrackWriter(Context context, boolean multiple) { public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, exportPhotos); return new KmlTrackWriter(context,true, true, exportPhotos);
} }
@Override @Override
@@ -201,7 +201,7 @@ public enum TrackFileFormat {
FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter, tracks); FileTrackExporter fileTrackExporter = new FileTrackExporter(contentProviderUtils, trackWriter, tracks);
return new KmzTrackExporter(context, contentProviderUtils, fileTrackExporter, tracks, exportPhotos); return new KmzTrackExporter(context, contentProviderUtils, fileTrackExporter, exportPhotos);
} }
/** /**
@@ -66,13 +66,18 @@ public class FileTrackExporter implements TrackExporter {
for (Track track1 : tracks) { for (Track track1 : tracks) {
writeWaypoints(track1); writeWaypoints(track1);
} }
trackWriter.writeBeginTracks(); boolean hasMultipleTracks = tracks.length > 1;
if (hasMultipleTracks) {
trackWriter.writeMultiTrackBegin();
}
long startTime = tracks[0].getTrackStatistics().getStartTime_ms(); long startTime = tracks[0].getTrackStatistics().getStartTime_ms();
for (Track track : tracks) { for (Track track : tracks) {
long offset = track.getTrackStatistics().getStartTime_ms() - startTime; long offset = track.getTrackStatistics().getStartTime_ms() - startTime;
writeLocations(track, offset); writeLocations(track, offset);
} }
trackWriter.writeEndTracks(); if (hasMultipleTracks) {
trackWriter.writeMultiTrackEnd();
}
trackWriter.writeFooter(); trackWriter.writeFooter();
trackWriter.close(); trackWriter.close();
@@ -146,12 +146,12 @@ public class GpxTrackWriter implements TrackWriter {
} }
@Override @Override
public void writeBeginTracks() { public void writeMultiTrackBegin() {
// Do nothing // Do nothing
} }
@Override @Override
public void writeEndTracks() { public void writeMultiTrackEnd() {
// Do nothing // Do nothing
} }
@@ -57,7 +57,6 @@ public class KmlTrackWriter implements TrackWriter {
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";
private final Context context; private final Context context;
private final boolean hasMultipleTracks;
private final boolean exportPhotos; private final boolean exportPhotos;
private final boolean exportTrackDetail; private final boolean exportTrackDetail;
private final boolean exportSensorData; private final boolean exportSensorData;
@@ -74,14 +73,12 @@ public class KmlTrackWriter implements TrackWriter {
/** /**
* @param context the context * @param context the context
* @param hasMultipleTracks should encode multiple tracks into one file?
* @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, waypoints, timing)?
* @param exportSensorData should {@link TrackPoint}'s sensor data be exported? * @param exportSensorData should {@link TrackPoint}'s sensor data be exported?
* @param exportPhotos should pictures be exported (if true: exports to KMZ)? * @param exportPhotos should pictures be exported (if true: exports to KMZ)?
*/ */
public KmlTrackWriter(Context context, boolean hasMultipleTracks, boolean exportTrackDetail, boolean exportSensorData, boolean exportPhotos) { public KmlTrackWriter(Context context, boolean exportTrackDetail, boolean exportSensorData, boolean exportPhotos) {
this.context = context; this.context = context;
this.hasMultipleTracks = hasMultipleTracks;
this.exportTrackDetail = exportTrackDetail; this.exportTrackDetail = exportTrackDetail;
this.exportSensorData = exportSensorData; this.exportSensorData = exportSensorData;
this.exportPhotos = exportPhotos; this.exportPhotos = exportPhotos;
@@ -178,18 +175,16 @@ public class KmlTrackWriter implements TrackWriter {
} }
} }
@Override public void writeMultiTrackBegin() {
public void writeBeginTracks() { if (printWriter != null) {
if (printWriter != null && hasMultipleTracks) {
printWriter.println("<Folder id=tour>"); printWriter.println("<Folder id=tour>");
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>");
} }
} }
@Override public void writeMultiTrackEnd() {
public void writeEndTracks() { if (printWriter != null) {
if (printWriter != null && hasMultipleTracks) {
printWriter.println("</Folder>"); printWriter.println("</Folder>");
} }
} }
@@ -32,7 +32,7 @@ import de.dennisguse.opentracks.content.data.Waypoint;
* For each waypoint: * For each waypoint:
* {@link #writeWaypoint(Waypoint)} * {@link #writeWaypoint(Waypoint)}
* {@link #writeEndWaypoints()} * {@link #writeEndWaypoints()}
* {@link #writeBeginTracks()} * {@link #writeMultiTrackBegin()}
* For each track: * For each track:
* {@link #writeBeginTrack(Track, TrackPoint)} * {@link #writeBeginTrack(Track, TrackPoint)}
* For each segment: * For each segment:
@@ -41,7 +41,7 @@ import de.dennisguse.opentracks.content.data.Waypoint;
* {@link #writeTrackPoint(TrackPoint)} * {@link #writeTrackPoint(TrackPoint)}
* {@link #writeCloseSegment()} * {@link #writeCloseSegment()}
* {@link #writeEndTrack(Track, TrackPoint)} * {@link #writeEndTrack(Track, TrackPoint)}
* {@link #writeEndTracks()} * {@link #writeMultiTrackEnd()}
* {@link #writeFooter()} * {@link #writeFooter()}
* {@link #close()} * {@link #close()}
* </pre> * </pre>
@@ -96,12 +96,12 @@ public interface TrackWriter {
/** /**
* Writes the beginning of the tracks. * Writes the beginning of the tracks.
*/ */
void writeBeginTracks(); void writeMultiTrackBegin();
/** /**
* Writes the end of the tracks, * Writes the end of the tracks,
*/ */
void writeEndTracks(); void writeMultiTrackEnd();
/** /**
* Writes the beginning of a track. * Writes the beginning of a track.