diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-30 21:00:52 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-05-31 17:46:11 +0200 |
commit | aaa264d1748a9f399352e28f916ad579e4facf19 (patch) | |
tree | 62b1055fe51f67cd9e863faabcc1584ebf41d1b4 /main/src/cgeo/geocaching/ui | |
parent | 33ef283c045d49765784d46589139d7b1f8bda65 (diff) | |
download | cgeo-aaa264d1748a9f399352e28f916ad579e4facf19.zip cgeo-aaa264d1748a9f399352e28f916ad579e4facf19.tar.gz cgeo-aaa264d1748a9f399352e28f916ad579e4facf19.tar.bz2 |
fix #1680: compass gets stuck after some rotations
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r-- | main/src/cgeo/geocaching/ui/CompassMiniView.java | 4 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/ui/CompassView.java | 12 |
2 files changed, 5 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java index a60afa6..8c7c52e 100644 --- a/main/src/cgeo/geocaching/ui/CompassMiniView.java +++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java @@ -159,11 +159,9 @@ final public class CompassMiniView extends View { } private float calculateAzimuthRelative() { - float azimuthRelative = azimuth - heading; + float azimuthRelative = (azimuth - heading) % 360; if (azimuthRelative < 0) { azimuthRelative += 360; - } else if (azimuthRelative >= 360) { - azimuthRelative -= 360; } return azimuthRelative; } diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java index 770bbaf..5401bfd 100644 --- a/main/src/cgeo/geocaching/ui/CompassView.java +++ b/main/src/cgeo/geocaching/ui/CompassView.java @@ -128,15 +128,13 @@ public class CompassView extends View { * @return the new value */ static protected double smoothUpdate(double goal, double actual) { - double diff = goal - actual; - double offset = 0.0; - + double diff = (goal - actual) % 360; if (diff < 0.0) { diff += 360.0; - } else if (diff >= 360.0) { - diff -= 360.0; } + double offset = 0.0; + // If the difference is smaller than 1 degree, do nothing as it // causes the arrow to vibrate. if (diff > 1.0 && diff <= 180.0) { @@ -181,11 +179,9 @@ public class CompassView extends View { } double azimuthTemp = azimuthDrawn; - double azimuthRelative = azimuthTemp - headingDrawn; + double azimuthRelative = (azimuthTemp - headingDrawn) % 360; if (azimuthRelative < 0) { azimuthRelative += 360; - } else if (azimuthRelative >= 360) { - azimuthRelative -= 360; } // compass margins |