Commit dd1f40b7 authored by Chris Scott's avatar Chris Scott

Add is_moving state to each Location -- not the HTTP request

parent ab88653f
...@@ -10,6 +10,7 @@ import org.json.JSONArray; ...@@ -10,6 +10,7 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONException; import org.json.JSONException;
import android.os.Bundle; import android.os.Bundle;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.ActivityRecognitionResult; import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity; import com.google.android.gms.location.DetectedActivity;
import com.transistorsoft.locationmanager.BackgroundGeolocationService; import com.transistorsoft.locationmanager.BackgroundGeolocationService;
...@@ -133,11 +134,12 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -133,11 +134,12 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
callbackContext.error("Cannot #changePace while disabled"); callbackContext.error("Cannot #changePace while disabled");
} else { } else {
result = true; result = true;
isMoving = data.getBoolean(0);
paceChangeCallback = callbackContext; paceChangeCallback = 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);
event.putBoolean("isMoving", data.getBoolean(0)); event.putBoolean("isMoving", isMoving);
EventBus.getDefault().post(event); EventBus.getDefault().post(event);
} }
} else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) { } else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) {
...@@ -500,15 +502,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -500,15 +502,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
} else if (ACTION_ON_MOTION_CHANGE.equalsIgnoreCase(name)) { } else if (ACTION_ON_MOTION_CHANGE.equalsIgnoreCase(name)) {
this.onMotionChange(event); this.onMotionChange(event);
} else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GOOGLE_PLAY_SERVICES_CONNECT_ERROR)) {
GooglePlayServicesUtil.getErrorDialog(event.getInt("errorCode"), this.cordova.getActivity(), 1001).show();
} }
} }
private void onMotionChange(Bundle event) { private void onMotionChange(Bundle event) {
PluginResult result; PluginResult result;
isMoving = event.getBoolean("isMoving");
try { try {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("location", new JSONObject(event.getString("location"))); params.put("location", new JSONObject(event.getString("location")));
params.put("isMoving", event.getBoolean("isMoving")); params.put("isMoving", isMoving);
params.put("taskId", "android-bg-task-id"); params.put("taskId", "android-bg-task-id");
result = new PluginResult(PluginResult.Status.OK, params); result = new PluginResult(PluginResult.Status.OK, params);
} catch (JSONException e) { } catch (JSONException e) {
...@@ -544,14 +549,13 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -544,14 +549,13 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* @param {Location} location * @param {Location} location
*/ */
public void onEventMainThread(Location location) { public void onEventMainThread(Location location) {
JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity); JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity, isMoving);
this.onLocationChange(locationData); this.onLocationChange(locationData);
} }
private void onLocationChange(JSONObject location) { private void onLocationChange(JSONObject location) {
PluginResult result = new PluginResult(PluginResult.Status.OK, location); PluginResult result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(true); result.setKeepCallback(true);
isMoving = true;
result.setKeepCallback(true); result.setKeepCallback(true);
runInBackground(locationCallback, result); runInBackground(locationCallback, result);
......
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