diff options
Diffstat (limited to 'main/src/cgeo/geocaching/sensors/DirectionProvider.java')
| -rw-r--r-- | main/src/cgeo/geocaching/sensors/DirectionProvider.java | 18 |
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: |
