Commit 33b7cca6 authored by Chris Scott's avatar Chris Scott

Mistake in merge conflict resolution

parent 6baff327
...@@ -28,7 +28,7 @@ import android.media.AudioManager; ...@@ -28,7 +28,7 @@ import android.media.AudioManager;
import android.media.ToneGenerator; import android.media.ToneGenerator;
public class CDVBackgroundGeolocation extends CordovaPlugin { public class CDVBackgroundGeolocation extends CordovaPlugin {
private static final String TAG = "BackgroundGeolocation"; private static final String TAG = "TSLocationManager";
private static CordovaWebView gWebView; private static CordovaWebView gWebView;
public static Boolean forceReload = false; public static Boolean forceReload = false;
...@@ -38,31 +38,34 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -38,31 +38,34 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
*/ */
private static final long GET_CURRENT_POSITION_TIMEOUT = 30000; private static final long GET_CURRENT_POSITION_TIMEOUT = 30000;
public static final String ACTION_START = "start"; public static final String ACTION_START = "start";
public static final String ACTION_STOP = "stop"; public static final String ACTION_STOP = "stop";
public static final String ACTION_FINISH = "finish"; public static final String ACTION_FINISH = "finish";
public static final String ACTION_ERROR = "error"; public static final String ACTION_ERROR = "error";
public static final String ACTION_ON_PACE_CHANGE = "onPaceChange"; public static final String ACTION_CHANGE_PACE = "changePace";
public static final String ACTION_CONFIGURE = "configure"; public static final String ACTION_CONFIGURE = "configure";
public static final String ACTION_SET_CONFIG = "setConfig"; public static final String ACTION_SET_CONFIG = "setConfig";
public static final String ACTION_ON_STATIONARY = "addStationaryRegionListener"; public static final String ACTION_ON_STATIONARY = "addStationaryRegionListener";
public static final String ACTION_GET_LOCATIONS = "getLocations"; public static final String ACTION_ADD_MOTION_CHANGE_LISTENER = "addMotionChangeListener";
public static final String ACTION_SYNC = "sync"; public static final String ACTION_ON_MOTION_CHANGE = "onMotionChange";
public static final String ACTION_GET_ODOMETER = "getOdometer"; public static final String ACTION_GET_LOCATIONS = "getLocations";
public static final String ACTION_RESET_ODOMETER = "resetOdometer"; public static final String ACTION_SYNC = "sync";
public static final String ACTION_ADD_GEOFENCE = "addGeofence"; public static final String ACTION_GET_ODOMETER = "getOdometer";
public static final String ACTION_REMOVE_GEOFENCE = "removeGeofence"; public static final String ACTION_RESET_ODOMETER = "resetOdometer";
public static final String ACTION_GET_GEOFENCES = "getGeofences"; public static final String ACTION_ADD_GEOFENCE = "addGeofence";
public static final String ACTION_ON_GEOFENCE = "onGeofence"; public static final String ACTION_REMOVE_GEOFENCE = "removeGeofence";
public static final String ACTION_PLAY_SOUND = "playSound"; public static final String ACTION_GET_GEOFENCES = "getGeofences";
public static final String ACTION_ON_GEOFENCE = "onGeofence";
public static final String ACTION_PLAY_SOUND = "playSound";
public static final String ACTION_ACTIVITY_RELOAD = "activityReload";
private Boolean isEnabled = false; private Boolean isEnabled = false;
private Boolean stopOnTerminate = false; private Boolean stopOnTerminate = false;
private Boolean isMoving = false; private Boolean isMoving = false;
private Boolean isAcquiringCurrentPosition = false; private Boolean isAcquiringCurrentPosition = false;
private long isAcquiringCurrentPositionSince; private long isAcquiringCurrentPositionSince;
private Intent backgroundServiceIntent;
private Intent backgroundServiceIntent;
private DetectedActivity currentActivity; private DetectedActivity currentActivity;
// Geolocation callback // Geolocation callback
...@@ -77,7 +80,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -77,7 +80,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
private ToneGenerator toneGenerator; private ToneGenerator toneGenerator;
private List<CallbackContext> motionChangeCallbacks = new ArrayList<CallbackContext>();
private List<CallbackContext> geofenceCallbacks = new ArrayList<CallbackContext>(); private List<CallbackContext> geofenceCallbacks = new ArrayList<CallbackContext>();
private List<CallbackContext> currentPositionCallbacks = new ArrayList<CallbackContext>();
public static boolean isActive() { public static boolean isActive() {
return gWebView != null; return gWebView != null;
...@@ -149,6 +154,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -149,6 +154,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} else if (ACTION_ON_STATIONARY.equalsIgnoreCase(action)) { } else if (ACTION_ON_STATIONARY.equalsIgnoreCase(action)) {
result = true; result = true;
this.stationaryCallback = callbackContext; this.stationaryCallback = callbackContext;
} else if (ACTION_ADD_MOTION_CHANGE_LISTENER.equalsIgnoreCase(action)) {
result = true;
this.addMotionChangeListener(callbackContext);
} else if (ACTION_GET_LOCATIONS.equalsIgnoreCase(action)) { } else if (ACTION_GET_LOCATIONS.equalsIgnoreCase(action)) {
result = true; result = true;
Bundle event = new Bundle(); Bundle event = new Bundle();
...@@ -178,53 +186,25 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -178,53 +186,25 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
resetOdometerCallback = callbackContext; resetOdometerCallback = callbackContext;
EventBus.getDefault().post(event); EventBus.getDefault().post(event);
} else if (ACTION_ADD_GEOFENCE.equalsIgnoreCase(action)) { } else if (ACTION_ADD_GEOFENCE.equalsIgnoreCase(action)) {
result = true; result = onAddGeofence(data.getJSONObject(0));
if (result) {
JSONObject config = data.getJSONObject(0);
try {
Bundle event = new Bundle();
event.putString("name", action);
event.putBoolean("request", true);
event.putFloat("radius", (float) config.getLong("radius"));
event.putDouble("latitude", config.getDouble("latitude"));
event.putDouble("longitude", config.getDouble("longitude"));
event.putString("identifier", config.getString("identifier"));
if (config.has("notifyOnEntry")) {
event.putBoolean("notifyOnEntry", config.getBoolean("notifyOnEntry"));
}
if (config.has("notifyOnExit")) {
event.putBoolean("notifyOnExit", config.getBoolean("notifyOnExit"));
}
EventBus.getDefault().post(event);
callbackContext.success(); callbackContext.success();
} catch (JSONException e) { } else {
Log.w(TAG, e);
callbackContext.error("Failed to add geofence"); callbackContext.error("Failed to add geofence");
result = false;
} }
} else if (ACTION_REMOVE_GEOFENCE.equalsIgnoreCase(action)) { } else if (ACTION_REMOVE_GEOFENCE.equalsIgnoreCase(action)) {
result = true; result = onRemoveGeofence(data.getString(0));
try { if (result) {
Bundle event = new Bundle();
event.putString("name", action);
event.putBoolean("request", true);
event.putString("identifier", data.getString(0));
EventBus.getDefault().post(event);
callbackContext.success(); callbackContext.success();
} catch (JSONException e) { } else {
Log.w(TAG, e);
callbackContext.error("Failed to add geofence"); callbackContext.error("Failed to add geofence");
result = false;
} }
} else if (ACTION_ON_GEOFENCE.equalsIgnoreCase(action)) { } else if (ACTION_ON_GEOFENCE.equalsIgnoreCase(action)) {
result = true; result = true;
geofenceCallbacks.add(callbackContext); addGeofenceListener(callbackContext);
} else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(action)) { } else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(action)) {
result = true; result = true;
getGeofencesCallback = callbackContext; getGeofencesCallback = callbackContext;
Bundle event = new Bundle(); Bundle event = new Bundle();
event.putString("name", action); event.putString("name", action);
event.putBoolean("request", true); event.putBoolean("request", true);
...@@ -323,8 +303,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -323,8 +303,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
isEnabled = value; isEnabled = value;
Activity activity = this.cordova.getActivity(); Intent launchIntent = this.cordova.getActivity().getIntent();
if (launchIntent.hasExtra("forceReload") && launchIntent.hasExtra("location")) {
try {
JSONObject location = new JSONObject(launchIntent.getStringExtra("location"));
onLocationChange(location);
} catch (JSONException e) {
Log.w(TAG, e);
}
}
Activity activity = this.cordova.getActivity();
SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0); SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("enabled", isEnabled); editor.putBoolean("enabled", isEnabled);
...@@ -352,7 +342,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -352,7 +342,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("activityIsActive", true); editor.putBoolean("activityIsActive", true);
editor.putBoolean("isMoving", isMoving);
if (config.has("distanceFilter")) { if (config.has("distanceFilter")) {
editor.putFloat("distanceFilter", config.getInt("distanceFilter")); editor.putFloat("distanceFilter", config.getInt("distanceFilter"));
...@@ -372,6 +361,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -372,6 +361,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if (config.has("minimumActivityRecognitionConfidence")) { if (config.has("minimumActivityRecognitionConfidence")) {
editor.putInt("minimumActivityRecognitionConfidence", config.getInt("minimumActivityRecognitionConfidence")); editor.putInt("minimumActivityRecognitionConfidence", config.getInt("minimumActivityRecognitionConfidence"));
} }
if (config.has("triggerActivities")) {
editor.putString("triggerActivities", config.getString("triggerActivities"));
}
if (config.has("stopTimeout")) { if (config.has("stopTimeout")) {
editor.putLong("stopTimeout", config.getLong("stopTimeout")); editor.putLong("stopTimeout", config.getLong("stopTimeout"));
} }
...@@ -388,8 +380,17 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -388,8 +380,17 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if (config.has("startOnBoot")) { if (config.has("startOnBoot")) {
editor.putBoolean("startOnBoot", config.getBoolean("startOnBoot")); editor.putBoolean("startOnBoot", config.getBoolean("startOnBoot"));
} }
if (config.has("forceReload")) { if (config.has("forceReloadOnLocationChange")) {
editor.putBoolean("forceReload", config.getBoolean("forceReload")); editor.putBoolean("forceReloadOnLocationChange", config.getBoolean("forceReloadOnLocationChange"));
}
if (config.has("forceReload")) { // @deprecated, alias to #forceReloadOnLocationChange
editor.putBoolean("forceReloadOnLocationChange", config.getBoolean("forceReload"));
}
if (config.has("forceReloadOnMotionChange")) {
editor.putBoolean("forceReloadOnMotionChange", config.getBoolean("forceReloadOnMotionChange"));
}
if (config.has("forceReloadOnGeofence")) {
editor.putBoolean("forceReloadOnGeofence", config.getBoolean("forceReloadOnGeofence"));
} }
if (config.has("url")) { if (config.has("url")) {
editor.putString("url", config.getString("url")); editor.putString("url", config.getString("url"));
...@@ -482,6 +483,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -482,6 +483,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
PluginResult result = new PluginResult(PluginResult.Status.OK); PluginResult result = new PluginResult(PluginResult.Status.OK);
resetOdometerCallback.sendPluginResult(result); resetOdometerCallback.sendPluginResult(result);
} else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) { } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) {
//PluginResult result = new PluginResult(PluginResult.Status.OK);
//paceChangeCallback.sendPluginResult(result);
int state = event.getBoolean("isMoving") ? 1 : 0; int state = event.getBoolean("isMoving") ? 1 : 0;
paceChangeCallback.success(state); paceChangeCallback.success(state);
} else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) { } else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) {
...@@ -495,9 +498,28 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -495,9 +498,28 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
runInBackground(getGeofencesCallback, result); runInBackground(getGeofencesCallback, result);
} }
} else if (ACTION_ON_MOTION_CHANGE.equalsIgnoreCase(name)) {
this.onMotionChange(event);
} }
} }
private void onMotionChange(Bundle event) {
PluginResult result;
try {
JSONObject params = new JSONObject();
params.put("location", new JSONObject(event.getString("location")));
params.put("isMoving", event.getBoolean("isMoving"));
params.put("taskId", "android-bg-task-id");
result = new PluginResult(PluginResult.Status.OK, params);
} catch (JSONException e) {
e.printStackTrace();
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
}
result.setKeepCallback(true);
for (CallbackContext callback : motionChangeCallbacks) {
runInBackground(callback, result);
}
}
/** /**
* EventBus listener for ARS * EventBus listener for ARS
* @param {ActivityRecognitionResult} result * @param {ActivityRecognitionResult} result
...@@ -522,9 +544,16 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -522,9 +544,16 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* @param {Location} location * @param {Location} location
*/ */
public void onEventMainThread(Location location) { public void onEventMainThread(Location location) {
PluginResult result; JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity);
result = new PluginResult(PluginResult.Status.OK, BackgroundGeolocationService.locationToJson(location, currentActivity)); this.onLocationChange(locationData);
}
private void onLocationChange(JSONObject location) {
PluginResult result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(true);
isMoving = true;
result.setKeepCallback(true); result.setKeepCallback(true);
runInBackground(locationCallback, result);
if (isAcquiringCurrentPosition) { if (isAcquiringCurrentPosition) {
// Current position has arrived: release the hounds. // Current position has arrived: release the hounds.
...@@ -534,10 +563,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -534,10 +563,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
result.setKeepCallback(false); result.setKeepCallback(false);
runInBackground(callback, result); runInBackground(callback, result);
} }
} else { currentPositionCallbacks.clear();
isMoving = true;
result.setKeepCallback(true);
runInBackground(locationCallback, result);
} }
} }
/** /**
...@@ -548,30 +574,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -548,30 +574,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if (!geofenceCallbacks.isEmpty()) { if (!geofenceCallbacks.isEmpty()) {
for (Geofence geofence : geofenceEvent.getTriggeringGeofences()) { for (Geofence geofence : geofenceEvent.getTriggeringGeofences()) {
JSONObject params = new JSONObject(); JSONObject params = BackgroundGeolocationService.geofencingEventToJson(geofenceEvent, geofence);
String action = ""; handleGeofencingEvent(params);
int transitionType = geofenceEvent.getGeofenceTransition();
if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) {
action = "ENTER";
} else if (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
action = "EXIT";
} else {
action = "DWELL";
}
try {
params.put("identifier", geofence.getRequestId());
params.put("action", action);
} catch (JSONException e) {
e.printStackTrace();
}
PluginResult result = new PluginResult(PluginResult.Status.OK, params);
result.setKeepCallback(true);
for (CallbackContext callback : geofenceCallbacks) {
runInBackground(callback, result);
}
} }
} }
} }
private void handleGeofencingEvent(JSONObject params) {
PluginResult result = new PluginResult(PluginResult.Status.OK, params);
result.setKeepCallback(true);
for (CallbackContext callback : geofenceCallbacks) {
runInBackground(callback, result);
}
}
private void playSound(int soundId) { private void playSound(int soundId) {
int duration = 1000; int duration = 1000;
......
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