Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for uploading GPX waypointd #2417

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/androidTest/java/de/blau/android/gpx/GpxUploadTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.blau.android.gpx;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

Expand Down Expand Up @@ -137,10 +139,30 @@ public void uploadGpx() {
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
UiObject2 menuButton = TestUtils.getLayerButton(device, GPX_FILE, LayerDialogTest.MENU_BUTTON);
menuButton.click();
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_information), true, false));
assertTrue(TestUtils.findText(device, false, "112", 500, true));
assertTrue(TestUtils.findText(device, false, "79", 500, true));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
menuButton = TestUtils.getLayerButton(device, GPX_FILE, LayerDialogTest.MENU_BUTTON);
menuButton.click();
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_gps_upload), true, false));
mockServer.enqueue("userdetails");
mockServer.enqueue("200");
assertTrue(TestUtils.clickResource(device, false, "android:id/button1", true));
assertTrue(TestUtils.textGone(device, "Uploading", 5000));

try {
mockServer.takeRequest();
String upload = mockServer.takeRequest().getUtf8Body();
int gpxStart = upload.indexOf("<?xml");
Track track = new Track(main, false);
track.importFromGPX(new ByteArrayInputStream(upload.substring(gpxStart).getBytes()));
assertEquals(79, track.getWayPoints().size());
assertEquals(112, track.getTrackPoints().size());
} catch (InterruptedException e) {
fail(e.getMessage());
}
} finally {
TestUtils.deleteFile(main, GPX_FILE);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/blau/android/gpx/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ public void markNewSegment() {
*
* @param outputStream the stream we are writing to
* @throws XmlPullParserException
* @throws IOException
* @throws IOException if writing to the stream fails
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParserException, IllegalArgumentException, IllegalStateException, IOException {
public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParserException, IOException {
XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
serializer.setOutput(outputStream, OsmXml.UTF_8);
serializer.startDocument(OsmXml.UTF_8, null);
Expand All @@ -471,6 +471,9 @@ public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParser
serializer.attribute(null, "xsi:schemaLocation", "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd");
serializer.attribute(null, "version", "1.0");
serializer.attribute(null, "creator", "Vespucci");
for (WayPoint wt : getWayPoints()) {
wt.toXml(serializer, this);
}
serializer.startTag(null, TRK_ELEMENT);
serializer.startTag(null, TRKSEG_ELEMENT);
boolean hasPoints = false;
Expand Down
Loading