aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/DirectionProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/DirectionProvider.java')
-rw-r--r--main/src/cgeo/geocaching/DirectionProvider.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/DirectionProvider.java b/main/src/cgeo/geocaching/DirectionProvider.java
index 7bb940f..14fd283 100644
--- a/main/src/cgeo/geocaching/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/DirectionProvider.java
@@ -14,6 +14,12 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
private final SensorManager sensorManager;
+ // Previous values signalled to observers to avoid resending the same value when the
+ // device doesn't change orientation. The orientation is usually given with a 1 degree
+ // precision by Android, so it is not uncommon to obtain exactly the same value several
+ // times.
+ private float previous = -1;
+
public DirectionProvider(final Context context) {
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
@@ -46,7 +52,11 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
@Override
public void onSensorChanged(final SensorEvent event) {
- notifyObservers(event.values[0]);
+ final float direction = event.values[0];
+ if (direction != previous) {
+ notifyObservers(direction);
+ previous = direction;
+ }
}
/**
@@ -57,7 +67,7 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
* @return the adjusted direction in degrees, in the [0, 360[ range
*/
public static float getDirectionNow(final Activity activity, final float direction) {
- return Compatibility.getDirectionNow(direction, activity) % 360;
+ return Compatibility.getDirectionNow(direction, activity);
}
}