aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sensors/DirectionProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/sensors/DirectionProvider.java')
-rw-r--r--main/src/cgeo/geocaching/sensors/DirectionProvider.java49
1 files changed, 25 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
index f41097c..5b17df6 100644
--- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
@@ -30,6 +30,7 @@ public class DirectionProvider {
private int count = 0;
private SensorManager sensorManager;
+
@Override
public void onSensorChanged(final SensorEvent event) {
subject.onNext(event.values[0]);
@@ -71,6 +72,30 @@ public class DirectionProvider {
}
}
+ /**
+ * Assume that there is an orientation sensor, unless we have really checked that
+ */
+ private boolean hasSensor = true;
+
+ /**
+ * Flag for one time check if there is a sensor.
+ */
+ private boolean hasSensorChecked = false;
+
+ public boolean hasSensor(Context context) {
+ if (hasSensorChecked == false) {
+ hasSensor = getOrientationSensor(context) != null;
+ }
+ return hasSensor;
+ }
+
+ // This will be removed when using a new location service. Until then, it is okay to be used.
+ @SuppressWarnings("deprecation")
+ private Sensor getOrientationSensor(final Context context) {
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ return sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
+ }
+
}
private static final StartableHandlerThread handlerThread =
@@ -90,23 +115,6 @@ public class DirectionProvider {
}
/**
- * Assume that there is an orientation sensor, unless we have really checked that
- */
- private static boolean hasSensor = true;
-
- /**
- * Flag for one time check if there is a sensor.
- */
- private static boolean hasSensorChecked = false;
-
- public static boolean hasSensor(Context context) {
- if (hasSensorChecked == false) {
- hasSensor = getOrientationSensor(context) != null;
- }
- return hasSensor;
- }
-
- /**
* Take the phone rotation (through a given activity) in account and adjust the direction.
*
* @param direction the unadjusted direction in degrees, in the [0, 360[ range
@@ -134,11 +142,4 @@ public class DirectionProvider {
}
}
- // This will be removed when using a new location service. Until then, it is okay to be used.
- @SuppressWarnings("deprecation")
- private static Sensor getOrientationSensor(final Context context) {
- SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- return sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
- }
-
}