Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class OpenStreetMapConstants {
private static final String OSM_API_URL_DEV = "https://master.apis.dev.openstreetmap.org";
private static final String OSM_API_URL_PROD = "https://www.openstreetmap.org";
private static final String OSM_API_URL = (DEV_MODE) ? OSM_API_URL_DEV : OSM_API_URL_PROD;
public static final String PREFS_GPS_MIN_ACCURACY = "gps_min_accuracy";

public static class Api {

Expand Down
37 changes: 36 additions & 1 deletion app/src/main/java/net/osmtracker/service/gps/GPSLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
Expand All @@ -31,6 +32,7 @@
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.listener.PressureListener;
import net.osmtracker.listener.SensorListener;
import net.osmtracker.osm.OpenStreetMapConstants;

/**
* GPS logging service.
Expand All @@ -56,6 +58,14 @@ public class GPSLogger extends Service implements LocationListener {
* Is GPS enabled ?
*/
private boolean isGpsEnabled = false;
/**
* Minimum accuracy in meters for starting
*/
private int minAccuracy = 0;
/**
* Precision of the accuracy in meters is satisfied ?
*/
private boolean isAccuracySatisfied = false;

/**
* Use barometer yes/no ?
Expand Down Expand Up @@ -250,6 +260,18 @@ public void onCreate() {
use_barometer = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getBoolean(
OSMTracker.Preferences.KEY_USE_BAROMETER, OSMTracker.Preferences.VAL_USE_BAROMETER);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
try {
minAccuracy = Integer.parseInt(prefs.getString(OpenStreetMapConstants.PREFS_GPS_MIN_ACCURACY, "0"));
Comment thread
Andyporras marked this conversation as resolved.
Outdated
} catch (NumberFormatException e) {
minAccuracy = 0;
}
// minimum precision enabled
if (minAccuracy > 0) {
isAccuracySatisfied = false;
} else {
isAccuracySatisfied = true;
}
// Register our broadcast receiver
IntentFilter filter = new IntentFilter();
filter.addAction(OSMTracker.INTENT_TRACK_WP);
Expand Down Expand Up @@ -336,7 +358,20 @@ private void stopTrackingAndSave() {
}

@Override
public void onLocationChanged(Location location) {
public void onLocationChanged(Location location) {
if (location == null){
return;
}
// Wait for minimum accuracy before starting
if(!isAccuracySatisfied){
if(location.hasAccuracy() && location.getAccuracy() <= minAccuracy){
// Precision achieved we unlocked the door and began recording this one and the following ones.
isAccuracySatisfied = true;
}
else {
return;
}
}
// We're receiving location, so GPS is enabled
isGpsEnabled = true;

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<string name="prefs_gps_logging_min_distance_summary">Min. distance between track points in meters, use 0 for the shortest possible</string>
<string name="prefs_gps_logging_min_distance_meters">meters</string>
<string name="prefs_gps_logging_min_distance_empty">Min. distance between track points cannot be empty</string>
<string name="prefs_gps_min_accuracy">GPS minimum accuracy</string>
<string name="prefs_gps_min_accuracy_summary">Wait until accuracy is better than this value (in meters) to start recording. 0 to disable.</string>
<string name="prefs_gps_min_accuracy_dialog_title">Enter minimum accuracy (meters)</string>
<string name="prefs_ui">User interface</string>
<string name="prefs_ui_picture_source">Default photo source</string>
<string name="prefs_ui_picture_source_summary">Take photos from camera or gallery?</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
app:key="gps.logging.min_distance"
app:summary="@string/prefs_gps_logging_min_distance_summary"
app:title="@string/prefs_gps_logging_min_distance" />
<EditTextPreference
android:key="gps_min_accuracy"
android:defaultValue="0"
android:title="@string/prefs_gps_min_accuracy"
android:summary="@string/prefs_gps_min_accuracy_summary"
android:dialogTitle="@string/prefs_gps_min_accuracy_dialog_title"
android:inputType="number"
android:persistent="true" />
</PreferenceCategory>

<PreferenceCategory app:title="@string/prefs_output">
Expand Down