forked from upstream-mirrors/OpenTracks
Cleanup: moved AggregatorGPS to GPSManager.
This commit is contained in:
@@ -43,6 +43,8 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
|
|||||||
private Duration gpsInterval;
|
private Duration gpsInterval;
|
||||||
private Distance thresholdHorizontalAccuracy;
|
private Distance thresholdHorizontalAccuracy;
|
||||||
|
|
||||||
|
private AggregatorGPS aggregatorGPS;
|
||||||
|
|
||||||
public GpsManager(TrackPointCreator trackPointCreator, SensorManager observer) {
|
public GpsManager(TrackPointCreator trackPointCreator, SensorManager observer) {
|
||||||
this.trackPointCreator = trackPointCreator;
|
this.trackPointCreator = trackPointCreator;
|
||||||
this.observer = observer;
|
this.observer = observer;
|
||||||
@@ -57,7 +59,7 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
|
|||||||
gpsStatusManager = new GpsStatusManager(context, this, handler);
|
gpsStatusManager = new GpsStatusManager(context, this, handler);
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
observer.onConnect(new AggregatorGPS("internal"));
|
this.aggregatorGPS = new AggregatorGPS("internal");
|
||||||
|
|
||||||
registerLocationListener();
|
registerLocationListener();
|
||||||
gpsStatusManager.start();
|
gpsStatusManager.start();
|
||||||
@@ -79,12 +81,24 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
|
|||||||
gpsStatusManager.stop();
|
gpsStatusManager.stop();
|
||||||
gpsStatusManager = null;
|
gpsStatusManager = null;
|
||||||
|
|
||||||
observer.onDisconnect(new AggregatorGPS("internal"));
|
this.aggregatorGPS = null;
|
||||||
observer = null;
|
observer = null;
|
||||||
|
|
||||||
trackPointCreator = null;
|
trackPointCreator = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Exposed for refactoring. Is this necessary?
|
||||||
|
@Deprecated
|
||||||
|
AggregatorGPS getAggregatorGPS() {
|
||||||
|
return aggregatorGPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Exposed for refactoring. This is very ugly.
|
||||||
|
@Deprecated
|
||||||
|
void setAggregatorGPS() {
|
||||||
|
this.aggregatorGPS = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
boolean registerListener = false;
|
boolean registerListener = false;
|
||||||
@@ -136,7 +150,8 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
observer.onChange(position);
|
aggregatorGPS.add(observer.getNow(), position);
|
||||||
|
observer.onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
if (cyclingPower != null) cyclingPower.resetAggregated();
|
if (cyclingPower != null) cyclingPower.resetAggregated();
|
||||||
if (runningDistanceSpeedCadence != null) runningDistanceSpeedCadence.resetAggregated();
|
if (runningDistanceSpeedCadence != null) runningDistanceSpeedCadence.resetAggregated();
|
||||||
if (barometer != null) barometer.resetAggregated();
|
if (barometer != null) barometer.resetAggregated();
|
||||||
if (gps != null) gps.resetAggregated();
|
if (gpsManager.getAggregatorGPS() != null) gpsManager.getAggregatorGPS().resetAggregated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GpsManager getGpsManager() {
|
public GpsManager getGpsManager() {
|
||||||
@@ -169,8 +169,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public AggregatorBarometer barometer;
|
public AggregatorBarometer barometer;
|
||||||
|
|
||||||
public AggregatorGPS gps;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public SensorData<HeartRate> getHeartRate(Instant now) {
|
public SensorData<HeartRate> getHeartRate(Instant now) {
|
||||||
if (heartRate != null) {
|
if (heartRate != null) {
|
||||||
@@ -227,6 +225,10 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public void onChange(Record data) {
|
public void onChange(Record data) {
|
||||||
update(data);
|
update(data);
|
||||||
|
onChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onChange() {
|
||||||
observer.onChange();
|
observer.onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,10 +268,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
this.barometer.add(now, (AtmosphericPressure) value);
|
this.barometer.add(now, (AtmosphericPressure) value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (value instanceof Position) {
|
|
||||||
this.gps.add(now, (Position) value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnsupportedOperationException(value.getClass().getCanonicalName());
|
throw new UnsupportedOperationException(value.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
@@ -289,10 +287,16 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
this.cyclingPower = null;
|
this.cyclingPower = null;
|
||||||
this.runningDistanceSpeedCadence = null;
|
this.runningDistanceSpeedCadence = null;
|
||||||
this.barometer = null;
|
this.barometer = null;
|
||||||
this.gps = null;
|
|
||||||
|
//TODO This is to ExportImportTest alive; refactor test.
|
||||||
|
if (this.gpsManager != null) {
|
||||||
|
this.gpsManager.setAggregatorGPS();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensorDataSet getSensorDataSet(Instant now) {
|
public SensorDataSet getSensorDataSet(Instant now) {
|
||||||
|
AggregatorGPS gps = gpsManager.getAggregatorGPS();
|
||||||
|
|
||||||
return new SensorDataSet(
|
return new SensorDataSet(
|
||||||
gps != null && gps.hasReceivedData() ? gps.getAggregatedValueWithSensorName(now) : new SensorData<>(Position.of(now), ""),
|
gps != null && gps.hasReceivedData() ? gps.getAggregatedValueWithSensorName(now) : new SensorData<>(Position.of(now), ""),
|
||||||
getSpeed(now),
|
getSpeed(now),
|
||||||
@@ -337,10 +341,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
barometer = (AggregatorBarometer) sensorData;
|
barometer = (AggregatorBarometer) sensorData;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type instanceof AggregatorGPS) {
|
|
||||||
gps = (AggregatorGPS) sensorData;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnsupportedOperationException(type.getClass().getCanonicalName());
|
throw new UnsupportedOperationException(type.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user