Bug fix: only add folder tag when playing multiple tracks

This commit is contained in:
Jimmy Shih
2013-12-11 15:09:08 -08:00
parent 20bd0287dc
commit 4bf5b41cfa
5 changed files with 25 additions and 16 deletions
@@ -18,25 +18,25 @@ import java.util.Locale;
public enum TrackFileFormat implements Parcelable {
KML {
@Override
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
return new KmlTrackWriter(context, playTrack);
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
return new KmlTrackWriter(context, multiple, playTrack);
}
},
GPX {
@Override
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
return new GpxTrackWriter(context);
}
},
CSV {
@Override
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
return new CsvTrackWriter(context);
}
},
TCX {
@Override
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
public TrackWriter newTrackWriter(Context context, boolean multiple, boolean playTrack) {
return new TcxTrackWriter(context);
}
};
@@ -65,8 +65,12 @@ public enum TrackFileFormat implements Parcelable {
/**
* 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.
@@ -70,6 +70,7 @@ public class KmlTrackWriter implements TrackWriter {
TRACK_ICON = "http://earth.google.com/images/kml-icons/track-directional/track-0.png";
private final Context context;
private final boolean multiple;
private final boolean playTrack;
private final DescriptionGenerator descriptionGenerator;
private final MyTracksProviderUtils myTracksProviderUtils;
@@ -82,13 +83,15 @@ public class KmlTrackWriter implements TrackWriter {
private boolean hasCadence;
private boolean hasHeartRate;
public KmlTrackWriter(Context context, boolean playTrack) {
this(context, playTrack, new DescriptionGeneratorImpl(context));
public KmlTrackWriter(Context context, boolean multiple, boolean playTrack) {
this(context, multiple, playTrack, new DescriptionGeneratorImpl(context));
}
@VisibleForTesting
KmlTrackWriter(Context context, boolean playTrack, DescriptionGenerator descriptionGenerator) {
KmlTrackWriter(Context context, boolean multiple, boolean playTrack,
DescriptionGenerator descriptionGenerator) {
this.context = context;
this.multiple = multiple;
this.playTrack = playTrack;
this.descriptionGenerator = descriptionGenerator;
this.myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
@@ -184,7 +187,7 @@ public class KmlTrackWriter implements TrackWriter {
@Override
public void writeBeginTracks() {
if (printWriter != null && playTrack) {
if (printWriter != null && multiple) {
printWriter.println("<Folder id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
printWriter.println("<name>" + context.getString(R.string.generic_tracks) + "</name>");
printWriter.println("<open>1</open>");
@@ -193,7 +196,7 @@ public class KmlTrackWriter implements TrackWriter {
@Override
public void writeEndTracks() {
if (printWriter != null && playTrack) {
if (printWriter != null && multiple) {
printWriter.println("</Folder>");
}
}
@@ -203,7 +206,8 @@ public class KmlTrackWriter implements TrackWriter {
if (printWriter != null) {
String name = context.getString(R.string.marker_label_start, track.getName());
writePlacemark(name, "", "", START_STYLE, startLocation);
if (playTrack) {
if (multiple) {
// No need to add TOUR_FEATURE_ID_VALUE
printWriter.println("<Placemark>");
} else {
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;
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
trackFileFormat.newTrackWriter(context, tracks.length > 1, playTrack),
new TrackExporterListener() {
@Override
public void onProgressUpdate(int number, int max) {
@@ -466,8 +466,8 @@ public class SyncUtils {
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : TrackFileFormat.KML.getExtension();
java.io.File file = new java.io.File(
directory, FileUtils.buildUniqueFileName(directory, track.getName(), extension));
FileTrackExporter fileTrackExporter = new FileTrackExporter(
myTracksProviderUtils, tracks, TrackFileFormat.KML.newTrackWriter(context, false), null);
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
TrackFileFormat.KML.newTrackWriter(context, false, false), null);
TrackExporter trackExporter = useKmz ? new KmzTrackExporter(
myTracksProviderUtils, fileTrackExporter, tracks, context)
: fileTrackExporter;
@@ -55,7 +55,7 @@ public class KmlTrackWriterTest extends TrackWriterTest {
public void testXmlOutput() throws Exception {
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(
getContext(), false, new FakeDescriptionGenerator());
getContext(), false, false, new FakeDescriptionGenerator());
String result = writeTrack(kmlTrackWriter);
Document doc = parseXmlDocument(result);