Commit 87959ef6 authored by Chris Scott's avatar Chris Scott

Allow LocationRequest to be more configurable for calculating fastestInterval,...

Allow LocationRequest to be more configurable for calculating fastestInterval, locationUpdateInterval
parent ae05c066
...@@ -77,6 +77,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -77,6 +77,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
* @config {Integer} locationUpdateInterval (ms) * @config {Integer} locationUpdateInterval (ms)
*/ */
private Integer locationUpdateInterval = 60000; private Integer locationUpdateInterval = 60000;
/**
* @config {Integer} fastestLocationUpdateInterval (ms)
*/
private Integer fastestLocationUpdateInterval = 30000;
/** /**
* @config {Integer{ activityRecognitionInterval (ms) * @config {Integer{ activityRecognitionInterval (ms)
*/ */
...@@ -193,14 +197,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -193,14 +197,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override @Override
public void onConnected(Bundle arg0) { public void onConnected(Bundle arg0) {
Log.i(TAG, "- GooglePlayServices connected"); Log.i(TAG, "- GooglePlayServices connected");
// Configure FusedLocationProvider
locationRequest = LocationRequest.create()
.setPriority(translateDesiredAccuracy(desiredAccuracy))
.setInterval(this.locationUpdateInterval)
.setFastestInterval(30000)
.setSmallestDisplacement(distanceFilter);
Intent arsIntent = new Intent(this, ActivityRecognitionService.class); Intent arsIntent = new Intent(this, ActivityRecognitionService.class);
activityRecognitionPI = PendingIntent.getService(this, 0, arsIntent, PendingIntent.FLAG_UPDATE_CURRENT); activityRecognitionPI = PendingIntent.getService(this, 0, arsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
...@@ -367,6 +364,34 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -367,6 +364,34 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
return accuracy; return accuracy;
} }
private Integer getLocationUpdateInterval() {
// TODO Can add intelligence here based upon currentActivity.
return locationUpdateInterval;
}
private Integer getFastestLocationUpdateInterval() {
/* TODO Add intelligent calculation of fastestLocationUpdateInterval based upon currentActivity here
* switch (currentActivity.getType()) {
case DetectedActivity.IN_VEHICLE:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.ON_BICYCLE:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.ON_FOOT:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.RUNNING:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.WALKING:
fastestLocationUpdateInterval = 30000;
break;
}
*/
return fastestLocationUpdateInterval;
}
private String getActivityName(int activityType) { private String getActivityName(int activityType) {
switch (activityType) { switch (activityType) {
case DetectedActivity.IN_VEHICLE: case DetectedActivity.IN_VEHICLE:
...@@ -479,6 +504,14 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -479,6 +504,14 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
private void requestLocationUpdates() { private void requestLocationUpdates() {
if (!isPaused || !isEnabled) { return; } // <-- Don't engage GPS when app is in foreground if (!isPaused || !isEnabled) { return; } // <-- Don't engage GPS when app is in foreground
// Configure LocationRequest
locationRequest = LocationRequest.create()
.setPriority(translateDesiredAccuracy(desiredAccuracy))
.setInterval(this.getLocationUpdateInterval())
.setFastestInterval(this.getFastestLocationUpdateInterval())
.setSmallestDisplacement(distanceFilter);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationUpdatePI); LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationUpdatePI);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment