Search in sources :

Example 1 with GpxParser

use of nodomain.freeyourgadget.gadgetbridge.util.GpxParser in project Gadgetbridge by Freeyourgadget.

the class ActivitySummariesGpsFragment method processInBackgroundThread.

private void processInBackgroundThread() {
    final Canvas canvas = createCanvas(gpsView);
    new Thread(new Runnable() {

        @Override
        public void run() {
            GpxParser gpxParser = null;
            FileInputStream inputStream = null;
            try {
                inputStream = new FileInputStream(inputFile);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            if (inputStream != null) {
                gpxParser = new GpxParser(inputStream);
            }
            if (gpxParser != null) {
                if (gpxParser.getPoints().toArray().length > 0) {
                    drawTrack(canvas, gpxParser.getPoints());
                }
            }
        }
    }).start();
}
Also used : GpxParser(nodomain.freeyourgadget.gadgetbridge.util.GpxParser) Canvas(android.graphics.Canvas) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 2 with GpxParser

use of nodomain.freeyourgadget.gadgetbridge.util.GpxParser in project Gadgetbridge by Freeyourgadget.

the class GPXParserTest method shouldReadGPXCorrectly.

@Test
public void shouldReadGPXCorrectly() throws IOException {
    try (final InputStream inputStream = getClass().getResourceAsStream("/gpx-exporter-test-SampleTrack.gpx")) {
        GpxParser gpxParser = new GpxParser(inputStream);
        List<GPSCoordinate> trackPoints = gpxParser.getPoints();
        Assert.assertEquals(trackPoints.size(), 14);
        DecimalFormat df = new DecimalFormat("###.##");
        for (GPSCoordinate tp : trackPoints) {
            Assert.assertEquals(df.format(tp.getLongitude()), "44.15");
            Assert.assertEquals(df.format(tp.getLatitude()), "-68.2");
            Assert.assertThat(df.format(tp.getAltitude()), anyOf(is("40"), is("46")));
        }
    }
}
Also used : GpxParser(nodomain.freeyourgadget.gadgetbridge.util.GpxParser) InputStream(java.io.InputStream) DecimalFormat(java.text.DecimalFormat) GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate) Test(org.junit.Test)

Aggregations

GpxParser (nodomain.freeyourgadget.gadgetbridge.util.GpxParser)2 Canvas (android.graphics.Canvas)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 DecimalFormat (java.text.DecimalFormat)1 GPSCoordinate (nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)1 Test (org.junit.Test)1