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
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 ##
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)`,
......@@ -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.
//
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.
*/
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.
......
......@@ -134,7 +134,7 @@ var app = {
app.watchForegroundPosition();
},
configureBackgroundGeoLocation: function() {
var bgGeo = window.plugins.backgroundGeoLocation;
var bgGeo = window.BackgroundGeolocation;
app.onClickHome();
......@@ -281,7 +281,7 @@ var app = {
}
},
onClickChangePace: function(value) {
var bgGeo = window.plugins.backgroundGeoLocation,
var bgGeo = window.BackgroundGeolocation,
btnPace = app.btnPace;
btnPace.removeClass('btn-success');
......@@ -309,7 +309,7 @@ var app = {
app.path = undefined;
},
onClickToggleEnabled: function(value) {
var bgGeo = window.plugins.backgroundGeoLocation,
var bgGeo = window.BackgroundGeolocation,
btnEnabled = app.btnEnabled,
isEnabled = ENV.toggle('enabled');
......
......@@ -3,7 +3,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.transistorsoft.cordova.background-geolocation"
version="0.5.2">
version="0.5.3">
<name>BackgroundGeolocation</name>
<description>Sophisticated, battery-efficient background-geolocation plugin for Cordova</description>
<license>MIT</license>
......@@ -13,17 +13,23 @@
<engine name="cordova" version=">=3.0.0" />
</engines>
<!--
Pre-Cordova 5, non-npm plugin reference. Uncomment this if you're not using Cordova 5.
<dependency id="org.apache.cordova.dialogs" />
-->
<js-module src="www/BackgroundGeoLocation.js" name="BackgroundGeoLocation">
<clobbers target="plugins.backgroundGeoLocation" />
<!-- Cordova 5 npm-style plugin referernce. Comment this out if you're not using Cordova 5 -->
<dependency id="cordova-plugin-dialogs" />
<js-module src="www/BackgroundGeolocation.js" name="BackgroundGeolocation">
<clobbers target="window.BackgroundGeolocation" />
</js-module>
<!-- android -->
<platform name="android">
<framework src="com.google.android.gms:play-services-location:7.3.0" />
<source-file src="src/android/libs/eventbus-2.4.0.jar" target-dir="libs" />
<source-file src="src/android/libs/transistor-locationmanager.jar" target-dir="libs" />
<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
<resource-file src="src/android/libs/tslocationmanager.aar" target="src/android/libs/tslocationmanager.aar" />
<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" />
......@@ -51,7 +57,7 @@
</config-file>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="BackgroundGeoLocation">
<feature name="BackgroundGeolocation">
<param name="android-package" value="com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation"/>
</feature>
</config-file>
......@@ -61,7 +67,7 @@
<!-- required background modes: App registers for location updates -->
<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 target="*-Info.plist" parent="UIBackgroundModes">
......@@ -71,7 +77,7 @@
</config-file>
<config-file target="config.xml" parent="/*">
<feature name="BackgroundGeoLocation">
<feature name="BackgroundGeolocation">
<param name="ios-package" value="CDVBackgroundGeolocation"/>
</feature>
</config-file>
......
......@@ -20,6 +20,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -217,11 +218,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
callbackContext.success();
} else if (BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION.equalsIgnoreCase(action)) {
result = true;
if (!isEnabled) {
callbackContext.error(401); // aka HTTP UNAUTHORIZED
} else {
onGetCurrentPosition(callbackContext);
}
onGetCurrentPosition(callbackContext);
}
return result;
}
......@@ -231,10 +228,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
isAcquiringCurrentPositionSince = System.nanoTime();
addCurrentPositionListener(callbackContext);
Bundle event = new Bundle();
event.putString("name", BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION);
event.putBoolean("request", true);
EventBus.getDefault().post(event);
if (!isEnabled) {
EventBus.getDefault().register(this);
if (!BackgroundGeolocationService.isInstanceCreated()) {
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) {
try {
......@@ -310,6 +315,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
try {
JSONObject location = new JSONObject(launchIntent.getStringExtra("location"));
onLocationChange(location);
launchIntent.removeExtra("forceReload");
launchIntent.removeExtra("location");
} catch (JSONException e) {
Log.w(TAG, e);
}
......@@ -442,6 +449,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener for Event Bundle
* @param {Bundle} event
*/
@Subscribe
public void onEventMainThread(Bundle event) {
if (event.containsKey("request")) {
return;
......@@ -529,6 +537,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener for ARS
* @param {ActivityRecognitionResult} result
*/
@Subscribe
public void onEventMainThread(ActivityRecognitionResult result) {
currentActivity = result.getMostProbableActivity();
......@@ -548,20 +557,30 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* EventBus listener
* @param {Location} location
*/
@Subscribe
public void onEventMainThread(Location location) {
JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity, isMoving);
this.onLocationChange(locationData);
}
private void onLocationChange(JSONObject location) {
Log.i(TAG, "- CDVBackgroundGeolocation Rx Location: " + isEnabled);
PluginResult result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(true);
result.setKeepCallback(true);
runInBackground(locationCallback, result);
if (isAcquiringCurrentPosition) {
// Current position has arrived: release the hounds.
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) {
result = new PluginResult(PluginResult.Status.OK, location);
result.setKeepCallback(false);
......@@ -572,7 +591,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
}
/**
* EventBus handler for Geofencing events
*/
*/
@Subscribe
public void onEventMainThread(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 @@
- (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) {
self.currentPositionListeners = [[NSMutableArray alloc] init];
}
......
......@@ -10,7 +10,7 @@
</data>
<key>Info.plist</key>
<data>
1G+AqP61j6Sq6MmsyYP98Uqa1/Y=
ksNaWGtWPICW6cxKIrDME82hHsk=
</data>
<key>Modules/module.modulemap</key>
<data>
......
......@@ -40,7 +40,7 @@ module.exports = {
}
exec(mySuccess,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'configure',
[config]
);
......@@ -48,14 +48,14 @@ module.exports = {
start: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'start',
[]);
},
stop: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'stop',
[]);
},
......@@ -65,7 +65,7 @@ module.exports = {
}
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'finish',
[taskId]);
},
......@@ -75,14 +75,14 @@ module.exports = {
}
exec(function() {},
function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'error',
[taskId, message]);
},
changePace: function(isMoving, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'changePace',
[isMoving]);
},
......@@ -96,7 +96,7 @@ module.exports = {
this._apply(this.config, config);
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'setConfig',
[config]);
},
......@@ -106,7 +106,7 @@ module.exports = {
getStationaryLocation: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'getStationaryLocation',
[]);
},
......@@ -133,7 +133,7 @@ module.exports = {
};
exec(callback,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'addStationaryRegionListener',
[]);
},
......@@ -162,7 +162,7 @@ module.exports = {
};
exec(callback,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'addMotionChangeListener',
[]);
},
......@@ -180,7 +180,7 @@ module.exports = {
}
exec(mySuccess,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'getLocations',
[]);
},
......@@ -202,7 +202,7 @@ module.exports = {
}
exec(mySuccess,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'sync',
[]);
},
......@@ -212,7 +212,7 @@ module.exports = {
getOdometer: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'getOdometer',
[]);
},
......@@ -222,7 +222,7 @@ module.exports = {
resetOdometer: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'resetOdometer',
[]);
},
......@@ -245,7 +245,7 @@ module.exports = {
}
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'addGeofence',
[config]);
},
......@@ -259,7 +259,7 @@ module.exports = {
}
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'removeGeofence',
[identifier]);
},
......@@ -278,7 +278,7 @@ module.exports = {
};
exec(mySuccess,
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'onGeofence',
[]);
},
......@@ -288,7 +288,7 @@ module.exports = {
getGeofences: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'getGeofences',
[]);
},
......@@ -313,7 +313,7 @@ module.exports = {
}
exec(mySuccess || function() {},
failure || function() {},
'BackgroundGeoLocation',
'BackgroundGeolocation',
'getCurrentPosition',
[]);
},
......@@ -327,7 +327,7 @@ module.exports = {
var failure = function() {};
exec(success,
failure,
'BackgroundGeoLocation',
'BackgroundGeolocation',
'playSound',
[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