package com.tenforwardconsulting.cordova.bgloc;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.content.Intent;


public class BackgroundGpsPlugin extends CordovaPlugin {
	public static final String ACTION_START = "start";
	public static final String ACTION_STOP = "stop";
	public static final String ACTION_CONFIGURE = "configure";
	
	private String authToken;
	private String url;
	
	@Override
	public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
		Activity activity = this.cordova.getActivity();
		Intent updateServiceIntent = new Intent(activity, LocationUpdateService.class);
		if (ACTION_START.equalsIgnoreCase(action)) {
			if (authToken == null || url == null) {
				callbackContext.error("Call configure before calling start");
				return false;
			}
			updateServiceIntent.putExtra("authToken", authToken);
			updateServiceIntent.putExtra("url", url);
			activity.startService(updateServiceIntent);
			
		} else if (ACTION_STOP.equalsIgnoreCase(action)) {
			activity.stopService(updateServiceIntent);
		} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
			try {
				this.authToken = data.getString(0);
				this.url = data.getString(1);
			} catch (JSONException e) {
				callbackContext.error("authToken/url required as parameters: " + e.getMessage());
				return false;
			}
		}
		
		return true; 
	}
}

@@ -241,74 +241,230 @@
 ent.
-Intent;%0A%0A%0Apublic class BackgroundGpsPlugin extends CordovaPlugin %7B
+Context;%0Aimport android.content.Intent;%0Aimport android.location.LocationManager;%0Aimport android.util.Log;%0A%0Apublic class BackgroundGpsPlugin extends CordovaPlugin %7B%0A%09private static final String TAG = %22BackgroundGpsPlugin%22;%0A
 %0A%09pu
@@ -622,17 +622,54 @@
 igure%22;%0A
-%09
+%0A%09private Intent updateServiceIntent;%0A
 %0A%09privat
@@ -714,19 +714,207 @@
 l;%0A%09
-%0A%09@Override
+private String stationaryRadius = %2230%22;%0A%09private String desiredAccuracy = %22100%22;%0A%09private String distanceFilter = %2230%22;%0A%09private String locationTimeout = %2260%22;%0A%09private String isDebugging = %22false%22;%0A
 %0A%09pu
@@ -1052,23 +1052,16 @@
 ty();%0A%09%09
-Intent 
 updateSe
@@ -1406,16 +1406,423 @@
 , url);%0A
+%09%09%09updateServiceIntent.putExtra(%22stationaryRadius%22, stationaryRadius);%0A%09%09%09updateServiceIntent.putExtra(%22desiredAccuracy%22, desiredAccuracy);%0A%09%09%09updateServiceIntent.putExtra(%22distanceFilter%22, distanceFilter);%0A%09%09%09updateServiceIntent.putExtra(%22locationTimeout%22, locationTimeout);%0A%09%09%09updateServiceIntent.putExtra(%22desiredAccuracy%22, desiredAccuracy);%0A%09%09%09updateServiceIntent.putExtra(%22isDebugging%22, isDebugging);%0A%0A
 %09%09%09activ
@@ -1860,19 +1860,16 @@
 ntent);%0A
-%09%09%09
 %0A%09%09%7D els
@@ -2035,77 +2035,406 @@
 %09%09%09%09
-this.authToken = data.getString(0);%0A%09%09%09%09this.url = data.getString(1);
+// %5BauthToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug%5D);%0A%0A%09%09%09%09this.authToken = data.getString(0);%0A%09%09%09%09this.url = data.getString(1);%0A%09%09%09%09this.stationaryRadius = data.getString(2);%0A%09%09%09%09this.distanceFilter = data.getString(3);%0A%09%09%09%09this.locationTimeout = data.getString(4);%0A%09%09%09%09this.desiredAccuracy = data.getString(5);%0A%09%09%09%09this.isDebugging = data.getString(6);%0A
 %0A%09%09%09
@@ -2574,18 +2574,16 @@
 %09%09%7D%0A%09%09%7D%0A
-%09%09
 %0A%09%09retur
@@ -2589,15 +2589,14 @@
 rn true;
- 
 %0A%09%7D%0A%7D%0A

Introduce new params