diff options
| author | Michael Keppler <michael.keppler@gmx.de> | 2014-04-22 10:33:17 +0200 |
|---|---|---|
| committer | Michael Keppler <michael.keppler@gmx.de> | 2014-04-22 10:33:17 +0200 |
| commit | b803878a41364159063094af402bf5a81ae3567a (patch) | |
| tree | 0cde2d75648fcd87df25f7c15ee8913246ea0a05 /main/src/cgeo | |
| parent | d040d628e3aa8f71698a5bd0268f29f682ac8eb1 (diff) | |
| download | cgeo-b803878a41364159063094af402bf5a81ae3567a.zip cgeo-b803878a41364159063094af402bf5a81ae3567a.tar.gz cgeo-b803878a41364159063094af402bf5a81ae3567a.tar.bz2 | |
fix deprecation warning
Second try not using static methods and instead moving everything into
the listener class.
Diffstat (limited to 'main/src/cgeo')
| -rw-r--r-- | main/src/cgeo/geocaching/sensors/DirectionProvider.java | 49 |
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); - } - } |
