aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/DirectionProvider.java9
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java15
2 files changed, 19 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/DirectionProvider.java b/main/src/cgeo/geocaching/DirectionProvider.java
index 6802b2a..7bb940f 100644
--- a/main/src/cgeo/geocaching/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/DirectionProvider.java
@@ -49,8 +49,15 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
notifyObservers(event.values[0]);
}
+ /**
+ * Take the phone rotation (through a given activity) in account and adjust the direction.
+ *
+ * @param activity the activity to consider when computing the rotation
+ * @param direction the unadjusted direction in degrees, in the [0, 360[ range
+ * @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);
+ return Compatibility.getDirectionNow(direction, activity) % 360;
}
}
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index f88ec2d..d869c58 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -38,8 +38,16 @@ public final class Compatibility {
}
}
- public static float getDirectionNow(final float directionNowPre,
- final Activity activity) {
+ /**
+ * 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
+ */
+ public static float getDirectionNow(final float directionNowPre, final Activity activity) {
if (isLevel8) {
try {
final int rotation = level8.getRotation(activity);
@@ -55,8 +63,7 @@ public final class Compatibility {
Log.e("Cannot call getRotation()", e);
}
} else {
- final Display display = activity.getWindowManager()
- .getDefaultDisplay();
+ final Display display = activity.getWindowManager().getDefaultDisplay();
final int rotation = display.getOrientation();
if (rotation == Configuration.ORIENTATION_LANDSCAPE) {
return directionNowPre + 90;