aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/compatibility
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-06-01 01:31:31 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-06-01 01:31:31 +0200
commit55546fcc11cb011245566907651f93e1b25ff29a (patch)
tree000c1b360a7ea064ef41826f7c02f5c1ec466a65 /main/src/cgeo/geocaching/compatibility
parente1afa5a46fc00e26639e97de007f2b84aedb9f7c (diff)
downloadcgeo-55546fcc11cb011245566907651f93e1b25ff29a.zip
cgeo-55546fcc11cb011245566907651f93e1b25ff29a.tar.gz
cgeo-55546fcc11cb011245566907651f93e1b25ff29a.tar.bz2
Refactoring: normalize Compatibility#getDirectionNow
Diffstat (limited to 'main/src/cgeo/geocaching/compatibility')
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java16
1 files changed, 8 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index d869c58..0821655 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.compatibility;
import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.reflect.MethodUtils;
@@ -40,23 +41,22 @@ public final class Compatibility {
/**
* Add 90, 180 or 270 degrees to the given rotation.
- * <br/>
- * Note: the result is not normalized and may fall outside your desired range.
*
* @param directionNowPre the direction in degrees before adjustment
* @param activity the activity whose rotation is used to adjust the direction
- * @return the adjusted direction
+ * @return the adjusted direction, in the [0, 360[ range
*/
public static float getDirectionNow(final float directionNowPre, final Activity activity) {
+ float offset = 0;
if (isLevel8) {
try {
final int rotation = level8.getRotation(activity);
if (rotation == Surface.ROTATION_90) {
- return directionNowPre + 90;
+ offset = 90;
} else if (rotation == Surface.ROTATION_180) {
- return directionNowPre + 180;
+ offset = 180;
} else if (rotation == Surface.ROTATION_270) {
- return directionNowPre + 270;
+ offset = 270;
}
} catch (final Exception e) {
// This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
@@ -66,10 +66,10 @@ public final class Compatibility {
final Display display = activity.getWindowManager().getDefaultDisplay();
final int rotation = display.getOrientation();
if (rotation == Configuration.ORIENTATION_LANDSCAPE) {
- return directionNowPre + 90;
+ offset = 90;
}
}
- return directionNowPre;
+ return AngleUtils.normalize(directionNowPre + offset);
}
public static void dataChanged(final String name) {