When play track, add a containing folder to contain all the merged tracks

This commit is contained in:
Jimmy Shih
2013-10-02 15:22:00 -07:00
parent 7594f6b516
commit b182c1cb80
17 changed files with 503 additions and 369 deletions
@@ -52,7 +52,8 @@ import java.util.ArrayList;
public class MyTracksProvider extends ContentProvider {
private static final String TAG = MyTracksProvider.class.getSimpleName();
private static final int DATABASE_VERSION = 22;
@VisibleForTesting
static final int DATABASE_VERSION = 22;
@VisibleForTesting
static final String DATABASE_NAME = "mytracks.db";
@@ -34,6 +34,7 @@ import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -188,7 +189,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
public void onSampledInTrackPoint(Location location) {
if (isResumed()) {
double[] data = new double[ChartView.NUM_SERIES + 1];
fillDataPoint(location, data);
fillDataPoint(getActivity(), location, data);
pendingPoints.add(data);
}
}
@@ -196,14 +197,14 @@ public class ChartFragment extends Fragment implements TrackDataListener {
@Override
public void onSampledOutTrackPoint(Location location) {
if (isResumed()) {
fillDataPoint(location, null);
fillDataPoint(getActivity(), location, null);
}
}
@Override
public void onSegmentSplit(Location location) {
if (isResumed()) {
fillDataPoint(location, null);
fillDataPoint(getActivity(), location, null);
}
}
@@ -437,11 +438,12 @@ public class ChartFragment extends Fragment implements TrackDataListener {
* data[5] = cadence <br>
* data[6] = power <br>
*
* @param context the context
* @param location the location
* @param data the data point to fill in, can be null
*/
@VisibleForTesting
void fillDataPoint(Location location, double data[]) {
void fillDataPoint(Context context, Location location, double data[]) {
double timeOrDistance = Double.NaN;
double elevation = Double.NaN;
double speed = Double.NaN;
@@ -451,8 +453,9 @@ public class ChartFragment extends Fragment implements TrackDataListener {
double power = Double.NaN;
if (tripStatisticsUpdater != null) {
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
.getInt(getActivity(), R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
int weight = PreferencesUtils.getInt(
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, weight);
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
if (chartByDistance) {
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
@@ -18,25 +18,25 @@ import java.util.Locale;
public enum TrackFileFormat implements Parcelable {
KML {
@Override
public TrackWriter newTrackWriter(Context context, boolean inZip) {
return new KmlTrackWriter(context, inZip);
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
return new KmlTrackWriter(context, playTrack);
}
},
GPX {
@Override
public TrackWriter newTrackWriter(Context context, boolean inZip) {
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
return new GpxTrackWriter(context);
}
},
CSV {
@Override
public TrackWriter newTrackWriter(Context context, boolean inZip) {
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
return new CsvTrackWriter(context);
}
},
TCX {
@Override
public TrackWriter newTrackWriter(Context context, boolean inZip) {
public TrackWriter newTrackWriter(Context context, boolean playTrack) {
return new TcxTrackWriter(context);
}
};
@@ -66,7 +66,7 @@ public enum TrackFileFormat implements Parcelable {
/**
* Creates a new track writer for the format.
*/
public abstract TrackWriter newTrackWriter(Context context, boolean inZip);
public abstract TrackWriter newTrackWriter(Context context, boolean playTrack);
/**
* Returns the mime type for each format.
@@ -46,7 +46,7 @@ import java.text.NumberFormat;
* "Segment","Point","Latitude (deg)","Longitude (deg)","Altitude (m)","Bearing
* (deg)","Accuracy (m)","Speed (m/s)","Time","Power (W)","Cadence (rpm)","Heart
* rate (bpm)","Battery level (%)"<br>
*
*
* @author Rodrigo Damazio
*/
public class CsvTrackWriter implements TrackWriter {
@@ -85,12 +85,13 @@ public class CsvTrackWriter implements TrackWriter {
printWriter = null;
}
}
@Override
public void writeHeader(Track track) {
public void writeHeader(Track[] tracks) {
writeCommaSeparatedLine(context.getString(R.string.generic_name),
context.getString(R.string.track_edit_activity_type_hint),
context.getString(R.string.generic_description));
Track track = tracks[0];
writeCommaSeparatedLine(track.getName(), track.getCategory(), track.getDescription());
writeCommaSeparatedLine();
}
@@ -101,7 +102,7 @@ public class CsvTrackWriter implements TrackWriter {
}
@Override
public void writeBeginWaypoints() {
public void writeBeginWaypoints(Track track) {
writeCommaSeparatedLine(context.getString(R.string.generic_name),
context.getString(R.string.marker_edit_marker_type_hint),
context.getString(R.string.generic_description),
@@ -122,20 +123,24 @@ public class CsvTrackWriter implements TrackWriter {
@Override
public void writeWaypoint(Waypoint waypoint) {
Location location = waypoint.getLocation();
writeCommaSeparatedLine(waypoint.getName(),
waypoint.getCategory(),
waypoint.getDescription(),
Double.toString(location.getLatitude()),
Double.toString(location.getLongitude()),
getAltitude(location),
getBearing(location),
getAccuracy(location),
getSpeed(location),
writeCommaSeparatedLine(waypoint.getName(), waypoint.getCategory(), waypoint.getDescription(),
Double.toString(location.getLatitude()), Double.toString(location.getLongitude()),
getAltitude(location), getBearing(location), getAccuracy(location), getSpeed(location),
StringUtils.formatDateTimeIso8601(location.getTime()));
}
@Override
public void writeBeginTrack(Track track, Location firstPoint) {
public void writeBeginTracks() {
// Do nothing
}
@Override
public void writeEndTracks() {
// Do nothing
}
@Override
public void writeBeginTrack(Track track, Location startLocation) {
writeCommaSeparatedLine(context.getString(R.string.description_track_segment),
context.getString(R.string.description_track_point),
context.getString(R.string.description_location_latitude),
@@ -151,7 +156,7 @@ public class CsvTrackWriter implements TrackWriter {
}
@Override
public void writeEndTrack(Track track, Location lastPoint) {
public void writeEndTrack(Track track, Location endLocation) {
// Do nothing
}
@@ -196,39 +201,31 @@ public class CsvTrackWriter implements TrackWriter {
}
}
pointIndex++;
writeCommaSeparatedLine(Integer.toString(segmentIndex),
Integer.toString(pointIndex),
Double.toString(location.getLatitude()),
Double.toString(location.getLongitude()),
getAltitude(location),
getBearing(location),
getAccuracy(location),
getSpeed(location),
StringUtils.formatDateTimeIso8601(location.getTime()),
power,
cadence,
heartRate);
writeCommaSeparatedLine(Integer.toString(segmentIndex), Integer.toString(pointIndex),
Double.toString(location.getLatitude()), Double.toString(location.getLongitude()),
getAltitude(location), getBearing(location), getAccuracy(location), getSpeed(location),
StringUtils.formatDateTimeIso8601(location.getTime()), power, cadence, heartRate);
}
private String getAltitude(Location location) {
return location.hasAltitude() ? Double.toString(location.getAltitude()) : null;
}
private String getBearing(Location location) {
return location.hasBearing() ? Double.toString(location.getBearing()) : null;
}
private String getAccuracy(Location location) {
return location.hasAccuracy() ? SHORT_FORMAT.format(location.getAccuracy()) : null;
}
private String getSpeed(Location location) {
return location.hasSpeed() ? SHORT_FORMAT.format(location.getSpeed()) : null;
}
/**
* Writes a single line of a CSV file.
*
*
* @param values the values to be written as CSV
*/
private void writeCommaSeparatedLine(String... values) {
@@ -22,11 +22,8 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.common.annotations.VisibleForTesting;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
import android.util.Log;
@@ -51,20 +48,11 @@ public class FileTrackExporter implements TrackExporter {
/**
* Constructor.
*
* @param context the context
* @param myTracksProviderUtils the my tracks provider utils
* @param tracks the tracks
* @param trackFileFormat the track file format
* @param trackWriter the track writer
* @param trackExporterListener the track export listener
*/
public FileTrackExporter(MyTracksProviderUtils myTracksProviderUtils,
Track[] tracks, TrackFileFormat trackFileFormat, Context context, boolean inZip,
TrackExporterListener trackExporterListener) {
this(myTracksProviderUtils, tracks, trackFileFormat.newTrackWriter(context, inZip),
trackExporterListener);
}
@VisibleForTesting
public FileTrackExporter(MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
TrackWriter trackWriter, TrackExporterListener trackExporterListener) {
this.myTracksProviderUtils = myTracksProviderUtils;
@@ -77,13 +65,17 @@ public class FileTrackExporter implements TrackExporter {
public boolean writeTrack(OutputStream outputStream) {
try {
trackWriter.prepare(outputStream);
trackWriter.writeHeader(tracks[0]);
long startTime = tracks[0].getTripStatistics().getStartTime();
trackWriter.writeHeader(tracks);
for (int i = 0; i < tracks.length; i++) {
writeWaypoints(tracks[i]);
}
trackWriter.writeBeginTracks();
long startTime = tracks[0].getTripStatistics().getStartTime();
for (int i = 0; i < tracks.length; i++) {
long offset = tracks[i].getTripStatistics().getStartTime() - startTime;
writeLocations(tracks[i], offset);
}
trackWriter.writeEndTracks();
trackWriter.writeFooter();
trackWriter.close();
return true;
@@ -117,7 +109,7 @@ public class FileTrackExporter implements TrackExporter {
throw new InterruptedException();
}
if (!hasWaypoints) {
trackWriter.writeBeginWaypoints();
trackWriter.writeBeginWaypoints(track);
hasWaypoints = true;
}
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
@@ -78,7 +78,7 @@ public class GpxTrackWriter implements TrackWriter {
}
@Override
public void writeHeader(Track track) {
public void writeHeader(Track[] tracks) {
if (printWriter != null) {
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
printWriter.println("<gpx");
@@ -94,6 +94,7 @@ public class GpxTrackWriter implements TrackWriter {
+ " http://www.topografix.com/GPX/Private/TopoGrafix/0/1"
+ " http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd\">");
printWriter.println("<metadata>");
Track track = tracks[0];
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
printWriter.println("</metadata>");
@@ -108,48 +109,7 @@ public class GpxTrackWriter implements TrackWriter {
}
@Override
public void writeBeginTrack(Track track, Location firstLocation) {
if (printWriter != null) {
printWriter.println("<trk>");
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(track.getCategory()) + "</type>");
printWriter.println("<extensions><topografix:color>c0c0c0</topografix:color></extensions>");
}
}
@Override
public void writeEndTrack(Track track, Location lastLocation) {
if (printWriter != null) {
printWriter.println("</trk>");
}
}
@Override
public void writeOpenSegment() {
printWriter.println("<trkseg>");
}
@Override
public void writeCloseSegment() {
printWriter.println("</trkseg>");
}
@Override
public void writeLocation(Location location) {
if (printWriter != null) {
printWriter.println("<trkpt " + formatLocation(location) + ">");
if (location.hasAltitude()) {
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
}
printWriter.println(
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("</trkpt>");
}
}
@Override
public void writeBeginWaypoints() {
public void writeBeginWaypoints(Track track) {
// Do nothing
}
@@ -179,6 +139,57 @@ public class GpxTrackWriter implements TrackWriter {
}
}
@Override
public void writeBeginTracks() {
// Do nothing
}
@Override
public void writeEndTracks() {
// Do nothing
}
@Override
public void writeBeginTrack(Track track, Location startLocation) {
if (printWriter != null) {
printWriter.println("<trk>");
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(track.getCategory()) + "</type>");
printWriter.println("<extensions><topografix:color>c0c0c0</topografix:color></extensions>");
}
}
@Override
public void writeEndTrack(Track track, Location endLocation) {
if (printWriter != null) {
printWriter.println("</trk>");
}
}
@Override
public void writeOpenSegment() {
printWriter.println("<trkseg>");
}
@Override
public void writeCloseSegment() {
printWriter.println("</trkseg>");
}
@Override
public void writeLocation(Location location) {
if (printWriter != null) {
printWriter.println("<trkpt " + formatLocation(location) + ">");
if (location.hasAltitude()) {
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
}
printWriter.println(
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
printWriter.println("</trkpt>");
}
}
/**
* Formats a location with latitude and longitude coordinates.
*
@@ -70,7 +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 inKmz;
private final boolean playTrack;
private final DescriptionGenerator descriptionGenerator;
private final MyTracksProviderUtils myTracksProviderUtils;
@@ -82,14 +82,14 @@ public class KmlTrackWriter implements TrackWriter {
private boolean hasCadence;
private boolean hasHeartRate;
public KmlTrackWriter(Context context, boolean inKmz) {
this(context, inKmz, new DescriptionGeneratorImpl(context));
public KmlTrackWriter(Context context, boolean playTrack) {
this(context, playTrack, new DescriptionGeneratorImpl(context));
}
@VisibleForTesting
KmlTrackWriter(Context context, boolean inKmz, DescriptionGenerator descriptionGenerator) {
KmlTrackWriter(Context context, boolean playTrack, DescriptionGenerator descriptionGenerator) {
this.context = context;
this.inKmz = inKmz;
this.playTrack = playTrack;
this.descriptionGenerator = descriptionGenerator;
this.myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
}
@@ -113,7 +113,7 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeHeader(Track track) {
public void writeHeader(Track[] tracks) {
if (printWriter != null) {
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
printWriter.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\"");
@@ -122,6 +122,7 @@ public class KmlTrackWriter implements TrackWriter {
printWriter.println("<Document>");
printWriter.println("<open>1</open>");
printWriter.println("<visibility>1</visibility>");
Track track = tracks[0];
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<atom:author><atom:name>"
+ StringUtils.formatCData(context.getString(R.string.send_google_by_my_tracks, "", ""))
@@ -148,10 +149,11 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeBeginWaypoints() {
public void writeBeginWaypoints(Track track) {
if (printWriter != null) {
printWriter.println("<Folder><name>"
+ StringUtils.formatCData(context.getString(R.string.menu_markers)) + "</name>");
+ StringUtils.formatCData(context.getString(R.string.track_markers, track.getName()))
+ "</name>");
printWriter.println("<open>1</open>");
}
}
@@ -181,11 +183,31 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeBeginTrack(Track track, Location firstLocation) {
public void writeBeginTracks() {
if (printWriter != null && playTrack) {
printWriter.println("<Folder id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
printWriter.println("<name>" + context.getString(R.string.generic_tracks) + "</name>");
printWriter.println("<open>1</open>");
}
}
@Override
public void writeEndTracks() {
if (printWriter != null && playTrack) {
printWriter.println("</Folder>");
}
}
@Override
public void writeBeginTrack(Track track, Location startLocation) {
if (printWriter != null) {
String name = context.getString(R.string.marker_label_start, track.getName());
writePlacemark(name, "", "", START_STYLE, firstLocation);
printWriter.println("<Placemark id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
writePlacemark(name, "", "", START_STYLE, startLocation);
if (playTrack) {
printWriter.println("<Placemark>");
} else {
printWriter.println("<Placemark id=\"" + GoogleEarthUtils.TOUR_FEATURE_ID_VALUE + "\">");
}
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println(
"<description>" + StringUtils.formatCData(track.getDescription()) + "</description>");
@@ -198,13 +220,13 @@ public class KmlTrackWriter implements TrackWriter {
}
@Override
public void writeEndTrack(Track track, Location lastLocation) {
public void writeEndTrack(Track track, Location endLocation) {
if (printWriter != null) {
printWriter.println("</gx:MultiTrack>");
printWriter.println("</Placemark>");
String name = context.getString(R.string.marker_label_end, track.getName());
String description = descriptionGenerator.generateTrackDescription(track, null, null, false);
writePlacemark(name, "", description, END_STYLE, lastLocation);
writePlacemark(name, "", description, END_STYLE, endLocation);
}
}
@@ -353,12 +375,12 @@ public class KmlTrackWriter implements TrackWriter {
+ StringUtils.formatDateTimeIso8601(location.getTime()) + "</when></TimeStamp>");
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
writeCategory(category);
if (inKmz) {
if (playTrack) {
printWriter.println("<Icon><href>" + Uri.decode(photoUrl) + "</href></Icon>");
} else {
Uri uri = Uri.parse(photoUrl);
printWriter.println("<Icon><href>" + KmzTrackExporter.KMZ_IMAGES_DIR + File.separatorChar
+ uri.getLastPathSegment() + "</href></Icon>");
} else {
printWriter.println("<Icon><href>" + Uri.decode(photoUrl) + "</href></Icon>");
+ uri.getLastPathSegment() + "</href></Icon>");
}
printWriter.print("<ViewVolume>");
@@ -184,7 +184,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
return false;
}
Track track = tracks[0];
boolean useKmz = !playTrack && trackFileFormat == TrackFileFormat.KML;
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
// Make sure the file doesn't exist yet (possibly by changing the filename)
@@ -195,7 +195,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
}
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
trackFileFormat, context, useKmz, new TrackExporterListener() {
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
@Override
public void onProgressUpdate(int number, int max) {
@@ -111,7 +111,7 @@ public class TcxTrackWriter implements TrackWriter {
}
@Override
public void writeHeader(Track track) {
public void writeHeader(Track[] tracks) {
if (printWriter != null) {
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
printWriter.println("<TrainingCenterDatabase"
@@ -142,7 +142,32 @@ public class TcxTrackWriter implements TrackWriter {
}
@Override
public void writeBeginTrack(Track track, Location firstPoint) {
public void writeBeginWaypoints(Track track) {
// Do nothing
}
@Override
public void writeEndWaypoints() {
// Do nothing
}
@Override
public void writeWaypoint(Waypoint waypoint) {
// Do nothing
}
@Override
public void writeBeginTracks() {
// Do nothing
}
@Override
public void writeEndTracks() {
// Do nothing
}
@Override
public void writeBeginTrack(Track track, Location startLocation) {
sportType = getSportType(track.getCategory());
if (printWriter != null) {
String startTime = StringUtils.formatDateTimeIso8601(
@@ -164,7 +189,7 @@ public class TcxTrackWriter implements TrackWriter {
}
@Override
public void writeEndTrack(Track track, Location lastPoint) {
public void writeEndTrack(Track track, Location endLocation) {
if (printWriter != null) {
printWriter.println("</Lap>");
printWriter.println("<Notes>" + StringUtils.formatCData(track.getDescription()) + "</Notes>");
@@ -261,21 +286,6 @@ public class TcxTrackWriter implements TrackWriter {
}
}
@Override
public void writeBeginWaypoints() {
// Do nothing.
}
@Override
public void writeEndWaypoints() {
// Do nothing.
}
@Override
public void writeWaypoint(Waypoint waypoint) {
// Do nothing.
}
/**
* Writes the TCX Version.
*/
@@ -23,58 +23,57 @@ import android.location.Location;
import java.io.OutputStream;
/**
* Interface for writing tracks to a file.
*
* The expected sequence of calls is:
* <ul>
* <li>{@link #prepare}</li>
* <li>{@link #writeHeader}</li>
* <li>For each track:</li>
* <ul>
* <li>{@link #writeBeginWaypoints}
* <li>For each waypoint: {@link #writeWaypoint}
* <li>{@link #writeEndWaypoints}
* <li>{@link #writeBeginTrack}
* <li>For each segment:
* <ul>
* <li>{@link #writeOpenSegment}</li>
* <li>For each location in the segment: {@link #writeLocation}</li>
* <li>{@link #writeCloseSegment}</li>
* </ul>
* </li>
* <li>{@link #writeEndTrack}</li>
* </ul>
* <li>{@link #writeFooter}</li>
* <li>{@link #close}</li>
* </ul>
*
* Interface for writing tracks to a file. The expected sequence of calls is:
*
* <pre>
* {@link #prepare(OutputStream)}
* {@link #writeHeader(Track[])}
* For each track:
* {@link #writeBeginWaypoints(Track)}
* For each waypoint:
* {@link #writeWaypoint(Waypoint)}
* {@link #writeEndWaypoints()}
* {@link #writeBeginTracks()}
* For each track:
* {@link #writeBeginTrack(Track, Location)}
* For each segment:
* {@link #writeOpenSegment()}
* For each location in the segment:
* {@link #writeLocation(Location)}
* {@link #writeCloseSegment()}
* {@link #writeEndTrack(Track, Location)}
* {@link #writeEndTracks()}
* {@link #writeFooter()}
* {@link #close()}
* </pre>
*
* @author Rodrigo Damazio
*/
public interface TrackWriter {
/**
* Gets the file extension (i.e. gpx, kml, ...)
* Gets the file extension (e.g, gpx, kml, ...).
*/
public String getExtension();
/**
* Sets up the file handler.
*
* @param outputStream the output stream for the file handler
* Prepares the output stream.
*
* @param outputStream the output stream
*/
public void prepare(OutputStream outputStream);
/**
* Closes the underlying file handler.
* Closes the output stream.
*/
public void close();
/**
* Writes the header for a file
* Writes the header
*
* @param track the track
* @param tracks the tracks
*/
public void writeHeader(Track track);
public void writeHeader(Track[] tracks);
/**
* Writes the footer.
@@ -83,50 +82,62 @@ public interface TrackWriter {
/**
* Writes the beginning of the waypoints.
*
* @param track the track
*/
public void writeBeginWaypoints();
public void writeBeginWaypoints(Track track);
/**
* Writes the end of the waypoints.
*/
public void writeEndWaypoints();
/**
* Writes a waypoint.
*
*
* @param waypoint the waypoint
*/
public void writeWaypoint(Waypoint waypoint);
/**
* Writes the beginning of the track.
*
* @param track the track
* @param firstLocation the first location
* Writes the beginning of the tracks.
*/
public void writeBeginTrack(Track track, Location firstLocation);
public void writeBeginTracks();
/**
* Writes the end of the track.
*
* @param track the track
* @param lastLocation the last location
* Writes the end of the tracks,
*/
public void writeEndTrack(Track track, Location lastLocation);
public void writeEndTracks();
/**
* Writes the statements necessary to open a new segment.
* Writes the beginning of a track.
*
* @param track the track
* @param startLocation the start location
*/
public void writeBeginTrack(Track track, Location startLocation);
/**
* Writes the end of a track.
*
* @param track the track
* @param endLocation the end location
*/
public void writeEndTrack(Track track, Location endLocation);
/**
* Writes open segment.
*/
public void writeOpenSegment();
/**
* Writes the statements necessary to close a segment.
* Writes close segment.
*/
public void writeCloseSegment();
/**
* Writes a location.
*
*
* @param location the location
*/
public void writeLocation(Location location);
@@ -441,8 +441,8 @@ public class SyncUtils {
java.io.File file = new java.io.File(directory,
FileUtils.buildUniqueFileName(directory, track.getName(), trackFileFormat.getExtension()));
FileTrackExporter fileTrackExporter = new FileTrackExporter(
myTracksProviderUtils, new Track[] { track }, trackFileFormat, context, false, null);
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils,
new Track[] { track }, trackFileFormat.newTrackWriter(context, false), null);
FileOutputStream fileOutputStream = null;
try {