Commit c0292424 authored by Chris Scott's avatar Chris Scott

Merge pull request #126 from christocracy/edge

Edge
parents 01b75f33 cd3a21b6
...@@ -8,7 +8,7 @@ Follows the [Cordova Plugin spec](http://cordova.apache.org/docs/en/3.0.0/plugin ...@@ -8,7 +8,7 @@ Follows the [Cordova Plugin spec](http://cordova.apache.org/docs/en/3.0.0/plugin
This plugin leverages Cordova/PhoneGap's [require/define functionality used for plugins](http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html). This plugin leverages Cordova/PhoneGap's [require/define functionality used for plugins](http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html).
## Using the plugin ## ## Using the plugin ##
The plugin creates the object `window.plugins.backgroundGeoLocation` with the methods The plugin creates the object `window.BackgroundGeolocation` with the methods
`configure(success, fail, option)`, `configure(success, fail, option)`,
...@@ -61,11 +61,18 @@ The plugin creates the object `window.plugins.backgroundGeoLocation` with the me ...@@ -61,11 +61,18 @@ The plugin creates the object `window.plugins.backgroundGeoLocation` with the me
// As with all Cordova plugins, you must configure within an #deviceready callback. // As with all Cordova plugins, you must configure within an #deviceready callback.
// //
function onDeviceReady() { function onDeviceReady() {
// Get a reference to the plugin.
var bgGeo = window.BackgroundGeolocation;
/** /**
* This callback will be executed every time a geolocation is recorded in the background. * This callback will be executed every time a geolocation is recorded in the background.
*/ */
var callbackFn = function(location, taskId) { var callbackFn = function(location, taskId) {
console.log('[js] BackgroundGeoLocation callback: ' + location.latitude + ',' + location.longitude); var coords = location.coords;
var lat = coords.latitude;
var lng = coords.longitude;
console.log('[js] BackgroundGeoLocation callback: ' + JSON.stringify(location));
/** /**
* This would be your own callback for Ajax-requests after POSTing background geolocation to your server. * This would be your own callback for Ajax-requests after POSTing background geolocation to your server.
......
...@@ -134,7 +134,7 @@ var app = { ...@@ -134,7 +134,7 @@ var app = {
app.watchForegroundPosition(); app.watchForegroundPosition();
}, },
configureBackgroundGeoLocation: function() { configureBackgroundGeoLocation: function() {
var bgGeo = window.plugins.backgroundGeoLocation; var bgGeo = window.BackgroundGeolocation;
app.onClickHome(); app.onClickHome();
...@@ -281,7 +281,7 @@ var app = { ...@@ -281,7 +281,7 @@ var app = {
} }
}, },
onClickChangePace: function(value) { onClickChangePace: function(value) {
var bgGeo = window.plugins.backgroundGeoLocation, var bgGeo = window.BackgroundGeolocation,
btnPace = app.btnPace; btnPace = app.btnPace;
btnPace.removeClass('btn-success'); btnPace.removeClass('btn-success');
...@@ -309,7 +309,7 @@ var app = { ...@@ -309,7 +309,7 @@ var app = {
app.path = undefined; app.path = undefined;
}, },
onClickToggleEnabled: function(value) { onClickToggleEnabled: function(value) {
var bgGeo = window.plugins.backgroundGeoLocation, var bgGeo = window.BackgroundGeolocation,
btnEnabled = app.btnEnabled, btnEnabled = app.btnEnabled,
isEnabled = ENV.toggle('enabled'); isEnabled = ENV.toggle('enabled');
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="com.transistorsoft.cordova.background-geolocation" id="com.transistorsoft.cordova.background-geolocation"
version="0.5.2"> version="0.5.3">
<name>BackgroundGeolocation</name> <name>BackgroundGeolocation</name>
<description>Sophisticated, battery-efficient background-geolocation plugin for Cordova</description> <description>Sophisticated, battery-efficient background-geolocation plugin for Cordova</description>
<license>MIT</license> <license>MIT</license>
...@@ -13,17 +13,23 @@ ...@@ -13,17 +13,23 @@
<engine name="cordova" version=">=3.0.0" /> <engine name="cordova" version=">=3.0.0" />
</engines> </engines>
<!--
Pre-Cordova 5, non-npm plugin reference. Uncomment this if you're not using Cordova 5.
<dependency id="org.apache.cordova.dialogs" /> <dependency id="org.apache.cordova.dialogs" />
-->
<js-module src="www/BackgroundGeoLocation.js" name="BackgroundGeoLocation"> <!-- Cordova 5 npm-style plugin referernce. Comment this out if you're not using Cordova 5 -->
<clobbers target="plugins.backgroundGeoLocation" /> <dependency id="cordova-plugin-dialogs" />
<js-module src="www/BackgroundGeolocation.js" name="BackgroundGeolocation">
<clobbers target="window.BackgroundGeolocation" />
</js-module> </js-module>
<!-- android --> <!-- android -->
<platform name="android"> <platform name="android">
<framework src="com.google.android.gms:play-services-location:7.3.0" /> <framework src="src/android/build.gradle" custom="true" type="gradleReference" />
<source-file src="src/android/libs/eventbus-2.4.0.jar" target-dir="libs" /> <resource-file src="src/android/libs/tslocationmanager.aar" target="src/android/libs/tslocationmanager.aar" />
<source-file src="src/android/libs/transistor-locationmanager.jar" target-dir="libs" />
<source-file src="src/android/CDVBackgroundGeolocation.java" target-dir="src/com/transistorsoft/cordova/bggeo" /> <source-file src="src/android/CDVBackgroundGeolocation.java" target-dir="src/com/transistorsoft/cordova/bggeo" />
<source-file src="src/android/BootReceiver.java" target-dir="src/com/transistorsoft/cordova/bggeo" /> <source-file src="src/android/BootReceiver.java" target-dir="src/com/transistorsoft/cordova/bggeo" />
...@@ -51,7 +57,7 @@ ...@@ -51,7 +57,7 @@
</config-file> </config-file>
<config-file target="res/xml/config.xml" parent="/*"> <config-file target="res/xml/config.xml" parent="/*">
<feature name="BackgroundGeoLocation"> <feature name="BackgroundGeolocation">
<param name="android-package" value="com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation"/> <param name="android-package" value="com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation"/>
</feature> </feature>
</config-file> </config-file>
...@@ -61,7 +67,7 @@ ...@@ -61,7 +67,7 @@
<!-- required background modes: App registers for location updates --> <!-- required background modes: App registers for location updates -->
<config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription"> <config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
<string>This app requires background location tracking</string> <string>TSLocationManager requires background location tracking</string>
</config-file> </config-file>
<config-file target="*-Info.plist" parent="UIBackgroundModes"> <config-file target="*-Info.plist" parent="UIBackgroundModes">
...@@ -71,7 +77,7 @@ ...@@ -71,7 +77,7 @@
</config-file> </config-file>
<config-file target="config.xml" parent="/*"> <config-file target="config.xml" parent="/*">
<feature name="BackgroundGeoLocation"> <feature name="BackgroundGeolocation">
<param name="ios-package" value="CDVBackgroundGeolocation"/> <param name="ios-package" value="CDVBackgroundGeolocation"/>
</feature> </feature>
</config-file> </config-file>
......
...@@ -20,6 +20,7 @@ import android.app.AlertDialog; ...@@ -20,6 +20,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -217,11 +218,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -217,11 +218,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
callbackContext.success(); callbackContext.success();
} else if (BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION.equalsIgnoreCase(action)) { } else if (BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION.equalsIgnoreCase(action)) {
result = true; result = true;
if (!isEnabled) { onGetCurrentPosition(callbackContext);
callbackContext.error(401); // aka HTTP UNAUTHORIZED
} else {
onGetCurrentPosition(callbackContext);
}
} }
return result; return result;
} }
...@@ -231,10 +228,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -231,10 +228,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
isAcquiringCurrentPositionSince = System.nanoTime(); isAcquiringCurrentPositionSince = System.nanoTime();
addCurrentPositionListener(callbackContext); addCurrentPositionListener(callbackContext);
Bundle event = new Bundle(); if (!isEnabled) {
event.putString("name", BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION); EventBus.getDefault().register(this);
event.putBoolean("request", true); if (!BackgroundGeolocationService.isInstanceCreated()) {
EventBus.getDefault().post(event); backgroundServiceIntent.putExtra("command", BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION);
this.cordova.getActivity().startService(backgroundServiceIntent);
}
} else {
Bundle event = new Bundle();
event.putString("name", BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION);
event.putBoolean("request", true);
EventBus.getDefault().post(event);
}
} }
private Boolean onAddGeofence(JSONObject config) { private Boolean onAddGeofence(JSONObject config) {
try { try {
...@@ -310,6 +315,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -310,6 +315,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
try { try {
JSONObject location = new JSONObject(launchIntent.getStringExtra("location")); JSONObject location = new JSONObject(launchIntent.getStringExtra("location"));
onLocationChange(location); onLocationChange(location);
launchIntent.removeExtra("forceReload");
launchIntent.removeExtra("location");
} catch (JSONException e) { } catch (JSONException e) {
Log.w(TAG, e); Log.w(TAG, e);
} }
...@@ -442,6 +449,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -442,6 +449,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener for Event Bundle * EventBus listener for Event Bundle
* @param {Bundle} event * @param {Bundle} event
*/ */
@Subscribe
public void onEventMainThread(Bundle event) { public void onEventMainThread(Bundle event) {
if (event.containsKey("request")) { if (event.containsKey("request")) {
return; return;
...@@ -529,6 +537,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -529,6 +537,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener for ARS * EventBus listener for ARS
* @param {ActivityRecognitionResult} result * @param {ActivityRecognitionResult} result
*/ */
@Subscribe
public void onEventMainThread(ActivityRecognitionResult result) { public void onEventMainThread(ActivityRecognitionResult result) {
currentActivity = result.getMostProbableActivity(); currentActivity = result.getMostProbableActivity();
...@@ -548,20 +557,30 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -548,20 +557,30 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener * EventBus listener
* @param {Location} location * @param {Location} location
*/ */
@Subscribe
public void onEventMainThread(Location location) { public void onEventMainThread(Location location) {
JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity, isMoving); JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity, isMoving);
this.onLocationChange(locationData); this.onLocationChange(locationData);
} }
private void onLocationChange(JSONObject location) { private void onLocationChange(JSONObject location) {
Log.i(TAG, "- CDVBackgroundGeolocation Rx Location: " + isEnabled);
PluginResult result = new PluginResult(PluginResult.Status.OK, location); PluginResult result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(true); result.setKeepCallback(true);
result.setKeepCallback(true);
runInBackground(locationCallback, result); runInBackground(locationCallback, result);
if (isAcquiringCurrentPosition) { if (isAcquiringCurrentPosition) {
// Current position has arrived: release the hounds. // Current position has arrived: release the hounds.
isAcquiringCurrentPosition = false; isAcquiringCurrentPosition = false;
// When currentPosition is explicitly requested while plugin is stopped, shut Service down again and stop listening to EventBus
if (!isEnabled) {
backgroundServiceIntent.removeExtra("command");
EventBus.getDefault().unregister(this);
this.cordova.getActivity().stopService(backgroundServiceIntent);
}
// Execute callbacks.
for (CallbackContext callback : currentPositionCallbacks) { for (CallbackContext callback : currentPositionCallbacks) {
result = new PluginResult(PluginResult.Status.OK, location); result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(false); result.setKeepCallback(false);
...@@ -572,7 +591,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin { ...@@ -572,7 +591,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} }
/** /**
* EventBus handler for Geofencing events * EventBus handler for Geofencing events
*/ */
@Subscribe
public void onEventMainThread(GeofencingEvent geofenceEvent) { public void onEventMainThread(GeofencingEvent geofenceEvent) {
Log.i(TAG, "- Rx GeofencingEvent: " + geofenceEvent); Log.i(TAG, "- Rx GeofencingEvent: " + geofenceEvent);
......
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories{
jcenter()
flatDir{
dirs 'src/android/libs'
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile 'de.greenrobot:eventbus:3.0.0-beta1'
compile(name:'tslocationmanager', ext:'aar')
}
...@@ -324,13 +324,6 @@ ...@@ -324,13 +324,6 @@
- (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];
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</data> </data>
<key>Info.plist</key> <key>Info.plist</key>
<data> <data>
1G+AqP61j6Sq6MmsyYP98Uqa1/Y= ksNaWGtWPICW6cxKIrDME82hHsk=
</data> </data>
<key>Modules/module.modulemap</key> <key>Modules/module.modulemap</key>
<data> <data>
......
...@@ -40,7 +40,7 @@ module.exports = { ...@@ -40,7 +40,7 @@ module.exports = {
} }
exec(mySuccess, exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'configure', 'configure',
[config] [config]
); );
...@@ -48,14 +48,14 @@ module.exports = { ...@@ -48,14 +48,14 @@ module.exports = {
start: function(success, failure, config) { start: function(success, failure, config) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'start', 'start',
[]); []);
}, },
stop: function(success, failure, config) { stop: function(success, failure, config) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'stop', 'stop',
[]); []);
}, },
...@@ -65,7 +65,7 @@ module.exports = { ...@@ -65,7 +65,7 @@ module.exports = {
} }
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'finish', 'finish',
[taskId]); [taskId]);
}, },
...@@ -75,14 +75,14 @@ module.exports = { ...@@ -75,14 +75,14 @@ module.exports = {
} }
exec(function() {}, exec(function() {},
function() {}, function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'error', 'error',
[taskId, message]); [taskId, message]);
}, },
changePace: function(isMoving, success, failure) { changePace: function(isMoving, success, failure) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'changePace', 'changePace',
[isMoving]); [isMoving]);
}, },
...@@ -96,7 +96,7 @@ module.exports = { ...@@ -96,7 +96,7 @@ module.exports = {
this._apply(this.config, config); this._apply(this.config, config);
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'setConfig', 'setConfig',
[config]); [config]);
}, },
...@@ -106,7 +106,7 @@ module.exports = { ...@@ -106,7 +106,7 @@ module.exports = {
getStationaryLocation: function(success, failure) { getStationaryLocation: function(success, failure) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'getStationaryLocation', 'getStationaryLocation',
[]); []);
}, },
...@@ -133,7 +133,7 @@ module.exports = { ...@@ -133,7 +133,7 @@ module.exports = {
}; };
exec(callback, exec(callback,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'addStationaryRegionListener', 'addStationaryRegionListener',
[]); []);
}, },
...@@ -162,7 +162,7 @@ module.exports = { ...@@ -162,7 +162,7 @@ module.exports = {
}; };
exec(callback, exec(callback,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'addMotionChangeListener', 'addMotionChangeListener',
[]); []);
}, },
...@@ -180,7 +180,7 @@ module.exports = { ...@@ -180,7 +180,7 @@ module.exports = {
} }
exec(mySuccess, exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'getLocations', 'getLocations',
[]); []);
}, },
...@@ -202,7 +202,7 @@ module.exports = { ...@@ -202,7 +202,7 @@ module.exports = {
} }
exec(mySuccess, exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'sync', 'sync',
[]); []);
}, },
...@@ -212,7 +212,7 @@ module.exports = { ...@@ -212,7 +212,7 @@ module.exports = {
getOdometer: function(success, failure) { getOdometer: function(success, failure) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'getOdometer', 'getOdometer',
[]); []);
}, },
...@@ -222,7 +222,7 @@ module.exports = { ...@@ -222,7 +222,7 @@ module.exports = {
resetOdometer: function(success, failure) { resetOdometer: function(success, failure) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'resetOdometer', 'resetOdometer',
[]); []);
}, },
...@@ -245,7 +245,7 @@ module.exports = { ...@@ -245,7 +245,7 @@ module.exports = {
} }
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'addGeofence', 'addGeofence',
[config]); [config]);
}, },
...@@ -259,7 +259,7 @@ module.exports = { ...@@ -259,7 +259,7 @@ module.exports = {
} }
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'removeGeofence', 'removeGeofence',
[identifier]); [identifier]);
}, },
...@@ -278,7 +278,7 @@ module.exports = { ...@@ -278,7 +278,7 @@ module.exports = {
}; };
exec(mySuccess, exec(mySuccess,
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'onGeofence', 'onGeofence',
[]); []);
}, },
...@@ -288,7 +288,7 @@ module.exports = { ...@@ -288,7 +288,7 @@ module.exports = {
getGeofences: function(success, failure) { getGeofences: function(success, failure) {
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'getGeofences', 'getGeofences',
[]); []);
}, },
...@@ -313,7 +313,7 @@ module.exports = { ...@@ -313,7 +313,7 @@ module.exports = {
} }
exec(mySuccess || function() {}, exec(mySuccess || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeolocation',
'getCurrentPosition', 'getCurrentPosition',
[]); []);
}, },
...@@ -327,7 +327,7 @@ module.exports = { ...@@ -327,7 +327,7 @@ module.exports = {
var failure = function() {}; var failure = function() {};
exec(success, exec(success,
failure, failure,
'BackgroundGeoLocation', 'BackgroundGeolocation',
'playSound', 'playSound',
[soundId]); [soundId]);
}, },
......
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