From c1eca4632f211dfcd0813dd07edc3034aee06e4e Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 28 Mar 2018 14:11:12 +0300 Subject: [PATCH 1/3] Adds a method providing the last fixed location. --- .../location/manager/lib/Services/KalmanLocationService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java index 1e58cb2..079e133 100644 --- a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java +++ b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java @@ -137,6 +137,10 @@ public void addStatusInterfaces(List locationSer } } + public Location getLastLocation() { + return m_lastLocation; + } + /*Service implementation*/ public class LocalBinder extends Binder { public KalmanLocationService getService() { From a5796f20b53dd2720efebff6ff64f26c0a8e4978 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 28 Mar 2018 14:37:15 +0300 Subject: [PATCH 2/3] Add another method for getting the Kalman Service. However, if it's not already initalized, the method will return null. --- .../location/manager/lib/Services/ServicesHelper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/ServicesHelper.java b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/ServicesHelper.java index ed5832f..61d2f28 100644 --- a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/ServicesHelper.java +++ b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/ServicesHelper.java @@ -6,13 +6,13 @@ import android.content.ServiceConnection; import android.os.IBinder; +import java.util.ArrayList; +import java.util.List; + import mad.location.manager.lib.Interfaces.LocationServiceInterface; import mad.location.manager.lib.Interfaces.LocationServiceStatusInterface; import mad.location.manager.lib.Interfaces.SimpleTempCallback; -import java.util.ArrayList; -import java.util.List; - /** * Created by lezh1k on 2/13/18. */ @@ -107,4 +107,7 @@ public static void getLocationService(Context context, SimpleTempCallback Date: Wed, 28 Mar 2018 15:03:51 +0300 Subject: [PATCH 3/3] Replaces the not descriptive int values with descriptive enum for the statuses. --- .../LocationServiceStatusInterface.java | 4 +- .../lib/Services/KalmanLocationService.java | 43 +++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/madlocationmanager/src/main/java/mad/location/manager/lib/Interfaces/LocationServiceStatusInterface.java b/madlocationmanager/src/main/java/mad/location/manager/lib/Interfaces/LocationServiceStatusInterface.java index fbd7945..5ba1932 100644 --- a/madlocationmanager/src/main/java/mad/location/manager/lib/Interfaces/LocationServiceStatusInterface.java +++ b/madlocationmanager/src/main/java/mad/location/manager/lib/Interfaces/LocationServiceStatusInterface.java @@ -1,11 +1,13 @@ package mad.location.manager.lib.Interfaces; +import static mad.location.manager.lib.Services.KalmanLocationService.ServiceStatus; + /** * Created by lezh1k on 2/13/18. */ public interface LocationServiceStatusInterface { - void serviceStatusChanged(int status); + void serviceStatusChanged(ServiceStatus status); void GPSStatusChanged(int activeSatellites); void GPSEnabledChanged(boolean enabled); void lastLocationAccuracyChanged(float accuracy); diff --git a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java index 079e133..cf2c890 100644 --- a/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java +++ b/madlocationmanager/src/main/java/mad/location/manager/lib/Services/KalmanLocationService.java @@ -24,6 +24,11 @@ import android.support.v4.app.ActivityCompat; import android.util.Log; +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.PriorityBlockingQueue; + import mad.location.manager.lib.Commons.Coordinates; import mad.location.manager.lib.Commons.GeoPoint; import mad.location.manager.lib.Commons.SensorGpsDataItem; @@ -34,11 +39,6 @@ import mad.location.manager.lib.Interfaces.LocationServiceStatusInterface; import mad.location.manager.lib.Loggers.GeohashRTFilter; -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.PriorityBlockingQueue; - public class KalmanLocationService extends Service implements SensorEventListener, LocationListener, GpsStatus.Listener { @@ -80,19 +80,28 @@ public Settings(double accelerationDeviation, protected Location m_lastLocation; - public static final int PermissionDenied = 0; - public static final int ServiceStopped = 1; - public static final int StartLocationUpdates = 2; - public static final int HaveLocation = 3; - public static final int ServicePaused = 4; - protected int m_serviceStatus = ServiceStopped; + protected ServiceStatus m_serviceStatus = ServiceStatus.SERVICE_STOPPED; + + public enum ServiceStatus { + PERMISSION_DENIED(0), + SERVICE_STOPPED(1), + SERVICE_STARTED(2), + HAS_LOCATION(3), + SERVICE_PAUSED(4); + + int value; + + ServiceStatus(int value) { this.value = value;} + + public int getValue() { return value; } + } public boolean isSensorsEnabled() { return m_sensorsEnabled; } public boolean IsRunning() { - return m_serviceStatus != ServiceStopped && m_serviceStatus != ServicePaused && m_sensorsEnabled; + return m_serviceStatus != ServiceStatus.SERVICE_STOPPED && m_serviceStatus != ServiceStatus.SERVICE_PAUSED && m_sensorsEnabled; } public void addInterface(LocationServiceInterface locationServiceInterface) { @@ -326,7 +335,7 @@ void onLocationChangedImp(Location location) { return; } - m_serviceStatus = HaveLocation; + m_serviceStatus = ServiceStatus.HAS_LOCATION; m_lastLocation = location; m_lastLocationAccuracy = location.getAccuracy(); @@ -395,9 +404,9 @@ public void start() { m_wakeLock.acquire(); m_sensorDataQueue.clear(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - m_serviceStatus = PermissionDenied; + m_serviceStatus = ServiceStatus.PERMISSION_DENIED; } else { - m_serviceStatus = StartLocationUpdates; + m_serviceStatus = ServiceStatus.SERVICE_STARTED; m_locationManager.removeGpsStatusListener(this); m_locationManager.addGpsStatusListener(this); m_locationManager.removeUpdates(this); @@ -428,9 +437,9 @@ public void stop() { m_wakeLock.release(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - m_serviceStatus = ServiceStopped; + m_serviceStatus = ServiceStatus.SERVICE_STOPPED; } else { - m_serviceStatus = ServicePaused; + m_serviceStatus = ServiceStatus.SERVICE_PAUSED; m_locationManager.removeGpsStatusListener(this); m_locationManager.removeUpdates(this); }