Search in sources :

Example 1 with GPSCoordinate

use of nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate in project Gadgetbridge by Freeyourgadget.

the class ActivitySummariesGpsFragment method drawTrack.

private void drawTrack(Canvas canvas, List<GPSCoordinate> trackPoints) {
    double maxLat = (Collections.max(trackPoints, new GPSCoordinate.compareLatitude())).getLatitude();
    double minLat = (Collections.min(trackPoints, new GPSCoordinate.compareLatitude())).getLatitude();
    double maxLon = (Collections.max(trackPoints, new GPSCoordinate.compareLongitude())).getLongitude();
    double minLon = (Collections.min(trackPoints, new GPSCoordinate.compareLongitude())).getLongitude();
    double maxAlt = (Collections.max(trackPoints, new GPSCoordinate.compareElevation())).getAltitude();
    double minAlt = (Collections.min(trackPoints, new GPSCoordinate.compareElevation())).getAltitude();
    float scale_factor_w = (float) ((maxLat - minLat) / (maxLon - minLon));
    float scale_factor_h = (float) ((maxLon - minLon) / (maxLat - minLat));
    if (scale_factor_h > scale_factor_w) {
        // scaling to draw proportionally
        scale_factor_h = 1;
    } else {
        scale_factor_w = 1;
    }
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(1);
    paint.setColor(getResources().getColor(R.color.chart_activity_light));
    for (GPSCoordinate p : trackPoints) {
        float lat = (float) ((p.getLatitude() - minLat) / (maxLat - minLat));
        float lon = (float) ((p.getLongitude() - minLon) / (maxLon - minLon));
        float alt = (float) ((p.getAltitude() - minAlt) / (maxAlt - minAlt));
        // make thicker with higher altitude, we could do more here
        paint.setStrokeWidth(1 + alt);
        canvas.drawPoint(CANVAS_SIZE * lat * scale_factor_w, CANVAS_SIZE * lon * scale_factor_h, paint);
    }
}
Also used : Paint(android.graphics.Paint) GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)

Example 2 with GPSCoordinate

use of nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate in project Gadgetbridge by Freeyourgadget.

the class HuamiActivityDetailsParser method consumeGPSAndUpdateBaseLocation.

private int consumeGPSAndUpdateBaseLocation(byte[] bytes, int offset, long timeOffset) {
    int i = 0;
    int longitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    int latitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    int altitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
    baseLongitude += longitudeDelta;
    baseLatitude += latitudeDelta;
    if (baseAltitude != -20000) {
        baseAltitude += altitudeDelta;
    }
    GPSCoordinate coordinate = new GPSCoordinate(convertHuamiValueToDecimalDegrees(baseLongitude), convertHuamiValueToDecimalDegrees(baseLatitude), baseAltitude);
    ActivityPoint ap = getActivityPointFor(timeOffset, coordinate);
    ap.setLocation(coordinate);
    add(ap);
    return i;
}
Also used : ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)

Example 3 with GPSCoordinate

use of nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate in project Gadgetbridge by Freeyourgadget.

the class GPXExporterTest method readActivityPoints.

private List<ActivityPoint> readActivityPoints(String resourcePath) throws IOException, ParseException {
    final List<ActivityPoint> points = new ArrayList<>();
    try (final InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            String nextLine = reader.readLine();
            while (nextLine != null) {
                final String[] pieces = nextLine.split("\\s+");
                final ActivityPoint point = new ActivityPoint();
                point.setLocation(new GPSCoordinate(Double.parseDouble(pieces[0]), Double.parseDouble(pieces[1]), Double.parseDouble(pieces[2])));
                final int dateIndex;
                if (pieces.length == 5) {
                    point.setHeartRate(Integer.parseInt(pieces[3]));
                    dateIndex = 4;
                } else {
                    dateIndex = 3;
                }
                // Not sure about this parser but seemed safe to use
                point.setTime(ISO8601Utils.parse(pieces[dateIndex], new ParsePosition(0)));
                points.add(point);
                nextLine = reader.readLine();
            }
        }
    }
    return points;
}
Also used : InputStreamReader(java.io.InputStreamReader) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ActivityPoint(nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint) GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate) ParsePosition(java.text.ParsePosition)

Example 4 with GPSCoordinate

use of nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate 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)

Example 5 with GPSCoordinate

use of nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate in project Gadgetbridge by Freeyourgadget.

the class GPXExporter method exportTrackPoint.

private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source, List<ActivityPoint> trackPoints) throws IOException {
    GPSCoordinate location = point.getLocation();
    if (location == null) {
        // skip invalid points, that just contain hr data, for example
        return false;
    }
    ser.startTag(NS_GPX_URI, "trkpt");
    // lon and lat attributes do not have an explicit namespace
    ser.attribute(null, "lon", formatLocation(location.getLongitude()));
    ser.attribute(null, "lat", formatLocation(location.getLatitude()));
    if (location.getAltitude() != -20000) {
        ser.startTag(NS_GPX_URI, "ele").text(formatLocation(location.getAltitude())).endTag(NS_GPX_URI, "ele");
    }
    ser.startTag(NS_GPX_URI, "time").text(DateTimeUtils.formatIso8601UTC(point.getTime())).endTag(NS_GPX_URI, "time");
    String description = point.getDescription();
    if (description != null) {
        ser.startTag(NS_GPX_URI, "desc").text(description).endTag(NS_GPX_URI, "desc");
    }
    // ser.startTag(NS_GPX_URI, "src").text(source).endTag(NS_GPX_URI, "src");
    exportTrackpointExtensions(ser, point, trackPoints);
    ser.endTag(NS_GPX_URI, "trkpt");
    return true;
}
Also used : GPSCoordinate(nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)

Aggregations

GPSCoordinate (nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate)5 InputStream (java.io.InputStream)2 ActivityPoint (nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint)2 Paint (android.graphics.Paint)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 DecimalFormat (java.text.DecimalFormat)1 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1 GpxParser (nodomain.freeyourgadget.gadgetbridge.util.GpxParser)1 Test (org.junit.Test)1