aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sensors/Sensors.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2015-01-08 14:48:06 +0100
committerSamuel Tardieu <sam@rfc1149.net>2015-01-08 14:48:06 +0100
commit6f30b1eec46cd9302d85ee9829f6867b16d6b88e (patch)
tree129ffc2245f9f6870fa3c1d35a2d4a33ed90aca8 /main/src/cgeo/geocaching/sensors/Sensors.java
parenta4ad5b06f249e8e1ac55bc7ad57ad497a4723b55 (diff)
downloadcgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.zip
cgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.tar.gz
cgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.tar.bz2
fix #4603: do not query the magnetic field sensor
Diffstat (limited to 'main/src/cgeo/geocaching/sensors/Sensors.java')
-rw-r--r--main/src/cgeo/geocaching/sensors/Sensors.java16
1 files changed, 7 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/sensors/Sensors.java b/main/src/cgeo/geocaching/sensors/Sensors.java
index 498ec0e..80ed175 100644
--- a/main/src/cgeo/geocaching/sensors/Sensors.java
+++ b/main/src/cgeo/geocaching/sensors/Sensors.java
@@ -15,8 +15,6 @@ import rx.functions.Action1;
import rx.functions.Func1;
import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -29,7 +27,7 @@ public class Sensors {
@NonNull private volatile GeoData currentGeo = GeoData.DUMMY_LOCATION;
private volatile float currentDirection = 0.0f;
private volatile boolean hasValidLocation = false;
- private final boolean hasMagneticFieldSensor;
+ private final boolean hasCompassCapabilities;
private final CgeoApplication app = CgeoApplication.getInstance();
private static class InstanceHolder {
@@ -53,8 +51,8 @@ public class Sensors {
private Sensors() {
gpsStatusObservable = GpsStatusProvider.create(app).replay(1).refCount();
- final SensorManager sensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
- hasMagneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null;
+ final Context context = CgeoApplication.getInstance().getApplicationContext();
+ hasCompassCapabilities = RotationProvider.hasRotationSensor(context) || OrientationProvider.hasOrientationSensor(context);
}
public static final Sensors getInstance() {
@@ -84,8 +82,8 @@ public class Sensors {
public void setupDirectionObservable(final boolean useLowPower) {
// If we have no magnetic sensor, there is no point in trying to setup any, we will always get the direction from the GPS.
- if (!hasMagneticFieldSensor) {
- Log.i("No magnetic field sensor, using only the GPS for the orientation");
+ if (!hasCompassCapabilities) {
+ Log.i("No compass capabilities, using only the GPS for the orientation");
directionObservable = RxUtils.rememberLast(geoDataObservableLowPower.map(GPS_TO_DIRECTION).doOnNext(onNextrememberDirectionAction), 0f);
return;
}
@@ -153,8 +151,8 @@ public class Sensors {
return currentDirection;
}
- public boolean hasMagneticFieldSensor() {
- return hasMagneticFieldSensor;
+ public boolean hasCompassCapabilities() {
+ return hasCompassCapabilities;
}
}