forked from upstream-mirrors/OpenTracks
Bug fix: only add folder tag when playing multiple tracks
This commit is contained in:
@@ -18,25 +18,25 @@ import java.util.Locale;
|
|||||||
public enum TrackFileFormat implements Parcelable {
|
public enum TrackFileFormat implements Parcelable {
|
||||||
KML {
|
KML {
|
||||||
@Override
|
@Override
|
||||||
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
|
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
|
||||||
return new KmlTrackWriter(context, playTrack);
|
return new KmlTrackWriter(context, multiple, playTrack);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GPX {
|
GPX {
|
||||||
@Override
|
@Override
|
||||||
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
|
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
|
||||||
return new GpxTrackWriter(context);
|
return new GpxTrackWriter(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
CSV {
|
CSV {
|
||||||
@Override
|
@Override
|
||||||
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
|
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
|
||||||
return new CsvTrackWriter(context);
|
return new CsvTrackWriter(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TCX {
|
TCX {
|
||||||
@Override
|
@Override
|
||||||
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
|
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
|
||||||
return new TcxTrackWriter(context);
|
return new TcxTrackWriter(context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -65,8 +65,12 @@ public enum TrackFileFormat implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new track writer for the format.
|
* Creates a new track writer for the format.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param multiple true for writing multiple tracks
|
||||||
|
* @param playTrack true to play track
|
||||||
*/
|
*/
|
||||||
public abstract TrackWriter newTrackWriter(Context context, boolean playTrack);
|
public abstract TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the mime type for each format.
|
* Returns the mime type for each format.
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
TRACK_ICON = "http://earth.google.com/images/kml-icons/track-directional/track-0.png";
|
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 multiple;
|
||||||
private final boolean playTrack;
|
private final boolean playTrack;
|
||||||
private final DescriptionGenerator descriptionGenerator;
|
private final DescriptionGenerator descriptionGenerator;
|
||||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||||
@@ -82,13 +83,15 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
private boolean hasCadence;
|
private boolean hasCadence;
|
||||||
private boolean hasHeartRate;
|
private boolean hasHeartRate;
|
||||||
|
|
||||||
public KmlTrackWriter(Context context, boolean playTrack) {
|
public KmlTrackWriter(Context context, boolean multiple, boolean playTrack) {
|
||||||
this(context, playTrack, new DescriptionGeneratorImpl(context));
|
this(context, multiple, playTrack, new DescriptionGeneratorImpl(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
KmlTrackWriter(Context context, boolean playTrack, DescriptionGenerator descriptionGenerator) {
|
KmlTrackWriter(Context context, boolean multiple, boolean playTrack,
|
||||||
|
DescriptionGenerator descriptionGenerator) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.multiple = multiple;
|
||||||
this.playTrack = playTrack;
|
this.playTrack = playTrack;
|
||||||
this.descriptionGenerator = descriptionGenerator;
|
this.descriptionGenerator = descriptionGenerator;
|
||||||
this.myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
this.myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
@@ -184,7 +187,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeBeginTracks() {
|
public void writeBeginTracks() {
|
||||||
if (printWriter != null && playTrack) {
|
if (printWriter != null && multiple) {
|
||||||
printWriter.println("<Folder id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
|
printWriter.println("<Folder id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
|
||||||
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>");
|
||||||
@@ -193,7 +196,7 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeEndTracks() {
|
public void writeEndTracks() {
|
||||||
if (printWriter != null && playTrack) {
|
if (printWriter != null && multiple) {
|
||||||
printWriter.println("</Folder>");
|
printWriter.println("</Folder>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +206,8 @@ public class KmlTrackWriter implements TrackWriter {
|
|||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
String name = context.getString(R.string.marker_label_start, track.getName());
|
String name = context.getString(R.string.marker_label_start, track.getName());
|
||||||
writePlacemark(name, "", "", START_STYLE, startLocation);
|
writePlacemark(name, "", "", START_STYLE, startLocation);
|
||||||
if (playTrack) {
|
if (multiple) {
|
||||||
|
// No need to add TOUR_FEATURE_ID_VALUE
|
||||||
printWriter.println("<Placemark>");
|
printWriter.println("<Placemark>");
|
||||||
} else {
|
} else {
|
||||||
printWriter.println("<Placemark id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
|
printWriter.println("<Placemark id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
|
||||||
|
|||||||
@@ -188,7 +188,8 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
|
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
|
||||||
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
|
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
|
||||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
||||||
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
|
trackFileFormat.newTrackWriter(context, tracks.length > 1, playTrack),
|
||||||
|
new TrackExporterListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(int number, int max) {
|
public void onProgressUpdate(int number, int max) {
|
||||||
|
|||||||
@@ -466,8 +466,8 @@ public class SyncUtils {
|
|||||||
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : TrackFileFormat.KML.getExtension();
|
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : TrackFileFormat.KML.getExtension();
|
||||||
java.io.File file = new java.io.File(
|
java.io.File file = new java.io.File(
|
||||||
directory, FileUtils.buildUniqueFileName(directory, track.getName(), extension));
|
directory, FileUtils.buildUniqueFileName(directory, track.getName(), extension));
|
||||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(
|
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
||||||
myTracksProviderUtils, tracks, TrackFileFormat.KML.newTrackWriter(context, false), null);
|
TrackFileFormat.KML.newTrackWriter(context, false, false), null);
|
||||||
TrackExporter trackExporter = useKmz ? new KmzTrackExporter(
|
TrackExporter trackExporter = useKmz ? new KmzTrackExporter(
|
||||||
myTracksProviderUtils, fileTrackExporter, tracks, context)
|
myTracksProviderUtils, fileTrackExporter, tracks, context)
|
||||||
: fileTrackExporter;
|
: fileTrackExporter;
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ public class KmlTrackWriterTest extends TrackWriterTest {
|
|||||||
|
|
||||||
public void testXmlOutput() throws Exception {
|
public void testXmlOutput() throws Exception {
|
||||||
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(
|
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(
|
||||||
getContext(), false, new FakeDescriptionGenerator());
|
getContext(), false, false, new FakeDescriptionGenerator());
|
||||||
String result = writeTrack(kmlTrackWriter);
|
String result = writeTrack(kmlTrackWriter);
|
||||||
Document doc = parseXmlDocument(result);
|
Document doc = parseXmlDocument(result);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user