diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2015-01-08 16:05:47 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2015-01-08 16:05:47 +0100 |
| commit | fcce011590c5717344544322975eb79ce7d1ffc5 (patch) | |
| tree | dc04810b2cea73db81e2f51b242d8fe2555edb5a /main/src | |
| parent | 0746334491ceeb12e881c854b87b3b0391492596 (diff) | |
| download | cgeo-fcce011590c5717344544322975eb79ce7d1ffc5.zip cgeo-fcce011590c5717344544322975eb79ce7d1ffc5.tar.gz cgeo-fcce011590c5717344544322975eb79ce7d1ffc5.tar.bz2 | |
Favor the orientation sensor over the rotation one
On some devices, it looks like the orientation sensor may be bogus. This
confirms what the author of GPS Status wrote in private mail.
This commits favors the rotation sensor over the orientation one, unless
low-power mode is used, in which case the orientation sensor (which may
benefit from low-power mode if it has a gyroscope-less mode) will be
preferred.
Part of work on #4599.
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/sensors/Sensors.java | 16 |
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 80ed175..7a85ccb 100644 --- a/main/src/cgeo/geocaching/sensors/Sensors.java +++ b/main/src/cgeo/geocaching/sensors/Sensors.java @@ -89,18 +89,16 @@ public class Sensors { } // Combine the magnetic direction observable with the GPS when compass is disabled or speed is high enough. - final AtomicBoolean useDirectionFromGps = new AtomicBoolean(false); - final Observable<Float> magneticDirectionObservable = RotationProvider.create(app, useLowPower).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() { - @Override - public Observable<? extends Float> call(final Throwable throwable) { - return OrientationProvider.create(app); - } - }).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() { + // The rotation sensor seems to be bogus on some devices. We should start with the orientation one, except when we explicitely + // want to use the low-power geomagnetic rotation sensor or when we do not have an orientation sensor. + final boolean useRotationSensor = (Settings.useLowPowerMode() && RotationProvider.hasGeomagneticRotationSensor(app)) || !OrientationProvider.hasOrientationSensor(app); + final Observable<Float> sensorDirectionObservable = useRotationSensor ? RotationProvider.create(app, useLowPower) : OrientationProvider.create(app); + final Observable<Float> magneticDirectionObservable = sensorDirectionObservable.onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() { @Override public Observable<? extends Float> call(final Throwable throwable) { - Log.e("Device orientation will not be available as no suitable sensors were found, disabling compass"); + Log.e("Device orientation is not available due to sensors error, disabling compass", throwable); Settings.setUseCompass(false); return Observable.<Float>never().startWith(0.0f); } @@ -111,7 +109,7 @@ public class Sensors { } }); - final Observable<Float> directionFromGpsObservable = geoDataObservable(true).filter(new Func1<GeoData, Boolean>() { + final Observable<Float> directionFromGpsObservable = geoDataObservableLowPower.filter(new Func1<GeoData, Boolean>() { @Override public Boolean call(final GeoData geoData) { final boolean useGps = geoData.getSpeed() > 5.0f; |
