Skip to content
Open
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
2 changes: 2 additions & 0 deletions app/src/main/java/net/osmtracker/OSMTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static final class Preferences {
public final static String KEY_GPS_IGNORE_CLOCK = "gps.ignoreclock";
public final static String KEY_GPS_LOGGING_INTERVAL = "gps.logging.interval";
public final static String KEY_GPS_LOGGING_MIN_DISTANCE = "gps.logging.min_distance";
public static final String KEY_GPS_LOGGING_MIN_ACCURACY = "gps.logging.min.accuracy";
public final static String KEY_USE_BAROMETER = "gpx.use_barometer";
public final static String KEY_USE_NOTES = "gpx.notes";
public final static String KEY_OUTPUT_FILENAME = "gpx.filename";
Expand Down Expand Up @@ -61,6 +62,7 @@ public static final class Preferences {
public final static boolean VAL_GPS_IGNORE_CLOCK = false;
public final static String VAL_GPS_LOGGING_INTERVAL = "0";
public final static String VAL_GPS_LOGGING_MIN_DISTANCE = "0";
public static final String VAL_GPS_LOGGING_MIN_ACCURACY = "0";
public final static boolean VAL_USE_BAROMETER = false;
public final static String VAL_USE_NOTES = "both";

Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/net/osmtracker/activity/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.osmtracker.R;

import java.io.File;
import java.util.Objects;

/**
* Manages preferences screen
Expand Down Expand Up @@ -90,7 +89,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getString(R.string.prefs_gps_logging_min_distance_empty),
OSMTracker.Preferences.VAL_GPS_LOGGING_MIN_DISTANCE
);

// GPS Logging Minimum Accuracy
setupEditTextNum(
OSMTracker.Preferences.KEY_GPS_LOGGING_MIN_ACCURACY,
getString(R.string.prefs_gps_logging_min_distance_meters),
getString(R.string.prefs_gps_min_accuracy_summary),
getString(R.string.prefs_gps_min_accuracy_empty),
OSMTracker.Preferences.VAL_GPS_LOGGING_MIN_ACCURACY
);

// GPX Settings
setupStorageDirectory();
Expand Down Expand Up @@ -229,7 +235,7 @@ private void setupOSMAuthClearData(SharedPreferences prefs) {
}

/**
* Setup a preference that launches an activity via Intent
* Set up a preference that launches an activity via Intent
* @param preferenceKey The preference key
* @param intent The intent to launch
*/
Expand Down Expand Up @@ -335,7 +341,7 @@ public void onFragmentStarted(


/**
* Setup a ListPreference with a custom two lines summary, displays the selected entry
* Set up a ListPreference with a custom two lines summary, displays the selected entry
* on the first line, and the static summary on the second line.
*
* @param preferenceKey preference identifier
Expand Down
49 changes: 48 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,19 @@ 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;

/**
* Precision of the accuracy in meters is satisfied ?
*/
private boolean isAccuracySatisfied = false;

/**
* Use barometer yes/no ?
Expand Down Expand Up @@ -98,6 +113,10 @@ public class GPSLogger extends Service implements LocationListener {
*/
private long gpsLoggingInterval;
private long gpsLoggingMinDistance;
/**
* Minimum accuracy in meters for starting defined in the preferences
*/
private long gpsLoggingMinAccuracy;

/**
* sensors for magnetic orientation
Expand Down Expand Up @@ -252,9 +271,24 @@ public void onCreate() {
OSMTracker.Preferences.KEY_GPS_LOGGING_INTERVAL, OSMTracker.Preferences.VAL_GPS_LOGGING_INTERVAL)) * 1000;
gpsLoggingMinDistance = Long.parseLong(PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString(
OSMTracker.Preferences.KEY_GPS_LOGGING_MIN_DISTANCE, OSMTracker.Preferences.VAL_GPS_LOGGING_MIN_DISTANCE));
gpsLoggingMinAccuracy = Long.parseLong(PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString(
OSMTracker.Preferences.KEY_GPS_LOGGING_MIN_ACCURACY, OSMTracker.Preferences.VAL_GPS_LOGGING_MIN_ACCURACY));
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(
OSMTracker.Preferences.KEY_GPS_MIN_ACCURACY,
OSMTracker.Preferences.VAL_GPS_MIN_ACCURACY));
} catch (NumberFormatException e) {
minAccuracy = Integer.parseInt(OSMTracker.Preferences.VAL_GPS_MIN_ACCURACY);
}
// minimum precision enabled
if (minAccuracy == 0) {
isAccuracySatisfied = true;
}
// Register our broadcast receiver
IntentFilter filter = new IntentFilter();
filter.addAction(OSMTracker.INTENT_TRACK_WP);
Expand Down Expand Up @@ -342,7 +376,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() <= gpsLoggingMinAccuracy){
// 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
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<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_gps_min_accuracy_empty">GPS logging accuracy cannot be empty</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
7 changes: 7 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,13 @@
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:inputType="number"
app:defaultValue="0"
app:key="gps.logging.min.accuracy"
app:summary="@string/prefs_gps_min_accuracy_summary"
app:title="@string/prefs_gps_min_accuracy"
app:dialogTitle="@string/prefs_gps_min_accuracy_dialog_title" />
</PreferenceCategory>

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