|
24 | 24 | import android.support.v4.app.ActivityCompat; |
25 | 25 | import android.util.Log; |
26 | 26 |
|
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.List; |
| 29 | +import java.util.Queue; |
| 30 | +import java.util.concurrent.PriorityBlockingQueue; |
| 31 | + |
27 | 32 | import mad.location.manager.lib.Commons.Coordinates; |
28 | 33 | import mad.location.manager.lib.Commons.GeoPoint; |
29 | 34 | import mad.location.manager.lib.Commons.SensorGpsDataItem; |
|
34 | 39 | import mad.location.manager.lib.Interfaces.LocationServiceStatusInterface; |
35 | 40 | import mad.location.manager.lib.Loggers.GeohashRTFilter; |
36 | 41 |
|
37 | | -import java.util.ArrayList; |
38 | | -import java.util.List; |
39 | | -import java.util.Queue; |
40 | | -import java.util.concurrent.PriorityBlockingQueue; |
41 | | - |
42 | 42 | public class KalmanLocationService extends Service |
43 | 43 | implements SensorEventListener, LocationListener, GpsStatus.Listener { |
44 | 44 |
|
@@ -80,19 +80,28 @@ public Settings(double accelerationDeviation, |
80 | 80 |
|
81 | 81 | protected Location m_lastLocation; |
82 | 82 |
|
83 | | - public static final int PermissionDenied = 0; |
84 | | - public static final int ServiceStopped = 1; |
85 | | - public static final int StartLocationUpdates = 2; |
86 | | - public static final int HaveLocation = 3; |
87 | | - public static final int ServicePaused = 4; |
88 | | - protected int m_serviceStatus = ServiceStopped; |
| 83 | + protected ServiceStatus m_serviceStatus = ServiceStatus.SERVICE_STOPPED; |
| 84 | + |
| 85 | + public enum ServiceStatus { |
| 86 | + PERMISSION_DENIED(0), |
| 87 | + SERVICE_STOPPED(1), |
| 88 | + SERVICE_STARTED(2), |
| 89 | + HAS_LOCATION(3), |
| 90 | + SERVICE_PAUSED(4); |
| 91 | + |
| 92 | + int value; |
| 93 | + |
| 94 | + ServiceStatus(int value) { this.value = value;} |
| 95 | + |
| 96 | + public int getValue() { return value; } |
| 97 | + } |
89 | 98 |
|
90 | 99 | public boolean isSensorsEnabled() { |
91 | 100 | return m_sensorsEnabled; |
92 | 101 | } |
93 | 102 |
|
94 | 103 | public boolean IsRunning() { |
95 | | - return m_serviceStatus != ServiceStopped && m_serviceStatus != ServicePaused && m_sensorsEnabled; |
| 104 | + return m_serviceStatus != ServiceStatus.SERVICE_STOPPED && m_serviceStatus != ServiceStatus.SERVICE_PAUSED && m_sensorsEnabled; |
96 | 105 | } |
97 | 106 |
|
98 | 107 | public void addInterface(LocationServiceInterface locationServiceInterface) { |
@@ -137,6 +146,10 @@ public void addStatusInterfaces(List<LocationServiceStatusInterface> locationSer |
137 | 146 | } |
138 | 147 | } |
139 | 148 |
|
| 149 | + public Location getLastLocation() { |
| 150 | + return m_lastLocation; |
| 151 | + } |
| 152 | + |
140 | 153 | /*Service implementation*/ |
141 | 154 | public class LocalBinder extends Binder { |
142 | 155 | public KalmanLocationService getService() { |
@@ -322,7 +335,7 @@ void onLocationChangedImp(Location location) { |
322 | 335 | return; |
323 | 336 | } |
324 | 337 |
|
325 | | - m_serviceStatus = HaveLocation; |
| 338 | + m_serviceStatus = ServiceStatus.HAS_LOCATION; |
326 | 339 | m_lastLocation = location; |
327 | 340 | m_lastLocationAccuracy = location.getAccuracy(); |
328 | 341 |
|
@@ -391,9 +404,9 @@ public void start() { |
391 | 404 | m_wakeLock.acquire(); |
392 | 405 | m_sensorDataQueue.clear(); |
393 | 406 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
394 | | - m_serviceStatus = PermissionDenied; |
| 407 | + m_serviceStatus = ServiceStatus.PERMISSION_DENIED; |
395 | 408 | } else { |
396 | | - m_serviceStatus = StartLocationUpdates; |
| 409 | + m_serviceStatus = ServiceStatus.SERVICE_STARTED; |
397 | 410 | m_locationManager.removeGpsStatusListener(this); |
398 | 411 | m_locationManager.addGpsStatusListener(this); |
399 | 412 | m_locationManager.removeUpdates(this); |
@@ -424,9 +437,9 @@ public void stop() { |
424 | 437 | m_wakeLock.release(); |
425 | 438 |
|
426 | 439 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
427 | | - m_serviceStatus = ServiceStopped; |
| 440 | + m_serviceStatus = ServiceStatus.SERVICE_STOPPED; |
428 | 441 | } else { |
429 | | - m_serviceStatus = ServicePaused; |
| 442 | + m_serviceStatus = ServiceStatus.SERVICE_PAUSED; |
430 | 443 | m_locationManager.removeGpsStatusListener(this); |
431 | 444 | m_locationManager.removeUpdates(this); |
432 | 445 | } |
|
0 commit comments