Workaround to show hidden accents in options menu
[pub/Android/ownCloud.git] / src / com / owncloud / android / location / LocationUpdateService.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package com.owncloud.android.location;
19
20 import android.app.IntentService;
21 import android.content.Intent;
22 import android.content.SharedPreferences;
23 import android.location.Criteria;
24 import android.location.Location;
25 import android.location.LocationListener;
26 import android.location.LocationManager;
27 import android.location.LocationProvider;
28 import android.os.Bundle;
29 import android.preference.PreferenceManager;
30 import android.util.Log;
31 import android.widget.Toast;
32
33 import com.owncloud.android.R;
34
35 public class LocationUpdateService extends IntentService implements
36 LocationListener {
37
38 public static final String TAG = "LocationUpdateService";
39
40 private LocationManager mLocationManager;
41 private LocationProvider mLocationProvider;
42 private SharedPreferences mPreferences;
43
44 public LocationUpdateService() {
45 super(TAG);
46 }
47
48 @Override
49 protected void onHandleIntent(Intent intent) {
50 mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
51 // Determine, how we can track the device
52 Criteria criteria = new Criteria();
53 criteria.setAccuracy(Criteria.ACCURACY_FINE);
54 criteria.setPowerRequirement(Criteria.POWER_LOW);
55 mLocationProvider = mLocationManager.getProvider(mLocationManager
56 .getBestProvider(criteria, true));
57
58 // Notify user if there is no way to track the device
59 if (mLocationProvider == null) {
60 Toast.makeText(this,
61 R.string.location_no_provider,
62 Toast.LENGTH_LONG);
63 stopSelf();
64 return;
65 }
66
67 // Get preferences for device tracking
68 mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
69 boolean trackDevice = mPreferences.getBoolean("enable_devicetracking",
70 true);
71 int updateIntervall = Integer.parseInt(mPreferences.getString(
72 "devicetracking_update_intervall", "30")) * 60 * 1000;
73 int distanceBetweenLocationChecks = 50;
74
75 // If we do shall track the device -> Stop
76 if (!trackDevice) {
77 Log.d(TAG, "Devicetracking is disabled");
78 stopSelf();
79 return;
80 }
81
82 mLocationManager.requestLocationUpdates(mLocationProvider.getName(),
83 updateIntervall, distanceBetweenLocationChecks, this);
84 }
85
86 @Override
87 public void onLocationChanged(Location location) {
88 Log.d(TAG, "Location changed: " + location);
89
90 }
91
92 @Override
93 public void onProviderDisabled(String arg0) {
94 // TODO Auto-generated method stub
95
96 }
97
98 @Override
99 public void onProviderEnabled(String arg0) {
100 // TODO Auto-generated method stub
101
102 }
103
104 @Override
105 public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
106 // TODO Auto-generated method stub
107
108 }
109
110 }