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 {
@Override
public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, false, false, false);
return new KmlTrackWriter(context,false, false, false);
}
@Override
@@ -37,7 +37,7 @@ public enum TrackFileFormat {
KML_WITH_TRACKDETAIL {
@Override
public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, false, false);
return new KmlTrackWriter(context,true, false, false);
}
@Override
@@ -52,7 +52,7 @@ public enum TrackFileFormat {
KML_WITH_TRACKDETAIL_AND_SENSORDATA {
@Override
public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, false);
return new KmlTrackWriter(context,true, true, false);
}
@Override
@@ -70,7 +70,7 @@ public enum TrackFileFormat {
@Override
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) {
@@ -97,7 +97,7 @@ public enum TrackFileFormat {
@Override
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) {
@@ -125,7 +125,7 @@ public enum TrackFileFormat {
@Override
public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, exportPhotos);
return new KmlTrackWriter(context,true, true, exportPhotos);
}
@Override
@@ -154,7 +154,7 @@ public enum TrackFileFormat {
@Override
public TrackWriter newTrackWriter(Context context, boolean multiple) {
return new KmlTrackWriter(context, multiple, true, true, exportPhotos);
return new KmlTrackWriter(context,true, true, exportPhotos);
}
@Override
@@ -201,7 +201,7 @@ public enum TrackFileFormat {
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) {
writeWaypoints(track1);
}
trackWriter.writeBeginTracks();
boolean hasMultipleTracks = tracks.length > 1;
if (hasMultipleTracks) {
trackWriter.writeMultiTrackBegin();
}
long startTime = tracks[0].getTrackStatistics().getStartTime_ms();
for (Track track : tracks) {
long offset = track.getTrackStatistics().getStartTime_ms() - startTime;
writeLocations(track, offset);
}
trackWriter.writeEndTracks();
if (hasMultipleTracks) {
trackWriter.writeMultiTrackEnd();
}
trackWriter.writeFooter();
trackWriter.close();
@@ -146,12 +146,12 @@ public class GpxTrackWriter implements TrackWriter {
}
@Override
public void writeBeginTracks() {
public void writeMultiTrackBegin() {
// Do nothing
}
@Override
public void writeEndTracks() {
public void writeMultiTrackEnd() {
// 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 final Context context;
private final boolean hasMultipleTracks;
private final boolean exportPhotos;
private final boolean exportTrackDetail;
private final boolean exportSensorData;
@@ -74,14 +73,12 @@ public class KmlTrackWriter implements TrackWriter {
/**
* @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 exportSensorData should {@link TrackPoint}'s sensor data be exported?
* @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.hasMultipleTracks = hasMultipleTracks;
this.exportTrackDetail = exportTrackDetail;
this.exportSensorData = exportSensorData;
this.exportPhotos = exportPhotos;
@@ -178,18 +175,16 @@ public class KmlTrackWriter implements TrackWriter {
}
}
@Override
public void writeBeginTracks() {
if (printWriter != null && hasMultipleTracks) {
public void writeMultiTrackBegin() {
if (printWriter != null) {
printWriter.println("<Folder id=tour>");
printWriter.println("<name>" + context.getString(R.string.generic_tracks) + "</name>");
printWriter.println("<open>1</open>");
}
}
@Override
public void writeEndTracks() {
if (printWriter != null && hasMultipleTracks) {
public void writeMultiTrackEnd() {
if (printWriter != null) {
printWriter.println("</Folder>");
}
}
@@ -32,7 +32,7 @@ import de.dennisguse.opentracks.content.data.Waypoint;
* For each waypoint:
* {@link #writeWaypoint(Waypoint)}
* {@link #writeEndWaypoints()}
* {@link #writeBeginTracks()}
* {@link #writeMultiTrackBegin()}
* For each track:
* {@link #writeBeginTrack(Track, TrackPoint)}
* For each segment:
@@ -41,7 +41,7 @@ import de.dennisguse.opentracks.content.data.Waypoint;
* {@link #writeTrackPoint(TrackPoint)}
* {@link #writeCloseSegment()}
* {@link #writeEndTrack(Track, TrackPoint)}
* {@link #writeEndTracks()}
* {@link #writeMultiTrackEnd()}
* {@link #writeFooter()}
* {@link #close()}
* </pre>
@@ -96,12 +96,12 @@ public interface TrackWriter {
/**
* Writes the beginning of the tracks.
*/
void writeBeginTracks();
void writeMultiTrackBegin();
/**
* Writes the end of the tracks,
*/
void writeEndTracks();
void writeMultiTrackEnd();
/**
* Writes the beginning of a track.