diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-30 21:00:52 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-05-30 21:22:54 +0200 |
| commit | ad93745d42f9aaf5bc4925075987ef64c13b2f71 (patch) | |
| tree | 415c5b391da9b9248f57838c5f3adc94c4c15ac5 | |
| parent | 7e607f82e2acb252ab84ab2e1b33d4fc6c15132b (diff) | |
| download | cgeo-ad93745d42f9aaf5bc4925075987ef64c13b2f71.zip cgeo-ad93745d42f9aaf5bc4925075987ef64c13b2f71.tar.gz cgeo-ad93745d42f9aaf5bc4925075987ef64c13b2f71.tar.bz2 | |
fix #1680: compass gets stuck after some rotations
| -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 |
