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