diff options
| author | Michael Keppler <michael.keppler@gmx.de> | 2014-04-22 10:04:52 +0200 |
|---|---|---|
| committer | Michael Keppler <michael.keppler@gmx.de> | 2014-04-22 10:04:52 +0200 |
| commit | d040d628e3aa8f71698a5bd0268f29f682ac8eb1 (patch) | |
| tree | 773646047762b7babd7b50285c587b678104a6c6 /main/src/cgeo/geocaching/sensors/DirectionProvider.java | |
| parent | a1eb213952f27a4eea6aee25f6db57e0b2440ff8 (diff) | |
| download | cgeo-d040d628e3aa8f71698a5bd0268f29f682ac8eb1.zip cgeo-d040d628e3aa8f71698a5bd0268f29f682ac8eb1.tar.gz cgeo-d040d628e3aa8f71698a5bd0268f29f682ac8eb1.tar.bz2 | |
fix new deprecation warning
Diffstat (limited to 'main/src/cgeo/geocaching/sensors/DirectionProvider.java')
| -rw-r--r-- | main/src/cgeo/geocaching/sensors/DirectionProvider.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java index 8e7507d..f41097c 100644 --- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java +++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java @@ -50,16 +50,13 @@ public class DirectionProvider { //Log.i(Settings.tag, "Compass' accuracy is low (" + accuracy + ")"); } - // This will be removed when using a new location service. Until then, it is okay to be used. - @SuppressWarnings("deprecation") @Override public void start(final Context context, final Handler handler) { if (!hasSensor(context)) { return; } if (++count == 1) { - sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); - Sensor orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); + Sensor orientationSensor = getOrientationSensor(context); sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL, handler); } } @@ -104,8 +101,7 @@ public class DirectionProvider { public static boolean hasSensor(Context context) { if (hasSensorChecked == false) { - SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); - hasSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION) != null; + hasSensor = getOrientationSensor(context) != null; } return hasSensor; } @@ -138,4 +134,11 @@ 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); + } + } |
