aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sensors/DirectionProvider.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-06 22:25:28 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-06 22:25:28 +0200
commit5054a74e00e6b0cf522d3fa3f978177c0c92427d (patch)
treed93c6fbbbbe863325da8dd2e7a0bf2a989bf044d /main/src/cgeo/geocaching/sensors/DirectionProvider.java
parentfcbfb693f0a2dd166025dd4b5e44cb3ae843ccfc (diff)
downloadcgeo-5054a74e00e6b0cf522d3fa3f978177c0c92427d.zip
cgeo-5054a74e00e6b0cf522d3fa3f978177c0c92427d.tar.gz
cgeo-5054a74e00e6b0cf522d3fa3f978177c0c92427d.tar.bz2
fix #3729: compass deviation -90° in landscape mode (GPS)
Diffstat (limited to 'main/src/cgeo/geocaching/sensors/DirectionProvider.java')
-rw-r--r--main/src/cgeo/geocaching/sensors/DirectionProvider.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
index 44732f7..788d5bd 100644
--- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.sensors;
+import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.StartableHandlerThread;
@@ -8,7 +9,6 @@ import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.subjects.BehaviorSubject;
-import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
@@ -17,11 +17,14 @@ import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Process;
import android.view.Surface;
+import android.view.WindowManager;
public class DirectionProvider {
private static final BehaviorSubject<Float> subject = BehaviorSubject.create(0.0f);
+ private static final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
+
static class Listener implements SensorEventListener, StartableHandlerThread.Callback {
private int count = 0;
@@ -85,17 +88,20 @@ public class DirectionProvider {
/**
* 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 AngleUtils.normalize(direction + getRotationOffset(activity));
+ public static float getDirectionNow(final float direction) {
+ return AngleUtils.normalize(direction + getRotationOffset());
+ }
+
+ static float reverseDirectionNow(final float direction) {
+ return AngleUtils.normalize(direction - getRotationOffset());
}
- private static int getRotationOffset(final Activity activity) {
- switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
+ private static int getRotationOffset() {
+ switch (windowManager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180: