X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/6e43d84b17a15b934989d0b71c1ac795186f26b4..435b31ba4f3597cc7a43270cd4a54fb0180956c1:/src/eu/alefzero/owncloud/location/LocationServiceLauncherReciever.java diff --git a/src/eu/alefzero/owncloud/location/LocationServiceLauncherReciever.java b/src/eu/alefzero/owncloud/location/LocationServiceLauncherReciever.java index 813b46e4..9c210bb5 100644 --- a/src/eu/alefzero/owncloud/location/LocationServiceLauncherReciever.java +++ b/src/eu/alefzero/owncloud/location/LocationServiceLauncherReciever.java @@ -28,56 +28,61 @@ import android.util.Log; public class LocationServiceLauncherReciever extends BroadcastReceiver { - private final String TAG = getClass().getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - Intent deviceTrackingIntent = new Intent(); - deviceTrackingIntent.setAction("eu.alefzero.owncloud.location.LocationUpdateService"); - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - boolean trackDevice = preferences.getBoolean("enable_devicetracking", true); - - // Used in Preferences activity so that tracking is disabled or reenabled - if(intent.hasExtra("TRACKING_SETTING")){ - trackDevice = intent.getBooleanExtra("TRACKING_SETTING", true); - } - - startOrStopDeviceTracking(context, trackDevice); - } - - /** - * Used internally. Starts or stops the device tracking service - * - * @param trackDevice - * true to start the service, false to stop it - */ - private void startOrStopDeviceTracking(Context context, boolean trackDevice) { - Intent deviceTrackingIntent = new Intent(); - deviceTrackingIntent - .setAction("eu.alefzero.owncloud.location.LocationUpdateService"); - if (!isDeviceTrackingServiceRunning(context) && trackDevice) { - Log.d(TAG, "Starting device tracker service"); - context.startService(deviceTrackingIntent); - } else if (isDeviceTrackingServiceRunning(context) && !trackDevice) { - Log.d(TAG, "Stopping device tracker service"); - context.stopService(deviceTrackingIntent); - } - } - - /** - * Checks to see whether or not the LocationUpdateService is running - * - * @return true, if it is. Otherwise false - */ - private boolean isDeviceTrackingServiceRunning(Context context) { - ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - for (RunningServiceInfo service : manager - .getRunningServices(Integer.MAX_VALUE)) { - if (getClass().getName().equals(service.service.getClassName())) { - return true; - } - } - return false; - } + private final String TAG = getClass().getSimpleName(); + + @Override + public void onReceive(Context context, Intent intent) { + Intent deviceTrackingIntent = new Intent(); + deviceTrackingIntent + .setAction("eu.alefzero.owncloud.location.LocationUpdateService"); + SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + boolean trackDevice = preferences.getBoolean("enable_devicetracking", + true); + + // Used in Preferences activity so that tracking is disabled or + // reenabled + if (intent.hasExtra("TRACKING_SETTING")) { + trackDevice = intent.getBooleanExtra("TRACKING_SETTING", true); + } + + startOrStopDeviceTracking(context, trackDevice); + } + + /** + * Used internally. Starts or stops the device tracking service + * + * @param trackDevice + * true to start the service, false to stop it + */ + private void startOrStopDeviceTracking(Context context, boolean trackDevice) { + Intent deviceTrackingIntent = new Intent(); + deviceTrackingIntent + .setAction("eu.alefzero.owncloud.location.LocationUpdateService"); + if (!isDeviceTrackingServiceRunning(context) && trackDevice) { + Log.d(TAG, "Starting device tracker service"); + context.startService(deviceTrackingIntent); + } else if (isDeviceTrackingServiceRunning(context) && !trackDevice) { + Log.d(TAG, "Stopping device tracker service"); + context.stopService(deviceTrackingIntent); + } + } + + /** + * Checks to see whether or not the LocationUpdateService is running + * + * @return true, if it is. Otherwise false + */ + private boolean isDeviceTrackingServiceRunning(Context context) { + ActivityManager manager = (ActivityManager) context + .getSystemService(Context.ACTIVITY_SERVICE); + for (RunningServiceInfo service : manager + .getRunningServices(Integer.MAX_VALUE)) { + if (getClass().getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } }