aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
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:37:19 +0200
commit720274c8d9478b8b590148f82819ba6a6755f4cd (patch)
treebc6ab7bae29a0987e367520679b6aaf5a8bdafd8 /main/src
parentf6cdebf0b504417256e652cbd91e592a017dfebf (diff)
downloadcgeo-720274c8d9478b8b590148f82819ba6a6755f4cd.zip
cgeo-720274c8d9478b8b590148f82819ba6a6755f4cd.tar.gz
cgeo-720274c8d9478b8b590148f82819ba6a6755f4cd.tar.bz2
fix #3729: compass deviation -90° in landscape mode (GPS)
Conflicts: main/src/cgeo/geocaching/sensors/DirectionProvider.java tests/src/cgeo/geocaching/compatibility/CompatibilityTest.java
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/CacheListActivity.java2
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java2
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java2
-rw-r--r--main/src/cgeo/geocaching/sensors/DirectionProvider.java36
-rw-r--r--main/src/cgeo/geocaching/sensors/GeoDirHandler.java6
5 files changed, 36 insertions, 12 deletions
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java
index 1ae6378..f892bcb 100644
--- a/main/src/cgeo/geocaching/CacheListActivity.java
+++ b/main/src/cgeo/geocaching/CacheListActivity.java
@@ -126,7 +126,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
@Override
public void updateDirection(final float direction) {
if (Settings.isLiveList()) {
- adapter.setActualHeading(DirectionProvider.getDirectionNow(CacheListActivity.this, direction));
+ adapter.setActualHeading(DirectionProvider.getDirectionNow(direction));
}
}
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index b4bff88..ff7a025 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -287,7 +287,7 @@ public class CompassActivity extends AbstractActivity {
navLocation.setText(res.getString(R.string.loc_trying));
}
- updateNorthHeading(DirectionProvider.getDirectionNow(CompassActivity.this, dir));
+ updateNorthHeading(DirectionProvider.getDirectionNow(dir));
} catch (RuntimeException e) {
Log.w("Failed to LocationUpdater location.");
}
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index cab961a..f06a42f 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -895,7 +895,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
locationValid = true;
currentLocation = geo.getLocation();
- currentHeading = DirectionProvider.getDirectionNow(activity, dir);
+ currentHeading = DirectionProvider.getDirectionNow(dir);
repaintPositionOverlay();
}
}
diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
index 8efbc1f..4f11a35 100644
--- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
@@ -1,26 +1,30 @@
package cgeo.geocaching.sensors;
-import android.os.Process;
-import cgeo.geocaching.compatibility.Compatibility;
-
+import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.StartableHandlerThread;
+
import rx.Observable;
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;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
-import android.os.*;
+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;
@@ -84,13 +88,29 @@ 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 Compatibility.getDirectionNow(direction, 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() {
+ switch (windowManager.getDefaultDisplay().getRotation()) {
+ case Surface.ROTATION_90:
+ return 90;
+ case Surface.ROTATION_180:
+ return 180;
+ case Surface.ROTATION_270:
+ return 270;
+ default:
+ return 0;
+ }
}
}
diff --git a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
index 37a0c5b..dd61cb1 100644
--- a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
+++ b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
@@ -18,6 +18,10 @@ import rx.subscriptions.CompositeSubscription;
* To use this class, override {@link #updateGeoDir(IGeoData, float)}. You need to start the handler using
* {@link #start()}. A good place to do so might be the {@code onResume} method of the Activity. Stop the Handler
* accordingly in {@code onPause}.
+ *
+ * The direction is always relative to the top of the device (natural direction), and that it must
+ * be fixed using {@link DirectionProvider#getDirectionNow(float)}. When the direction is derived from the GPS,
+ * it is altered so that the fix can still be applied as if the information came from the compass.
*/
public abstract class GeoDirHandler {
@@ -71,7 +75,7 @@ public abstract class GeoDirHandler {
private static float fixDirection(final IGeoData geoData, final float direction) {
final boolean useGPSBearing = !Settings.isUseCompass() || geoData.getSpeed() > 5;
- return useGPSBearing ? geoData.getBearing() : direction;
+ return useGPSBearing ? DirectionProvider.reverseDirectionNow(geoData.getBearing()) : direction;
}
/**