forked from upstream-mirrors/OpenTracks
Rename TrackFormatWriter to TrackWriter
This commit is contained in:
@@ -48,7 +48,7 @@ import java.text.NumberFormat;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class CsvTrackWriter implements TrackFormatWriter {
|
||||
public class CsvTrackWriter implements TrackWriter {
|
||||
|
||||
private static final NumberFormat SHORT_FORMAT = NumberFormat.getInstance();
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Locale;
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class GpxTrackWriter implements TrackFormatWriter {
|
||||
public class GpxTrackWriter implements TrackWriter {
|
||||
|
||||
private static final NumberFormat ELEVATION_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||
private static final NumberFormat COORDINATE_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||
|
||||
@@ -44,7 +44,7 @@ import java.util.ArrayList;
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class KmlTrackWriter implements TrackFormatWriter {
|
||||
public class KmlTrackWriter implements TrackWriter {
|
||||
|
||||
private static final String WAYPOINT_STYLE = "waypoint";
|
||||
private static final String STATISTICS_STYLE = "statistics";
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.Locale;
|
||||
* @author Sandor Dornbush
|
||||
* @author Dominik Rttsches
|
||||
*/
|
||||
public class TcxTrackWriter implements TrackFormatWriter {
|
||||
public class TcxTrackWriter implements TrackWriter {
|
||||
|
||||
/**
|
||||
* TCX sport type. See the TCX spec.
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TrackExporter {
|
||||
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
private final Track[] tracks;
|
||||
private final TrackFormatWriter trackFormatWriter;
|
||||
private final TrackWriter trackWriter;
|
||||
private final OnWriteListener onWriteListener;
|
||||
|
||||
private Thread writeThread;
|
||||
@@ -76,15 +76,15 @@ public class TrackExporter {
|
||||
*/
|
||||
public TrackExporter(Context context, MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
||||
TrackFileFormat trackFileFormat, OnWriteListener onWriteListener) {
|
||||
this(myTracksProviderUtils, tracks, trackFileFormat.newFormatWriter(context), onWriteListener);
|
||||
this(myTracksProviderUtils, tracks, trackFileFormat.newTrackWriter(context), onWriteListener);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public TrackExporter(MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
||||
TrackFormatWriter trackFormatWriter, OnWriteListener onWriteListener) {
|
||||
TrackWriter trackWriter, OnWriteListener onWriteListener) {
|
||||
this.myTracksProviderUtils = myTracksProviderUtils;
|
||||
this.tracks = tracks;
|
||||
this.trackFormatWriter = trackFormatWriter;
|
||||
this.trackWriter = trackWriter;
|
||||
this.onWriteListener = onWriteListener;
|
||||
}
|
||||
|
||||
@@ -105,16 +105,16 @@ public class TrackExporter {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(tracks[0]);
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(tracks[0]);
|
||||
long startTime = tracks[0].getTripStatistics().getStartTime();
|
||||
for (int i = 0; i < tracks.length; i++) {
|
||||
writeWaypoints(tracks[i]);
|
||||
long offset = tracks[i].getTripStatistics().getStartTime() - startTime;
|
||||
writeLocations(tracks[i], offset);
|
||||
}
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
success = true;
|
||||
} catch (InterruptedException e) {
|
||||
success = false;
|
||||
@@ -169,11 +169,11 @@ public class TrackExporter {
|
||||
*/
|
||||
while (cursor.moveToNext()) {
|
||||
if (!hasWaypoints) {
|
||||
trackFormatWriter.writeBeginWaypoints();
|
||||
trackWriter.writeBeginWaypoints();
|
||||
hasWaypoints = true;
|
||||
}
|
||||
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
|
||||
trackFormatWriter.writeWaypoint(waypoint);
|
||||
trackWriter.writeWaypoint(waypoint);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -182,7 +182,7 @@ public class TrackExporter {
|
||||
}
|
||||
}
|
||||
if (hasWaypoints) {
|
||||
trackFormatWriter.writeEndWaypoints();
|
||||
trackWriter.writeEndWaypoints();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,28 +211,28 @@ public class TrackExporter {
|
||||
boolean isSegmentValid = isLocationValid && isLastLocationValid;
|
||||
if (!wroteTrack && isSegmentValid) {
|
||||
// Found the first two consecutive locations that are valid
|
||||
trackFormatWriter.writeBeginTrack(track, locationFactory.lastLocation);
|
||||
trackWriter.writeBeginTrack(track, locationFactory.lastLocation);
|
||||
wroteTrack = true;
|
||||
}
|
||||
|
||||
if (isSegmentValid) {
|
||||
if (!wroteSegment) {
|
||||
// Start a segment
|
||||
trackFormatWriter.writeOpenSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
wroteSegment = true;
|
||||
|
||||
// Write the previous location, which we had previously skipped
|
||||
trackFormatWriter.writeLocation(locationFactory.lastLocation);
|
||||
trackWriter.writeLocation(locationFactory.lastLocation);
|
||||
}
|
||||
|
||||
// Write the current location
|
||||
trackFormatWriter.writeLocation(location);
|
||||
trackWriter.writeLocation(location);
|
||||
if (onWriteListener != null) {
|
||||
onWriteListener.onWrite(locationNumber, track.getNumberOfPoints());
|
||||
}
|
||||
} else {
|
||||
if (wroteSegment) {
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeCloseSegment();
|
||||
wroteSegment = false;
|
||||
}
|
||||
}
|
||||
@@ -241,17 +241,17 @@ public class TrackExporter {
|
||||
}
|
||||
|
||||
if (wroteSegment) {
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeCloseSegment();
|
||||
wroteSegment = false;
|
||||
}
|
||||
if (wroteTrack) {
|
||||
Location lastValidTrackPoint = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
|
||||
setLocationTime(lastValidTrackPoint, offset);
|
||||
trackFormatWriter.writeEndTrack(track, lastValidTrackPoint);
|
||||
trackWriter.writeEndTrack(track, lastValidTrackPoint);
|
||||
} else {
|
||||
// Write an empty track
|
||||
trackFormatWriter.writeBeginTrack(track, null);
|
||||
trackFormatWriter.writeEndTrack(track, null);
|
||||
trackWriter.writeBeginTrack(track, null);
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
}
|
||||
} finally {
|
||||
iterator.close();
|
||||
|
||||
@@ -12,25 +12,25 @@ import java.util.Locale;
|
||||
public enum TrackFileFormat implements Parcelable {
|
||||
KML {
|
||||
@Override
|
||||
TrackFormatWriter newFormatWriter(Context context) {
|
||||
TrackWriter newTrackWriter(Context context) {
|
||||
return new KmlTrackWriter(context);
|
||||
}
|
||||
},
|
||||
GPX {
|
||||
@Override
|
||||
TrackFormatWriter newFormatWriter(Context context) {
|
||||
TrackWriter newTrackWriter(Context context) {
|
||||
return new GpxTrackWriter(context);
|
||||
}
|
||||
},
|
||||
CSV {
|
||||
@Override
|
||||
public TrackFormatWriter newFormatWriter(Context context) {
|
||||
public TrackWriter newTrackWriter(Context context) {
|
||||
return new CsvTrackWriter(context);
|
||||
}
|
||||
},
|
||||
TCX {
|
||||
@Override
|
||||
public TrackFormatWriter newFormatWriter(Context context) {
|
||||
public TrackWriter newTrackWriter(Context context) {
|
||||
return new TcxTrackWriter(context);
|
||||
}
|
||||
};
|
||||
@@ -58,9 +58,9 @@ public enum TrackFileFormat implements Parcelable {
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates and returns a new format writer for each format.
|
||||
* Creates a new track writer for the format.
|
||||
*/
|
||||
abstract TrackFormatWriter newFormatWriter(Context context);
|
||||
abstract TrackWriter newTrackWriter(Context context);
|
||||
|
||||
/**
|
||||
* Returns the mime type for each format.
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ import java.io.OutputStream;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public interface TrackFormatWriter {
|
||||
public interface TrackWriter {
|
||||
|
||||
/**
|
||||
* Gets the file extension (i.e. gpx, kml, ...)
|
||||
@@ -21,7 +21,7 @@ package com.google.android.apps.mytracks.io.file;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class CsvTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
private static final String BEGIN_TAG = "\"";
|
||||
private static final String END_TAG = "\"\n";
|
||||
@@ -62,8 +62,8 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
+ expectedMarkerHeader + expectedMarker1 + expectedMarker2 + "\n"
|
||||
+ expectedPointHeader + expectedPoint1 + expectedPoint2 + expectedPoint3 + expectedPoint4;
|
||||
|
||||
CsvTrackWriter writer = new CsvTrackWriter(getContext());
|
||||
assertEquals(expected, writeTrack(writer));
|
||||
CsvTrackWriter csvTrackWriter = new CsvTrackWriter(getContext());
|
||||
assertEquals(expected, writeTrack(csvTrackWriter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,11 +25,11 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class GpxTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
TrackFormatWriter writer = new GpxTrackWriter(getContext());
|
||||
String result = writeTrack(writer);
|
||||
GpxTrackWriter gpxTrackWriter = new GpxTrackWriter(getContext());
|
||||
String result = writeTrack(gpxTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element gpxTag = getChildElement(doc, "gpx");
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class KmlTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
private static final String FULL_TRACK_DESCRIPTION = "full track description";
|
||||
|
||||
@@ -54,8 +54,8 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
||||
}
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
KmlTrackWriter writer = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
||||
String result = writeTrack(writer);
|
||||
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
||||
String result = writeTrack(kmlTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element kmlTag = getChildElement(doc, "kml");
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class TcxTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
||||
String result = writeTrack(writer);
|
||||
TcxTrackWriter tcxTrackWriter = new TcxTrackWriter(getContext());
|
||||
String result = writeTrack(tcxTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element root = getChildElement(doc, "TrainingCenterDatabase");
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
|
||||
private IMocksControl mocksControl;
|
||||
|
||||
private TrackFormatWriter trackFormatWriter;
|
||||
private TrackWriter trackWriter;
|
||||
private Track track;
|
||||
private OutputStream outputStream;
|
||||
private TrackExporter trackExporter;
|
||||
@@ -61,7 +61,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
myTracksProviderUtils);
|
||||
|
||||
mocksControl = EasyMock.createStrictControl();
|
||||
trackFormatWriter = mocksControl.createMock(TrackFormatWriter.class);
|
||||
trackWriter = mocksControl.createMock(TrackWriter.class);
|
||||
|
||||
track = new Track();
|
||||
track.setName(TRACK_NAME);
|
||||
@@ -76,7 +76,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
|
||||
}
|
||||
};
|
||||
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackFormatWriter, onWriteListener);
|
||||
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackWriter, onWriteListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,12 +91,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
public void testWriteTrack_emptyTrack() throws Exception {
|
||||
|
||||
// Set expected mock behavior
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackFormatWriter.writeBeginTrack(track, null);
|
||||
trackFormatWriter.writeEndTrack(track, null);
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginTrack(track, null);
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
@@ -123,12 +123,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
myTracksProviderUtils.bulkInsertTrackPoint(locations, locations.length, TRACK_ID));
|
||||
|
||||
// Set expected mock behavior
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackFormatWriter.writeBeginTrack(track, null);
|
||||
trackFormatWriter.writeEndTrack(track, null);
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginTrack(track, null);
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
@@ -162,38 +162,38 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
waypoint.setId(i + 1);
|
||||
}
|
||||
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
|
||||
// Expect reading/writing of the waypoints (except the first)
|
||||
trackFormatWriter.writeBeginWaypoints();
|
||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[1]));
|
||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[2]));
|
||||
trackFormatWriter.writeEndWaypoints();
|
||||
trackWriter.writeBeginWaypoints();
|
||||
trackWriter.writeWaypoint(waypointEq(waypoints[1]));
|
||||
trackWriter.writeWaypoint(waypointEq(waypoints[2]));
|
||||
trackWriter.writeEndWaypoints();
|
||||
|
||||
// Begin the track
|
||||
trackFormatWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
||||
trackWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
||||
|
||||
// Write locations 1-2
|
||||
trackFormatWriter.writeOpenSegment();
|
||||
trackFormatWriter.writeLocation(locationEq(locations[0]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[1]));
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(locationEq(locations[0]));
|
||||
trackWriter.writeLocation(locationEq(locations[1]));
|
||||
trackWriter.writeCloseSegment();
|
||||
|
||||
// Location 3 is not written - it's invalid
|
||||
|
||||
// Write locations 4-6
|
||||
trackFormatWriter.writeOpenSegment();
|
||||
trackFormatWriter.writeLocation(locationEq(locations[3]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[4]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[5]));
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(locationEq(locations[3]));
|
||||
trackWriter.writeLocation(locationEq(locations[4]));
|
||||
trackWriter.writeLocation(locationEq(locations[5]));
|
||||
trackWriter.writeCloseSegment();
|
||||
|
||||
// End the track
|
||||
trackFormatWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
||||
trackWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
||||
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
|
||||
+21
-21
@@ -34,7 +34,7 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
||||
public abstract class TrackWriterTest extends AndroidTestCase {
|
||||
|
||||
// All the user-provided strings have "]]>" to ensure that proper escaping is
|
||||
// being done.
|
||||
@@ -110,29 +110,29 @@ public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
||||
* Makes the right sequence of calls to the writer in order to write the fake
|
||||
* track in {@link #track}.
|
||||
*
|
||||
* @param writer the writer to write to
|
||||
* @param trackWriter the track writer
|
||||
* @return the written contents
|
||||
*/
|
||||
protected String writeTrack(TrackFormatWriter writer) throws Exception {
|
||||
protected String writeTrack(TrackWriter trackWriter) throws Exception {
|
||||
OutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||
writer.prepare(output);
|
||||
writer.writeHeader(track);
|
||||
writer.writeBeginWaypoints();
|
||||
writer.writeWaypoint(wp1);
|
||||
writer.writeWaypoint(wp2);
|
||||
writer.writeEndWaypoints();
|
||||
writer.writeBeginTrack(track, location1);
|
||||
writer.writeOpenSegment();
|
||||
writer.writeLocation(location1);
|
||||
writer.writeLocation(location2);
|
||||
writer.writeCloseSegment();
|
||||
writer.writeOpenSegment();
|
||||
writer.writeLocation(location3);
|
||||
writer.writeLocation(location4);
|
||||
writer.writeCloseSegment();
|
||||
writer.writeEndTrack(track, location4);
|
||||
writer.writeFooter();
|
||||
writer.close();
|
||||
trackWriter.prepare(output);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginWaypoints();
|
||||
trackWriter.writeWaypoint(wp1);
|
||||
trackWriter.writeWaypoint(wp2);
|
||||
trackWriter.writeEndWaypoints();
|
||||
trackWriter.writeBeginTrack(track, location1);
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(location1);
|
||||
trackWriter.writeLocation(location2);
|
||||
trackWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(location3);
|
||||
trackWriter.writeLocation(location4);
|
||||
trackWriter.writeCloseSegment();
|
||||
trackWriter.writeEndTrack(track, location4);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user