Commit 52ac07a4 authored by Chris Scott's avatar Chris Scott

Merge pull request #37 from christocracy/bug_fixes

Cast timestamp to Javascript new Date() before sending to callback.  …
parents b3c69c6d 32e6f4d4
...@@ -8,6 +8,8 @@ import org.json.JSONArray; ...@@ -8,6 +8,8 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONException; import org.json.JSONException;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;
import com.transistorsoft.locationmanager.BackgroundGeolocationService; import com.transistorsoft.locationmanager.BackgroundGeolocationService;
import com.transistorsoft.locationmanager.BackgroundGeolocationService.PaceChangeEvent; import com.transistorsoft.locationmanager.BackgroundGeolocationService.PaceChangeEvent;
import com.transistorsoft.locationmanager.BackgroundGeolocationService.PausedEvent; import com.transistorsoft.locationmanager.BackgroundGeolocationService.PausedEvent;
...@@ -39,6 +41,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -39,6 +41,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
private Intent backgroundServiceIntent; private Intent backgroundServiceIntent;
private DetectedActivity currentActivity;
// Geolocation callback // Geolocation callback
private CallbackContext locationCallback; private CallbackContext locationCallback;
// Called when DetectedActivity is STILL // Called when DetectedActivity is STILL
...@@ -205,12 +209,23 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -205,12 +209,23 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
} }
/**
* EventBus listener for ARS
* @param {ActivityRecognitionResult} result
*/
public void onEventMainThread(ActivityRecognitionResult result) {
currentActivity = result.getMostProbableActivity();
String activityName = BackgroundGeolocationService.getActivityName(currentActivity.getType());
int confidence = currentActivity.getConfidence();
Log.i(TAG, "----------- currentActivity: " + currentActivity);
}
/** /**
* EventBus listener * EventBus listener
* @param {Location} location * @param {Location} location
*/ */
public void onEventMainThread(Location location) { public void onEventMainThread(Location location) {
PluginResult result = new PluginResult(PluginResult.Status.OK, BackgroundGeolocationService.locationToJson(location)); PluginResult result;
result = new PluginResult(PluginResult.Status.OK, BackgroundGeolocationService.locationToJson(location, currentActivity));
result.setKeepCallback(true); result.setKeepCallback(true);
if (location instanceof com.transistorsoft.locationmanager.BackgroundGeolocationService.StationaryLocation) { if (location instanceof com.transistorsoft.locationmanager.BackgroundGeolocationService.StationaryLocation) {
......
...@@ -20,8 +20,15 @@ module.exports = { ...@@ -20,8 +20,15 @@ module.exports = {
configure: function(success, failure, config) { configure: function(success, failure, config) {
config = config || {}; config = config || {};
this.config = config; this.config = config;
success = success || function(location) {};
exec(success || function() {}, var mySuccess = function(location) {
// Transform timestamp to Date instance.
if (location.timestamp) {
location.timestamp = new Date(location.timestamp);
}
success.call(this, location);
}
exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'configure', 'configure',
......
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