Skip to content

Commit

Permalink
Merge pull request #3 from Seishin/master
Browse files Browse the repository at this point in the history
Adding small changes
  • Loading branch information
Lezh1k authored Mar 29, 2018
2 parents 2b05e5e + 5ed734a commit 395d3f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -137,6 +146,10 @@ public void addStatusInterfaces(List<LocationServiceStatusInterface> locationSer
}
}

public Location getLastLocation() {
return m_lastLocation;
}

/*Service implementation*/
public class LocalBinder extends Binder {
public KalmanLocationService getService() {
Expand Down Expand Up @@ -322,7 +335,7 @@ void onLocationChangedImp(Location location) {
return;
}

m_serviceStatus = HaveLocation;
m_serviceStatus = ServiceStatus.HAS_LOCATION;
m_lastLocation = location;
m_lastLocationAccuracy = location.getAccuracy();

Expand Down Expand Up @@ -391,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);
Expand Down Expand Up @@ -424,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -107,4 +107,7 @@ public static void getLocationService(Context context, SimpleTempCallback<Kalman
}
}

public static KalmanLocationService getLocationService() {
return instance.kalmanLocationService;
}
}

0 comments on commit 395d3f5

Please sign in to comment.