forked from upstream-mirrors/OpenTracks
@@ -45,8 +45,9 @@ public class GpsHandler extends SensorHandler<Location, Position> {
|
||||
gpsStatusManager.onMinSamplingIntervalChanged(PreferencesUtils.getMinSamplingInterval());
|
||||
}
|
||||
|
||||
//TODO
|
||||
connect();
|
||||
if (driver != null) {
|
||||
driver.updateDriverParameters(getContext(), sensorManager.getHandler());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ public abstract class SensorHandler<AggregatorInput, AggregatorOutput> implement
|
||||
|
||||
private static final String TAG = SensorHandler.class.getSimpleName();
|
||||
|
||||
private final SensorManager sensorManager;
|
||||
|
||||
@VisibleForTesting
|
||||
public Driver driver;
|
||||
|
||||
protected final SensorManager sensorManager;
|
||||
|
||||
protected Aggregator<AggregatorInput, AggregatorOutput> aggregator;
|
||||
|
||||
protected SensorHandler(SensorManager sensorManager) {
|
||||
|
||||
@@ -11,5 +11,9 @@ public interface Driver {
|
||||
//TODO Remove from interface?
|
||||
boolean isConnected();
|
||||
|
||||
default void updateDriverParameters(Context context, Handler handler) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
void disconnect();
|
||||
}
|
||||
|
||||
@@ -57,16 +57,11 @@ public class GpsInternal implements Driver {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationRequestCompat locationRequest = new LocationRequestCompat.Builder(PreferencesUtils.getMinSamplingInterval().toMillis())
|
||||
.setQuality(LocationRequestCompat.QUALITY_HIGH_ACCURACY)
|
||||
.setMaxUpdateDelayMillis(0)
|
||||
.build();
|
||||
|
||||
if (PermissionRequester.GPS.hasPermission(context)) {
|
||||
try {
|
||||
Log.i(TAG, "Register for location updates " + context);
|
||||
Log.i(TAG, "Register for location updates");
|
||||
driverObserver.onConnected(null, null);
|
||||
LocationManagerCompat.requestLocationUpdates(locationManager, LOCATION_PROVIDER, locationRequest, handler::post, locationListenerCompat);
|
||||
LocationManagerCompat.requestLocationUpdates(locationManager, LOCATION_PROVIDER, createLocationRequest(), handler::post, locationListenerCompat);
|
||||
return;
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Could not register location listener; permissions not granted.", e);
|
||||
@@ -76,6 +71,16 @@ public class GpsInternal implements Driver {
|
||||
driverObserver.onDisconnected();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MissingPermission"})
|
||||
@Override
|
||||
public void updateDriverParameters(Context context, Handler handler) {
|
||||
if (!isConnected()) return;
|
||||
|
||||
Log.i(TAG, "Update for location updates");
|
||||
driverObserver.onConnected(null, null);
|
||||
LocationManagerCompat.requestLocationUpdates(locationManager, LOCATION_PROVIDER, createLocationRequest(), handler::post, locationListenerCompat);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MissingPermission"})
|
||||
@Override
|
||||
public void disconnect() {
|
||||
@@ -87,9 +92,15 @@ public class GpsInternal implements Driver {
|
||||
driverObserver.onDisconnected();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return locationManager != null;
|
||||
}
|
||||
|
||||
private LocationRequestCompat createLocationRequest() {
|
||||
return new LocationRequestCompat.Builder(PreferencesUtils.getMinSamplingInterval().toMillis())
|
||||
.setQuality(LocationRequestCompat.QUALITY_HIGH_ACCURACY)
|
||||
.setMaxUpdateDelayMillis(0)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user