diff --git a/app/src/main/java/com/proculite/logmylocation/MainActivity.java b/app/src/main/java/com/proculite/logmylocation/MainActivity.java index dfcb3f5..142a611 100644 --- a/app/src/main/java/com/proculite/logmylocation/MainActivity.java +++ b/app/src/main/java/com/proculite/logmylocation/MainActivity.java @@ -33,6 +33,8 @@ public class MainActivity extends AppCompatActivity implements LocationListener, private final String TAG = MainActivity.class.getName(); private Button exportButton; private WriteToFile writeToFile; + private static boolean includeComments = false; + private static Double accuracyThreshold = 2.0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -93,7 +95,10 @@ public class MainActivity extends AppCompatActivity implements LocationListener, new Thread(() -> { GPX gpx = GPX.builder().addTrack(track -> track.addSegment(segment -> { for(LocationEntity location : binder.allLocations()){ - segment.addPoint(locationToWayPoint(location)); + WayPoint wayPoint = locationToWayPoint(location); + if(wayPoint != null) { + segment.addPoint(wayPoint); + } } })).build(); Log.d(TAG, "Built GPX."); @@ -111,6 +116,17 @@ public class MainActivity extends AppCompatActivity implements LocationListener, } private static WayPoint locationToWayPoint(LocationEntity location) { + if(accuracyThreshold != null) + { + if(location.accuracy == null) { + return null; + } + + if(location.accuracy > accuracyThreshold) { + return null; + } + } + WayPoint.Builder builder = WayPoint.builder() .lat(location.latitude) .lon(location.longitude) @@ -128,30 +144,32 @@ public class MainActivity extends AppCompatActivity implements LocationListener, builder.ele(location.altitude); } - StringBuilder commentBuilder = new StringBuilder(); + if(includeComments) { + StringBuilder commentBuilder = new StringBuilder(); - if(location.isMock){ - commentBuilder.append("Location is mock.\n"); + if (location.isMock) { + commentBuilder.append("Location is mock.\n"); + } + + if (location.accuracy != null) { + commentBuilder.append(String.format("Accuracy is expected to be within %s meters.\n", location.accuracy)); + } + + if (location.altitudeAccuracy != null) { + commentBuilder.append(String.format("Altitude accuracy is expected to be within %s meters.\n", location.altitudeAccuracy)); + } + + if (location.bearingAccuracy != null) { + commentBuilder.append(String.format("Bearing accuracy is expected to be within %s degrees.\n", location.bearingAccuracy)); + } + + if (location.speedAccuracy != null) { + commentBuilder.append(String.format("Speed accuracy is expected to be within %s meters per second.\n", location.speedAccuracy)); + } + + builder.cmt(commentBuilder.toString()); } - if(location.accuracy != null){ - commentBuilder.append(String.format("Accuracy is expected to be within %s meters.\n", location.accuracy)); - } - - if(location.altitudeAccuracy != null){ - commentBuilder.append(String.format("Altitude accuracy is expected to be within %s meters.\n", location.altitudeAccuracy)); - } - - if(location.bearingAccuracy != null){ - commentBuilder.append(String.format("Bearing accuracy is expected to be within %s degrees.\n", location.bearingAccuracy)); - } - - if(location.speedAccuracy != null){ - commentBuilder.append(String.format("Speed accuracy is expected to be within %s meters per second.\n", location.speedAccuracy)); - } - - builder.cmt(commentBuilder.toString()); - return builder.build(); }