forked from upstream-mirrors/OpenTracks
Cleanup: horizontal accuracy is now a Distance (and named consistently).
This commit is contained in:
@@ -49,7 +49,8 @@ public final class Marker {
|
||||
private final Instant time;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float accuracy;
|
||||
@Deprecated //Not needed
|
||||
private Distance accuracy;
|
||||
private Altitude altitude;
|
||||
private Float bearing;
|
||||
|
||||
@@ -96,7 +97,7 @@ public final class Marker {
|
||||
public void setTrackPoint(TrackPoint trackPoint) {
|
||||
this.latitude = trackPoint.getLatitude();
|
||||
this.longitude = trackPoint.getLongitude();
|
||||
if (trackPoint.hasAccuracy()) this.accuracy = trackPoint.getAccuracy();
|
||||
if (trackPoint.hasHorizontalAccuracy()) this.accuracy = trackPoint.getHorizontalAccuracy();
|
||||
if (trackPoint.hasAltitude()) this.altitude = trackPoint.getAltitude();
|
||||
if (trackPoint.hasBearing()) this.bearing = trackPoint.getBearing();
|
||||
}
|
||||
@@ -173,7 +174,7 @@ public final class Marker {
|
||||
location.setBearing(bearing);
|
||||
}
|
||||
if (hasAccuracy()) {
|
||||
location.setAccuracy(accuracy);
|
||||
location.setAccuracy((float) accuracy.toM());
|
||||
}
|
||||
if (hasAltitude()) {
|
||||
location.setAltitude(altitude.toM());
|
||||
@@ -202,11 +203,11 @@ public final class Marker {
|
||||
return accuracy != null;
|
||||
}
|
||||
|
||||
public Float getAccuracy() {
|
||||
public Distance getAccuracy() {
|
||||
return accuracy;
|
||||
}
|
||||
|
||||
public void setAccuracy(Float accuracy) {
|
||||
public void setAccuracy(Distance accuracy) {
|
||||
this.accuracy = accuracy;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TrackPoint {
|
||||
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float accuracy;
|
||||
private Distance horizontalAccuracy;
|
||||
private Altitude altitude;
|
||||
private Speed speed;
|
||||
private Float bearing;
|
||||
@@ -112,7 +112,7 @@ public class TrackPoint {
|
||||
this.longitude = location.getLongitude();
|
||||
this.altitude = location.hasAltitude() ? Altitude.WGS84.of(location.getAltitude()) : null;
|
||||
this.speed = location.hasSpeed() ? Speed.of(location.getSpeed()) : null;
|
||||
this.accuracy = location.hasAccuracy() ? location.getAccuracy() : null;
|
||||
this.horizontalAccuracy = location.hasAccuracy() ? Distance.of(location.getAccuracy()) : null;
|
||||
|
||||
//TODO Should we copy the bearing?
|
||||
}
|
||||
@@ -197,8 +197,8 @@ public class TrackPoint {
|
||||
if (hasBearing()) {
|
||||
location.setBearing(bearing);
|
||||
}
|
||||
if (hasAccuracy()) {
|
||||
location.setAccuracy(accuracy);
|
||||
if (hasHorizontalAccuracy()) {
|
||||
location.setAccuracy((float) horizontalAccuracy.toM());
|
||||
}
|
||||
if (hasAltitude()) {
|
||||
location.setAltitude(altitude.toM());
|
||||
@@ -293,16 +293,16 @@ public class TrackPoint {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasAccuracy() {
|
||||
return accuracy != null;
|
||||
public boolean hasHorizontalAccuracy() {
|
||||
return horizontalAccuracy != null;
|
||||
}
|
||||
|
||||
public float getAccuracy() {
|
||||
return accuracy;
|
||||
public Distance getHorizontalAccuracy() {
|
||||
return horizontalAccuracy;
|
||||
}
|
||||
|
||||
public TrackPoint setAccuracy(float horizontalAccuracy) {
|
||||
this.accuracy = horizontalAccuracy;
|
||||
public TrackPoint setHorizontalAccuracy(Distance horizontalAccuracy) {
|
||||
this.horizontalAccuracy = horizontalAccuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -318,8 +318,8 @@ public class TrackPoint {
|
||||
return Distance.of(getLocation().distanceTo(previous.getLocation()));
|
||||
}
|
||||
|
||||
public boolean fulfillsAccuracy(int poorAccuracy) {
|
||||
return hasAccuracy() && accuracy < poorAccuracy;
|
||||
public boolean fulfillsAccuracy(Distance thresholdHorizontalAccuracy) {
|
||||
return hasHorizontalAccuracy() && horizontalAccuracy.lessThan(thresholdHorizontalAccuracy);
|
||||
}
|
||||
|
||||
//TODO Bearing requires a location; what do we do if we don't have any?
|
||||
@@ -397,11 +397,11 @@ public class TrackPoint {
|
||||
return result;
|
||||
}
|
||||
result += ": lat=" + getLatitude() + " lng=" + getLongitude();
|
||||
if (!hasAccuracy()) {
|
||||
if (!hasHorizontalAccuracy()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result + " acc=" + getAccuracy();
|
||||
return result + " acc=" + getHorizontalAccuracy();
|
||||
}
|
||||
|
||||
public static class Id {
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface TrackPointsColumns extends BaseColumns {
|
||||
|
||||
String TIME = "time";
|
||||
String ALTITUDE = "elevation";
|
||||
String ACCURACY = "accuracy";
|
||||
String HORIZONTAL_ACCURACY = "accuracy";
|
||||
String SPEED = "speed";
|
||||
String BEARING = "bearing";
|
||||
String SENSOR_HEARTRATE = "sensor_heartrate";
|
||||
@@ -69,7 +69,7 @@ public interface TrackPointsColumns extends BaseColumns {
|
||||
+ LATITUDE + " INTEGER, "
|
||||
+ TIME + " INTEGER, "
|
||||
+ ALTITUDE + " FLOAT, "
|
||||
+ ACCURACY + " FLOAT, "
|
||||
+ HORIZONTAL_ACCURACY + " FLOAT, "
|
||||
+ SPEED + " FLOAT, "
|
||||
+ BEARING + " FLOAT, "
|
||||
+ SENSOR_HEARTRATE + " FLOAT, "
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class CachedTrackPointsIndexes {
|
||||
latitudeIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.LATITUDE);
|
||||
timeIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.TIME);
|
||||
altitudeIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALTITUDE);
|
||||
accuracyIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.ACCURACY);
|
||||
accuracyIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.HORIZONTAL_ACCURACY);
|
||||
speedIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.SPEED);
|
||||
bearingIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.BEARING);
|
||||
sensorHeartRateIndex = cursor.getColumnIndexOrThrow(TrackPointsColumns.SENSOR_HEARTRATE);
|
||||
|
||||
@@ -318,7 +318,7 @@ public class ContentProviderUtils {
|
||||
marker.setAltitude(Altitude.WGS84.of(cursor.getFloat(altitudeIndex)));
|
||||
}
|
||||
if (!cursor.isNull(accuracyIndex)) {
|
||||
marker.setAccuracy(cursor.getFloat(accuracyIndex));
|
||||
marker.setAccuracy(Distance.of(cursor.getFloat(accuracyIndex)));
|
||||
}
|
||||
if (!cursor.isNull(bearingIndex)) {
|
||||
marker.setBearing(cursor.getFloat(bearingIndex));
|
||||
@@ -472,7 +472,7 @@ public class ContentProviderUtils {
|
||||
values.put(MarkerColumns.ALTITUDE, marker.getAltitude().toM());
|
||||
}
|
||||
if (marker.hasAccuracy()) {
|
||||
values.put(MarkerColumns.ACCURACY, marker.getAccuracy());
|
||||
values.put(MarkerColumns.ACCURACY, marker.getAccuracy().toM());
|
||||
}
|
||||
if (marker.hasBearing()) {
|
||||
values.put(MarkerColumns.BEARING, marker.getBearing());
|
||||
@@ -520,7 +520,7 @@ public class ContentProviderUtils {
|
||||
trackPoint.setAltitude(Altitude.WGS84.of(cursor.getFloat(indexes.altitudeIndex)));
|
||||
}
|
||||
if (!cursor.isNull(indexes.accuracyIndex)) {
|
||||
trackPoint.setAccuracy(cursor.getFloat(indexes.accuracyIndex));
|
||||
trackPoint.setHorizontalAccuracy(Distance.of(cursor.getFloat(indexes.accuracyIndex)));
|
||||
}
|
||||
if (!cursor.isNull(indexes.speedIndex)) {
|
||||
trackPoint.setSpeed(Speed.of(cursor.getFloat(indexes.speedIndex)));
|
||||
@@ -681,8 +681,8 @@ public class ContentProviderUtils {
|
||||
if (trackPoint.hasAltitude()) {
|
||||
values.put(TrackPointsColumns.ALTITUDE, trackPoint.getAltitude().toM());
|
||||
}
|
||||
if (trackPoint.hasAccuracy()) {
|
||||
values.put(TrackPointsColumns.ACCURACY, trackPoint.getAccuracy());
|
||||
if (trackPoint.hasHorizontalAccuracy()) {
|
||||
values.put(TrackPointsColumns.HORIZONTAL_ACCURACY, trackPoint.getHorizontalAccuracy().toM());
|
||||
}
|
||||
if (trackPoint.hasSpeed()) {
|
||||
values.put(TrackPointsColumns.SPEED, trackPoint.getSpeed().toMPS());
|
||||
|
||||
@@ -492,7 +492,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy) {
|
||||
public void newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
||||
if (!isRecording() || isPaused()) {
|
||||
Log.w(TAG, "Ignore newTrackPoint. Not recording or paused.");
|
||||
return;
|
||||
@@ -504,7 +504,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
return;
|
||||
}
|
||||
|
||||
notificationManager.updateTrackPoint(this, track.getTrackStatistics(), trackPoint, recordingGpsAccuracy);
|
||||
notificationManager.updateTrackPoint(this, track.getTrackStatistics(), trackPoint, thresholdHorizontalAccuracy);
|
||||
|
||||
//TODO Figure out how to avoid loading the lastValidTrackPoint from the database
|
||||
TrackPoint lastValidTrackPoint = getLastValidTrackPointInCurrentSegment(track.getId());
|
||||
|
||||
+4
-4
@@ -65,12 +65,12 @@ class TrackRecordingServiceNotificationManager {
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
void updateTrackPoint(Context context, TrackStatistics trackStatistics, TrackPoint trackPoint, int recordingGpsAccuracy) {
|
||||
void updateTrackPoint(Context context, TrackStatistics trackStatistics, TrackPoint trackPoint, Distance recordingGpsAccuracy) {
|
||||
String formattedAccuracy = context.getString(R.string.value_none);
|
||||
if (trackPoint.hasAccuracy()) {
|
||||
formattedAccuracy = StringUtils.formatDistance(context, Distance.of(trackPoint.getAccuracy()), metricUnits);
|
||||
if (trackPoint.hasHorizontalAccuracy()) {
|
||||
formattedAccuracy = StringUtils.formatDistance(context, trackPoint.getHorizontalAccuracy(), metricUnits);
|
||||
|
||||
boolean currentLocationWasAccurate = trackPoint.getAccuracy() < recordingGpsAccuracy;
|
||||
boolean currentLocationWasAccurate = trackPoint.getHorizontalAccuracy().lessThan(recordingGpsAccuracy);
|
||||
boolean shouldAlert = !currentLocationWasAccurate && previousLocationWasAccurate;
|
||||
notificationBuilder.setOnlyAlertOnce(!shouldAlert);
|
||||
previousLocationWasAccurate = currentLocationWasAccurate;
|
||||
|
||||
@@ -5,11 +5,13 @@ import android.content.SharedPreferences;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
|
||||
@@ -24,8 +26,7 @@ class GpsStatus {
|
||||
// The duration that GpsStatus waits from minimal interval to consider GPS lost.
|
||||
private static final Duration SIGNAL_LOST_THRESHOLD = Duration.ofSeconds(10);
|
||||
|
||||
// Threshold for accuracy.
|
||||
private double signalBadThreshold; //TODO Distance?
|
||||
private Distance thresholdHorizontalAccuracy;
|
||||
// Threshold for time without points.
|
||||
private Duration signalLostThreshold;
|
||||
|
||||
@@ -68,7 +69,7 @@ class GpsStatus {
|
||||
this.context = context;
|
||||
|
||||
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||
signalBadThreshold = PreferencesUtils.getRecordingDistanceInterval(sharedPreferences, context).toM();
|
||||
thresholdHorizontalAccuracy = PreferencesUtils.getRecordingDistanceInterval(sharedPreferences, context);
|
||||
|
||||
Duration minRecordingInterval = Duration.ofSeconds(PreferencesUtils.getMinRecordingInterval(sharedPreferences, context));
|
||||
signalLostThreshold = !minRecordingInterval.isNegative() ? SIGNAL_LOST_THRESHOLD.plus(minRecordingInterval) : SIGNAL_LOST_THRESHOLD;
|
||||
@@ -97,8 +98,8 @@ class GpsStatus {
|
||||
*
|
||||
* @param value New preference value to signalBadThreshold.
|
||||
*/
|
||||
public void onRecordingDistanceChanged(int value) {
|
||||
signalBadThreshold = value;
|
||||
public void onRecordingDistanceChanged(@NonNull Distance value) {
|
||||
thresholdHorizontalAccuracy = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,13 +148,13 @@ class GpsStatus {
|
||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_LOST;
|
||||
sendStatus(oldStatus, gpsStatus);
|
||||
stopStatusRunner();
|
||||
} else if (lastTrackPoint.getAccuracy() > signalBadThreshold && gpsStatus != GpsStatusValue.GPS_SIGNAL_BAD) {
|
||||
} else if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_BAD) {
|
||||
// Too little accuracy -> bad signal.
|
||||
GpsStatusValue oldStatus = gpsStatus;
|
||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_BAD;
|
||||
sendStatus(oldStatus, gpsStatus);
|
||||
startStatusRunner();
|
||||
} else if (lastTrackPoint.getAccuracy() <= signalBadThreshold && gpsStatus != GpsStatusValue.GPS_SIGNAL_FIX) {
|
||||
} else if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_FIX) {
|
||||
// Gps okay.
|
||||
GpsStatusValue oldStatus = gpsStatus;
|
||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_FIX;
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
@@ -110,7 +111,7 @@ public class HandlerServer {
|
||||
locationHandler.onSharedPreferenceChanged(context, preferences, key);
|
||||
}
|
||||
|
||||
public void onNewTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy) {
|
||||
public void onNewTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
||||
// if (serviceExecutor == null || serviceExecutor.isTerminated() || serviceExecutor.isShutdown()) {
|
||||
// return;
|
||||
// }
|
||||
@@ -119,8 +120,8 @@ public class HandlerServer {
|
||||
fillAndReset(trackPoint);
|
||||
|
||||
|
||||
// serviceExecutor.execute(() -> service.newTrackPoint(trackPoint, recordingGpsAccuracy));
|
||||
service.newTrackPoint(trackPoint, recordingGpsAccuracy);
|
||||
// serviceExecutor.execute(() -> service.newTrackPoint(trackPoint, thresholdHorizontalAccuracy));
|
||||
service.newTrackPoint(trackPoint, thresholdHorizontalAccuracy);
|
||||
}
|
||||
|
||||
public TrackPoint createSegmentStartManual() {
|
||||
@@ -176,7 +177,7 @@ public class HandlerServer {
|
||||
}
|
||||
|
||||
public interface HandlerServerInterface {
|
||||
void newTrackPoint(TrackPoint trackPoint, int gpsAccuracy);
|
||||
void newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy);
|
||||
|
||||
void newGpsStatus(GpsStatusValue gpsStatusValue);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.annotation.NonNull;
|
||||
import java.time.Duration;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.util.LocationUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
@@ -26,7 +27,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
|
||||
private GpsStatus gpsStatus;
|
||||
private LocationListenerPolicy locationListenerPolicy;
|
||||
private Duration currentRecordingInterval;
|
||||
private int recordingGpsAccuracy;
|
||||
private Distance thresholdHorizontalAccuracy;
|
||||
private TrackPoint lastValidTrackPoint;
|
||||
|
||||
public LocationHandler(HandlerServer handlerServer) {
|
||||
@@ -69,7 +70,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
|
||||
registerLocationListener();
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.recording_gps_accuracy_key, key)) {
|
||||
recordingGpsAccuracy = PreferencesUtils.getRecordingGPSAccuracy(sharedPreferences, context);
|
||||
thresholdHorizontalAccuracy = PreferencesUtils.getThresholdHorizontalAccuracy(sharedPreferences, context);
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.min_recording_interval_key, key)) {
|
||||
if (gpsStatus != null) {
|
||||
@@ -78,7 +79,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.recording_distance_interval_key, key)) {
|
||||
if (gpsStatus != null) {
|
||||
gpsStatus.onRecordingDistanceChanged((int) PreferencesUtils.getRecordingDistanceInterval(sharedPreferences, context).toM()); //TODO Use Distance?
|
||||
gpsStatus.onRecordingDistanceChanged(PreferencesUtils.getRecordingDistanceInterval(sharedPreferences, context));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +92,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
|
||||
@Override
|
||||
public void onLocationChanged(@NonNull Location location) {
|
||||
TrackPoint trackPoint = new TrackPoint(location, handlerServer.createNow());
|
||||
boolean isAccurate = trackPoint.fulfillsAccuracy(recordingGpsAccuracy);
|
||||
boolean isAccurate = trackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy);
|
||||
boolean isValid = LocationUtils.isValidLocation(location);
|
||||
|
||||
if (gpsStatus != null) {
|
||||
@@ -119,7 +120,7 @@ class LocationHandler implements LocationListener, GpsStatus.GpsStatusListener {
|
||||
}
|
||||
|
||||
lastValidTrackPoint = trackPoint;
|
||||
handlerServer.onNewTrackPoint(trackPoint, recordingGpsAccuracy);
|
||||
handlerServer.onNewTrackPoint(trackPoint, thresholdHorizontalAccuracy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -247,9 +247,9 @@ public class PreferencesUtils {
|
||||
return Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_default));
|
||||
}
|
||||
|
||||
public static int getRecordingGPSAccuracy(SharedPreferences sharedPreferences, Context context) {
|
||||
public static Distance getThresholdHorizontalAccuracy(SharedPreferences sharedPreferences, Context context) {
|
||||
final int RECORDING_GPS_ACCURACY = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_default));
|
||||
return getInt(sharedPreferences, context, R.string.recording_gps_accuracy_key, RECORDING_GPS_ACCURACY);
|
||||
return Distance.of(getInt(sharedPreferences, context, R.string.recording_gps_accuracy_key, RECORDING_GPS_ACCURACY));
|
||||
}
|
||||
|
||||
public static boolean shouldInstantExportAfterWorkout(SharedPreferences sharedPreferences, Context context) {
|
||||
|
||||
Reference in New Issue
Block a user