diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2015-01-08 14:48:06 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2015-01-08 14:48:06 +0100 |
commit | 6f30b1eec46cd9302d85ee9829f6867b16d6b88e (patch) | |
tree | 129ffc2245f9f6870fa3c1d35a2d4a33ed90aca8 /main | |
parent | a4ad5b06f249e8e1ac55bc7ad57ad497a4723b55 (diff) | |
download | cgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.zip cgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.tar.gz cgeo-6f30b1eec46cd9302d85ee9829f6867b16d6b88e.tar.bz2 |
fix #4603: do not query the magnetic field sensor
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/AboutActivity.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/CompassActivity.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/sensors/Sensors.java | 16 |
3 files changed, 9 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/AboutActivity.java b/main/src/cgeo/geocaching/AboutActivity.java index d7d60d2..ceafc31 100644 --- a/main/src/cgeo/geocaching/AboutActivity.java +++ b/main/src/cgeo/geocaching/AboutActivity.java @@ -266,7 +266,7 @@ public class AboutActivity extends AbstractViewPagerActivity<AboutActivity.Page> } body .append("\nLow power mode: ").append(Settings.useLowPowerMode() ? "active" : "inactive") - .append("\nMagnetic field sensor: ").append(presence(Sensors.getInstance().hasMagneticFieldSensor())) + .append("\nCompass capabilities: ").append(Sensors.getInstance().hasCompassCapabilities() ? "yes" : "no") .append("\nRotation sensor: ").append(presence(RotationProvider.hasRotationSensor(context))) .append("\nGeomagnetic rotation sensor: ").append(presence(RotationProvider.hasGeomagneticRotationSensor(context))) .append("\nOrientation sensor: ").append(presence(OrientationProvider.hasOrientationSensor(context))) diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java index 8b0fc73..27dbb4a 100644 --- a/main/src/cgeo/geocaching/CompassActivity.java +++ b/main/src/cgeo/geocaching/CompassActivity.java @@ -139,7 +139,7 @@ public class CompassActivity extends AbstractActionBarActivity { @Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.compass_activity_options, menu); - menu.findItem(R.id.menu_compass_sensor).setVisible(Sensors.getInstance().hasMagneticFieldSensor()); + menu.findItem(R.id.menu_compass_sensor).setVisible(Sensors.getInstance().hasCompassCapabilities()); if (cache != null) { LoggingUI.addMenuItems(this, menu, cache); } 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; } } |