Commit 3560e27d authored by Chris Scott's avatar Chris Scott

Debugging getCurrentPosition. Adding success callbacks for several other api...

Debugging getCurrentPosition.  Adding success callbacks for several other api methods, such as start, stop, changePace.
parent eb1fa765
...@@ -103,15 +103,15 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -103,15 +103,15 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
Boolean result = false; Boolean result = false;
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) { if (ACTION_START.equalsIgnoreCase(action)) {
result = true; result = true;
this.setEnabled(true); this.setEnabled(true);
callbackContext.success(); callbackContext.success(1);
} else if (ACTION_STOP.equalsIgnoreCase(action)) { } else if (ACTION_STOP.equalsIgnoreCase(action)) {
// No implementation to stop background-tasks with Android. Just say "success" // No implementation to stop background-tasks with Android. Just say "success"
result = true; result = true;
this.setEnabled(false); this.setEnabled(false);
callbackContext.success(); callbackContext.success(0);
} else if (ACTION_FINISH.equalsIgnoreCase(action)) { } else if (ACTION_FINISH.equalsIgnoreCase(action)) {
result = true; result = true;
callbackContext.success(); callbackContext.success();
...@@ -126,7 +126,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -126,7 +126,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} else { } else {
callbackContext.error("- Configuration error!"); callbackContext.error("- Configuration error!");
} }
} else if (ACTION_CHANGE_PACE.equalsIgnoreCase(action)) { } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(action)) {
if (!isEnabled) { if (!isEnabled) {
Log.w(TAG, "- Cannot change pace while disabled"); Log.w(TAG, "- Cannot change pace while disabled");
result = false; result = false;
...@@ -297,6 +297,10 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -297,6 +297,10 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
private void setEnabled(boolean value) { private void setEnabled(boolean value) {
// Don't set a state that we're already in.
if (value == isEnabled) {
return;
}
isEnabled = value; isEnabled = value;
Intent launchIntent = this.cordova.getActivity().getIntent(); Intent launchIntent = this.cordova.getActivity().getIntent();
...@@ -478,9 +482,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -478,9 +482,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} else if (ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) { } else if (ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK); PluginResult result = new PluginResult(PluginResult.Status.OK);
resetOdometerCallback.sendPluginResult(result); resetOdometerCallback.sendPluginResult(result);
} else if (ACTION_CHANGE_PACE.equalsIgnoreCase(name)) { } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK); int state = event.getBoolean("isMoving") ? 1 : 0;
paceChangeCallback.sendPluginResult(result); paceChangeCallback.success(state);
} else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) { } else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) {
try { try {
JSONArray json = new JSONArray(event.getString("data")); JSONArray json = new JSONArray(event.getString("data"));
......
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
- (void) start:(CDVInvokedUrlCommand*)command - (void) start:(CDVInvokedUrlCommand*)command
{ {
[bgGeo start]; [bgGeo start];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: true];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
/** /**
* Turn it off * Turn it off
...@@ -62,6 +65,8 @@ ...@@ -62,6 +65,8 @@
- (void) stop:(CDVInvokedUrlCommand*)command - (void) stop:(CDVInvokedUrlCommand*)command
{ {
[bgGeo stop]; [bgGeo stop];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: false];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
- (void) getOdometer:(CDVInvokedUrlCommand*)command - (void) getOdometer:(CDVInvokedUrlCommand*)command
{ {
...@@ -83,6 +88,8 @@ ...@@ -83,6 +88,8 @@
{ {
BOOL moving = [[command.arguments objectAtIndex: 0] boolValue]; BOOL moving = [[command.arguments objectAtIndex: 0] boolValue];
[bgGeo changePace:moving]; [bgGeo changePace:moving];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: moving];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
/** /**
...@@ -307,7 +314,6 @@ ...@@ -307,7 +314,6 @@
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
- (void) onGeofence:(CDVInvokedUrlCommand*)command - (void) onGeofence:(CDVInvokedUrlCommand*)command
{ {
if (self.geofenceListeners == nil) { if (self.geofenceListeners == nil) {
...@@ -318,6 +324,13 @@ ...@@ -318,6 +324,13 @@
- (void) getCurrentPosition:(CDVInvokedUrlCommand*)command - (void) getCurrentPosition:(CDVInvokedUrlCommand*)command
{ {
if (![bgGeo isEnabled]) {
NSLog(@"- CDVBackgroundGeolocation#getCurrentPosition cannot be used when plugin is disabled");
// If plugin isn't enabled, return 401 Unauthorized
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:401];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
return;
}
if (self.currentPositionListeners == nil) { if (self.currentPositionListeners == nil) {
self.currentPositionListeners = [[NSMutableArray alloc] init]; self.currentPositionListeners = [[NSMutableArray alloc] init];
} }
...@@ -350,7 +363,6 @@ ...@@ -350,7 +363,6 @@
UIBackgroundTaskIdentifier taskId = [[command.arguments objectAtIndex: 0] integerValue]; UIBackgroundTaskIdentifier taskId = [[command.arguments objectAtIndex: 0] integerValue];
NSString *error = [command.arguments objectAtIndex:1]; NSString *error = [command.arguments objectAtIndex:1];
[bgGeo error:taskId message:error]; [bgGeo error:taskId message:error];
} }
- (void) onLocationManagerError:(NSNotification*)notification - (void) onLocationManagerError:(NSNotification*)notification
......
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