forked from upstream-mirrors/OpenTracks
Addressing review comments.
This commit is contained in:
@@ -38,17 +38,22 @@ import java.util.TimeZone;
|
|||||||
public class GpxTrackWriter implements TrackFormatWriter {
|
public class GpxTrackWriter implements TrackFormatWriter {
|
||||||
|
|
||||||
static final int LATLONG_FORMAT = Location.FORMAT_DEGREES;
|
static final int LATLONG_FORMAT = Location.FORMAT_DEGREES;
|
||||||
static final DecimalFormat ELEVATION_FORMAT =
|
static final DecimalFormat ELEVATION_FORMATTER =
|
||||||
new DecimalFormat("#.#");
|
new DecimalFormat("#.#");
|
||||||
static final SimpleDateFormat TIMESTAMP_FORMAT =
|
static final SimpleDateFormat TIMESTAMP_FORMATTER =
|
||||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
static {
|
static {
|
||||||
TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
TIMESTAMP_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PrintWriter pw = null;
|
private PrintWriter pw = null;
|
||||||
private Track track;
|
private Track track;
|
||||||
|
|
||||||
|
private String formatLocation(Location l) {
|
||||||
|
return "lat=\"" + Location.convert(l.getLatitude(), LATLONG_FORMAT)
|
||||||
|
+ "\" lon=\"" + Location.convert(l.getLongitude(), LATLONG_FORMAT) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(Track track, OutputStream out) {
|
public void prepare(Track track, OutputStream out) {
|
||||||
this.track = track;
|
this.track = track;
|
||||||
@@ -122,12 +127,10 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
@Override
|
@Override
|
||||||
public void writeLocation(Location l) {
|
public void writeLocation(Location l) {
|
||||||
if (pw != null) {
|
if (pw != null) {
|
||||||
pw.println("<trkpt lat=\""
|
pw.println("<trkpt " + formatLocation(l) + ">");
|
||||||
+ Location.convert(l.getLatitude(), LATLONG_FORMAT) + "\" lon=\""
|
|
||||||
+ Location.convert(l.getLongitude(), LATLONG_FORMAT) + "\">");
|
|
||||||
Date d = new Date(l.getTime());
|
Date d = new Date(l.getTime());
|
||||||
pw.println("<ele>" + ELEVATION_FORMAT.format(l.getAltitude()) + "</ele>");
|
pw.println("<ele>" + ELEVATION_FORMATTER.format(l.getAltitude()) + "</ele>");
|
||||||
pw.println("<time>" + TIMESTAMP_FORMAT.format(d) + "</time>");
|
pw.println("<time>" + TIMESTAMP_FORMATTER.format(d) + "</time>");
|
||||||
pw.println("</trkpt>");
|
pw.println("</trkpt>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,11 +148,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
if (pw != null) {
|
if (pw != null) {
|
||||||
Location l = waypoint.getLocation();
|
Location l = waypoint.getLocation();
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
pw.println("<wpt lat=\""
|
pw.println("<wpt " + formatLocation(l) + ">");
|
||||||
+ Location.convert(l.getLatitude(), LATLONG_FORMAT) + "\" lon=\""
|
pw.println("<ele>" + ELEVATION_FORMATTER.format(l.getAltitude()) + "</ele>");
|
||||||
+ Location.convert(l.getLongitude(), LATLONG_FORMAT) + "\">");
|
pw.println("<time>" + TIMESTAMP_FORMATTER.format(l.getTime()) + "</time>");
|
||||||
pw.println("<ele>" + ELEVATION_FORMAT.format(l.getAltitude()) + "</ele>");
|
|
||||||
pw.println("<time>" + TIMESTAMP_FORMAT.format(l.getTime()) + "</time>");
|
|
||||||
pw.println("<name>" + StringUtils.stringAsCData(waypoint.getName())
|
pw.println("<name>" + StringUtils.stringAsCData(waypoint.getName())
|
||||||
+ "</name>");
|
+ "</name>");
|
||||||
pw.println("<desc>"
|
pw.println("<desc>"
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
Location.convert(loc.getLongitude(), GpxTrackWriter.LATLONG_FORMAT),
|
Location.convert(loc.getLongitude(), GpxTrackWriter.LATLONG_FORMAT),
|
||||||
tag.getAttribute("lon"));
|
tag.getAttribute("lon"));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
GpxTrackWriter.TIMESTAMP_FORMAT.format(new Date(loc.getTime())),
|
GpxTrackWriter.TIMESTAMP_FORMATTER.format(new Date(loc.getTime())),
|
||||||
getChildTextValue(tag, "time"));
|
getChildTextValue(tag, "time"));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
GpxTrackWriter.ELEVATION_FORMAT.format(loc.getAltitude()),
|
GpxTrackWriter.ELEVATION_FORMATTER.format(loc.getAltitude()),
|
||||||
getChildTextValue(tag, "ele"));
|
getChildTextValue(tag, "ele"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user