aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/DirectionProvider.java11
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java4
2 files changed, 14 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/DirectionProvider.java b/main/src/cgeo/geocaching/DirectionProvider.java
index 7bb940f..2f54b41 100644
--- a/main/src/cgeo/geocaching/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/DirectionProvider.java
@@ -60,4 +60,15 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
return Compatibility.getDirectionNow(direction, activity) % 360;
}
+ /**
+ * Return the angle to turn of to go from an angle to the other
+ *
+ * @param from the origin angle in degrees, in the [0, 360[ range
+ * @param to the target angle in degreees, in the [0, 360[ range
+ * @return a value in degrees, in the [-180, 180[ range
+ */
+ public static double difference(final double from, final double to) {
+ return (to - from + 360 + 180) % 360 - 180;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 6f5b8b9..56cba9d 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.ui;
+import cgeo.geocaching.DirectionProvider;
import cgeo.geocaching.R;
import cgeo.geocaching.utils.PeriodicHandler;
@@ -153,7 +154,8 @@ public class CompassView extends View {
public void act() {
final double newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
final double newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
- if (Math.abs(newAzimuthShown - azimuthShown) >= 2 || Math.abs(newCacheHeadingShown - cacheHeadingShown) >= 2) {
+ if (Math.abs(DirectionProvider.difference(azimuthShown, newAzimuthShown)) >= 2 ||
+ Math.abs(DirectionProvider.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
synchronized(CompassView.this) {
azimuthShown = newAzimuthShown;
cacheHeadingShown = newCacheHeadingShown;