Commit 1abaa6e1 authored by affinionmobile's avatar affinionmobile

Merge pull request #31 from christocracy/extract_to_lib

ATTENTION EVERYONE!
parents 35eba74a 796ab79a
*.DS_Store
This diff is collapsed.
...@@ -9,4 +9,19 @@ ...@@ -9,4 +9,19 @@
</author> </author>
<content src="index.html" /> <content src="index.html" />
<access origin="*" /> <access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget> </widget>
...@@ -24,12 +24,11 @@ ...@@ -24,12 +24,11 @@
<meta name="msapplication-tap-highlight" content="no" /> <meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline' data:; img-src *; script-src * 'unsafe-inline' 'unsafe-eval'">
<link rel="stylesheet" type="text/css" href="css/bootstrap-min.css" /> <link rel="stylesheet" type="text/css" href="css/bootstrap-min.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" /> <link rel="stylesheet" type="text/css" href="css/index.css" />
<title>BG GeoLocation</title> <title>BG GeoLocation</title>
<script type="text/javascript" <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>
src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry">
</script>
</head> </head>
<body> <body>
......
...@@ -36,7 +36,7 @@ var app = { ...@@ -36,7 +36,7 @@ var app = {
/** /**
* @property {google.maps.Marker} location The current location * @property {google.maps.Marker} location The current location
*/ */
location: undefined, currentLocationMarker: undefined,
/** /**
* @property {google.map.PolyLine} path The list of background geolocations * @property {google.map.PolyLine} path The list of background geolocations
*/ */
...@@ -49,6 +49,10 @@ var app = { ...@@ -49,6 +49,10 @@ var app = {
* @property {Array} locations List of rendered map markers of prev locations * @property {Array} locations List of rendered map markers of prev locations
*/ */
locations: [], locations: [],
/**
* @property currentLocation {Location}
*/
currentLocation: null,
/** /**
* @private * @private
*/ */
...@@ -120,11 +124,10 @@ var app = { ...@@ -120,11 +124,10 @@ var app = {
onDeviceReady: function() { onDeviceReady: function() {
app.receivedEvent('deviceready'); app.receivedEvent('deviceready');
app.configureBackgroundGeoLocation(); app.configureBackgroundGeoLocation();
app.watchPosition(); app.watchForegroundPosition();
}, },
configureBackgroundGeoLocation: function() { configureBackgroundGeoLocation: function() {
var fgGeo = window.navigator.geolocation, var bgGeo = window.plugins.backgroundGeoLocation;
bgGeo = window.plugins.backgroundGeoLocation;
app.onClickHome(); app.onClickHome();
...@@ -132,6 +135,8 @@ var app = { ...@@ -132,6 +135,8 @@ var app = {
* 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.
*/ */
var yourAjaxCallback = function(response) { var yourAjaxCallback = function(response) {
// Very important to call #finish -- it signals to the native plugin that it can destroy the background thread, which your callbackFn is running in.
// IF YOU DON'T, THE OS CAN KILL YOUR APP FOR RUNNING TOO LONG IN THE BACKGROUND
bgGeo.finish(); bgGeo.finish();
}; };
...@@ -155,6 +160,14 @@ var app = { ...@@ -155,6 +160,14 @@ var app = {
// Only ios emits this stationary event // Only ios emits this stationary event
bgGeo.onStationary(function(location) { bgGeo.onStationary(function(location) {
console.log('[js] BackgroundGeoLocation onStationary ' + JSON.stringify(location)); console.log('[js] BackgroundGeoLocation onStationary ' + JSON.stringify(location));
app.setCurrentLocation(location);
var coords = location.coords;
// Center ourself on map
app.onClickHome();
if (!app.stationaryRadius) { if (!app.stationaryRadius) {
app.stationaryRadius = new google.maps.Circle({ app.stationaryRadius = new google.maps.Circle({
fillColor: '#cc0000', fillColor: '#cc0000',
...@@ -163,8 +176,8 @@ var app = { ...@@ -163,8 +176,8 @@ var app = {
map: app.map map: app.map
}); });
} }
var radius = (location.accuracy < location.radius) ? location.radius : location.accuracy; var radius = 50;
var center = new google.maps.LatLng(location.latitude, location.longitude); var center = new google.maps.LatLng(coords.latitude, coords.longitude);
app.stationaryRadius.setRadius(radius); app.stationaryRadius.setRadius(radius);
app.stationaryRadius.setCenter(center); app.stationaryRadius.setCenter(center);
...@@ -178,6 +191,8 @@ var app = { ...@@ -178,6 +191,8 @@ var app = {
distanceFilter: 50, distanceFilter: 50,
disableElasticity: false, // <-- [iOS] Default is 'false'. Set true to disable speed-based distanceFilter elasticity disableElasticity: false, // <-- [iOS] Default is 'false'. Set true to disable speed-based distanceFilter elasticity
locationUpdateInterval: 5000, locationUpdateInterval: 5000,
minimumActivityRecognitionConfidence: 80, // percentage
fastestLocationUpdateInterval: 5000,
activityRecognitionInterval: 10000, activityRecognitionInterval: 10000,
stopTimeout: 0, stopTimeout: 0,
forceReload: true, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app (WARNING: possibly distruptive to user) forceReload: true, // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app (WARNING: possibly distruptive to user)
...@@ -186,16 +201,15 @@ var app = { ...@@ -186,16 +201,15 @@ var app = {
activityType: 'AutomotiveNavigation' activityType: 'AutomotiveNavigation'
/** /**
* HTTP Feature: set an url to allow the native background service to POST locations to your server * HTTP Feature: set an url to allow the native background service to POST locations to your server
* */
,url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation', ,url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation',
maxDaysToPersist: 1, // <-- Maximum days to persist a location in plugin's SQLite database when HTTP fails
headers: { headers: {
"X-FOO": "bar" "X-FOO": "bar"
}, },
params: { params: {
"auth_token": "maybe_your_server_authenticates_via_token_YES?" "auth_token": "maybe_your_server_authenticates_via_token_YES?"
} }
*
*/
}); });
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app. // Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
...@@ -210,22 +224,20 @@ var app = { ...@@ -210,22 +224,20 @@ var app = {
} }
}, },
onClickHome: function() { onClickHome: function() {
var fgGeo = window.navigator.geolocation; var location = app.currentLocation;
if (!location) {
// Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation, // No location recorded yet; bail out.
// in order to prompt the user for Location permission. return;
fgGeo.getCurrentPosition(function(location) { }
var map = app.map, var map = app.map,
coords = location.coords, coords = location.coords,
ll = new google.maps.LatLng(coords.latitude, coords.longitude), ll = new google.maps.LatLng(coords.latitude, coords.longitude),
zoom = map.getZoom(); zoom = map.getZoom();
map.setCenter(ll); map.setCenter(ll);
if (zoom < 15) { if (zoom < 15) {
map.setZoom(15); map.setZoom(15);
} }
app.setCurrentLocation(coords);
});
}, },
onClickChangePace: function(value) { onClickChangePace: function(value) {
var bgGeo = window.plugins.backgroundGeoLocation, var bgGeo = window.plugins.backgroundGeoLocation,
...@@ -273,26 +285,27 @@ var app = { ...@@ -273,26 +285,27 @@ var app = {
bgGeo.stop(); bgGeo.stop();
} }
}, },
watchPosition: function() { /**
* We use standard cordova-plugin-geolocation to watch position in foreground.
*/
watchForegroundPosition: function() {
var fgGeo = window.navigator.geolocation; var fgGeo = window.navigator.geolocation;
if (app.watchId) { if (app.foregroundWatchId) {
app.stopPositionWatch(); app.stopPositionWatch();
} }
// Watch foreground location // Watch foreground location
app.watchId = fgGeo.watchPosition(function(location) { app.foregroundWatchId = fgGeo.watchPosition(function(location) {
app.setCurrentLocation(location.coords); app.setCurrentLocation(location);
}, function() {}, {
enableHighAccuracy: true,
maximumAge: 5000,
frequency: 10000,
timeout: 10000
}); });
}, },
stopPositionWatch: function() { /**
* Stop watching position in foreground when we pause: THIS IS VERY IMPORTANT
*/
stopWatchingForegroundPosition: function() {
var fgGeo = window.navigator.geolocation; var fgGeo = window.navigator.geolocation;
if (app.watchId) { if (app.foregroundWatchId) {
fgGeo.clearWatch(app.watchId); fgGeo.clearWatch(app.foregroundWatchId);
app.watchId = undefined; app.foregroundWatchId = undefined;
} }
}, },
/** /**
...@@ -301,23 +314,28 @@ var app = { ...@@ -301,23 +314,28 @@ var app = {
* determine start/stop of device. * determine start/stop of device.
*/ */
onPause: function() { onPause: function() {
console.log('- onPause'); console.log('[js] onPause');
app.stopPositionWatch(); app.stopWatchingForegroundPosition();
}, },
/** /**
* Once in foreground, re-engage foreground geolocation watch with standard Cordova GeoLocation api * Once in foreground, re-engage foreground geolocation watch with standard Cordova GeoLocation api
*/ */
onResume: function() { onResume: function() {
console.log('- onResume'); console.log('[js] onResume');
app.watchPosition(); app.watchForegroundPosition();
}, },
// Update DOM on a Received Event // Update DOM on a Received Event
receivedEvent: function(id) { receivedEvent: function(id) {
console.log('Received Event: ' + id); console.log('Received Event: ' + id);
}, },
setCurrentLocation: function(location) { setCurrentLocation: function(location) {
if (!app.location) { // Set currentLocation @property
app.location = new google.maps.Marker({ app.currentLocation = location;
var coords = location.coords;
if (!app.currentLocationMarker) {
app.currentLocationMarker = new google.maps.Marker({
map: app.map, map: app.map,
icon: { icon: {
path: google.maps.SymbolPath.CIRCLE, path: google.maps.SymbolPath.CIRCLE,
...@@ -327,12 +345,13 @@ var app = { ...@@ -327,12 +345,13 @@ var app = {
strokeWeight: 5 strokeWeight: 5
} }
}); });
app.locationAccuracy = new google.maps.Circle({ app.locationAccuracyMarker = new google.maps.Circle({
fillColor: '#3366cc', fillColor: '#3366cc',
fillOpacity: 0.4, fillOpacity: 0.4,
strokeOpacity: 0, strokeOpacity: 0,
map: app.map map: app.map
}); });
app.onClickHome();
} }
if (!app.path) { if (!app.path) {
app.path = new google.maps.Polyline({ app.path = new google.maps.Polyline({
...@@ -341,7 +360,8 @@ var app = { ...@@ -341,7 +360,8 @@ var app = {
fillOpacity: 0.4 fillOpacity: 0.4
}); });
} }
var latlng = new google.maps.LatLng(location.latitude, location.longitude); var latlng = new google.maps.LatLng(coords.latitude, coords.longitude);
if (app.previousLocation) { if (app.previousLocation) {
var prevLocation = app.previousLocation; var prevLocation = app.previousLocation;
...@@ -355,14 +375,14 @@ var app = { ...@@ -355,14 +375,14 @@ var app = {
strokeWeight: 5 strokeWeight: 5
}, },
map: app.map, map: app.map,
position: new google.maps.LatLng(prevLocation.latitude, prevLocation.longitude) position: new google.maps.LatLng(prevLocation.coords.latitude, prevLocation.coords.longitude)
})); }));
} }
// Update our current position marker and accuracy bubble. // Update our current position marker and accuracy bubble.
app.location.setPosition(latlng); app.currentLocationMarker.setPosition(latlng);
app.locationAccuracy.setCenter(latlng); app.locationAccuracyMarker.setCenter(latlng);
app.locationAccuracy.setRadius(location.accuracy); app.locationAccuracyMarker.setRadius(location.coords.accuracy);
// Add breadcrumb to current Polyline path. // Add breadcrumb to current Polyline path.
app.path.getPath().push(latlng); app.path.getPath().push(latlng);
......
...@@ -7,43 +7,30 @@ ...@@ -7,43 +7,30 @@
<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>
<keywords>phonegap,background geolocation</keywords> <keywords>cordova, phonegap, background geolocation</keywords>
<engines> <engines>
<engine name="cordova" version=">=3.0.0" /> <engine name="cordova" version=">=3.0.0" />
</engines> </engines>
<dependency id="org.apache.cordova.geolocation" />
<dependency id="org.apache.cordova.dialogs" /> <dependency id="org.apache.cordova.dialogs" />
<dependency id="com.google.playservices" url="https://github.com/MobileChromeApps/google-play-services.git" />
<js-module src="www/BackgroundGeoLocation.js" name="BackgroundGeoLocation"> <js-module src="www/BackgroundGeoLocation.js" name="BackgroundGeoLocation">
<clobbers target="plugins.backgroundGeoLocation" /> <clobbers target="plugins.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" />
<source-file src="src/android/libs/eventbus-2.4.0.jar" target-dir="libs" /> <source-file src="src/android/libs/eventbus-2.4.0.jar" target-dir="libs" />
<source-file src="src/android/BackgroundGeolocationPlugin.java" target-dir="src/com/transistorsoft/cordova/bggeo" /> <source-file src="src/android/libs/transistor-locationmanager.jar" target-dir="libs" />
<source-file src="src/android/BackgroundGeolocationService.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/ActivityRecognitionService.java" target-dir="src/com/transistorsoft/cordova/bggeo" />
<source-file src="src/android/LocationService.java" target-dir="src/com/transistorsoft/cordova/bggeo" />
<source-file src="src/android/BootReceiver.java" target-dir="src/com/transistorsoft/cordova/bggeo" />
<!-- For SQLite persistence NOT YET IMPLEMENTED
<source-file src="src/android/data/LocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data" />
<source-file src="src/android/data/sqlite/LocationOpenHelper.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" />
<source-file src="src/android/data/sqlite/SQLiteLocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" />
-->
<config-file target="AndroidManifest.xml" parent="/manifest/application"> <config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="com.transistorsoft.cordova.bggeo.BackgroundGeolocationService" /> <service android:name="com.transistorsoft.locationmanager.BackgroundGeolocationService" />
<service android:name="com.transistorsoft.cordova.bggeo.LocationService" /> <service android:name="com.transistorsoft.locationmanager.LocationService" />
<service android:name="com.transistorsoft.cordova.bggeo.ActivityRecognitionService" /> <service android:name="com.transistorsoft.locationmanager.ActivityRecognitionService" />
<receiver android:name="com.transistorsoft.locationmanager.BootReceiver" android:enabled="true" android:exported="false">
<!-- autorun on boot receiver -->
<receiver android:name="com.transistorsoft.cordova.bggeo.BootReceiver" android:enabled="true" android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter> </intent-filter>
...@@ -63,7 +50,7 @@ ...@@ -63,7 +50,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.BackgroundGeolocationPlugin"/> <param name="android-package" value="com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation"/>
</feature> </feature>
</config-file> </config-file>
</platform> </platform>
...@@ -83,13 +70,15 @@ ...@@ -83,13 +70,15 @@
<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>
<framework src="AudioToolbox.framework" weak="true" /> <framework src="AudioToolbox.framework" weak="true" />
<framework src="AVFoundation.framework" weak="true" /> <framework src="AVFoundation.framework" weak="true" />
<source-file src="src/ios/CDVBackgroundGeoLocation.m" /> <framework src="libsqlite3.dylib" weak="true" />
<header-file src="src/ios/CDVBackgroundGeoLocation.h" /> <framework src="src/ios/TSLocationManager.framework" custom="true" />
<source-file src="src/ios/CDVBackgroundGeolocation.m" />
<header-file src="src/ios/CDVBackgroundGeolocation.h" />
</platform> </platform>
<!-- wp8 --> <!-- wp8 -->
......
package com.transistorsoft.cordova.bggeo;
import de.greenrobot.event.EventBus;
import com.google.android.gms.location.DetectedActivity;
import com.google.android.gms.location.ActivityRecognitionResult;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
public class ActivityRecognitionService extends IntentService {
private static final String TAG = "BackgroundGeolocation";
public ActivityRecognitionService() {
super("com.transistorsoft.cordova.bggeo.ActivityRecognitionService");
}
@Override
protected void onHandleIntent(Intent intent) {
// Determine whether the fore-ground Activity is running. If it's not, we'll reboot it.
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity probableActivity = result.getMostProbableActivity();
Log.w(TAG, "Activity detected:" + getActivityName(probableActivity.getType()) + ", confidence:" + probableActivity.getConfidence());
if (probableActivity.getConfidence() < 80) {
return;
}
switch (probableActivity.getType()) {
case DetectedActivity.IN_VEHICLE:
case DetectedActivity.ON_BICYCLE:
case DetectedActivity.ON_FOOT:
case DetectedActivity.WALKING:
case DetectedActivity.RUNNING:
case DetectedActivity.STILL:
EventBus.getDefault().post(result);
break;
case DetectedActivity.UNKNOWN:
return;
case DetectedActivity.TILTING:
return;
}
}
}
/**
* This method has no other purpose than formatting the Activity for log-messages
*/
private String getActivityName(int activityType) {
switch (activityType) {
case DetectedActivity.IN_VEHICLE:
return "in_vehicle";
case DetectedActivity.ON_BICYCLE:
return "on_bicycle";
case DetectedActivity.ON_FOOT:
return "on_foot";
case DetectedActivity.RUNNING:
return "running";
case DetectedActivity.WALKING:
return "walking";
case DetectedActivity.STILL:
return "still";
case DetectedActivity.UNKNOWN:
return "unknown";
case DetectedActivity.TILTING:
return "tilting";
}
return "unknown";
}
}
\ No newline at end of file
This diff is collapsed.
package com.transistorsoft.cordova.bggeo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
/**
* This boot receiver is meant to handle the case where device is first booted after power up.
* This boot the headless BackgroundGeolocationService as configured by this class.
* @author chris scott
*
*/
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "BackgroundGeolocation";
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences settings = context.getSharedPreferences(TAG, 0);
boolean startOnBoot = settings.getBoolean("startOnBoot", false);
boolean enabled = settings.getBoolean("enabled", false);
if (!startOnBoot || !enabled) {
return;
}
Log.i(TAG, "- BootReceiver booting service");
// Start the service.
context.startService(new Intent(context, BackgroundGeolocationService.class));
}
}
...@@ -8,9 +8,10 @@ import org.json.JSONArray; ...@@ -8,9 +8,10 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONException; import org.json.JSONException;
import com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.PaceChangeEvent; import com.transistorsoft.locationmanager.BackgroundGeolocationService;
import com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.PausedEvent; import com.transistorsoft.locationmanager.BackgroundGeolocationService.PaceChangeEvent;
import com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.StationaryLocation; import com.transistorsoft.locationmanager.BackgroundGeolocationService.PausedEvent;
//import com.transistorsoft.locationmanager.BackgroundGeolocationService.StationaryLocation;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import android.app.Activity; import android.app.Activity;
...@@ -19,7 +20,7 @@ import android.content.SharedPreferences; ...@@ -19,7 +20,7 @@ import android.content.SharedPreferences;
import android.location.Location; import android.location.Location;
import android.util.Log; import android.util.Log;
public class BackgroundGeolocationPlugin extends CordovaPlugin { public class CDVBackgroundGeolocation extends CordovaPlugin {
private static final String TAG = "BackgroundGeolocation"; private static final String TAG = "BackgroundGeolocation";
private static CordovaWebView gWebView; private static CordovaWebView gWebView;
public static Boolean forceReload = false; public static Boolean forceReload = false;
...@@ -109,7 +110,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -109,7 +110,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
Activity activity = this.cordova.getActivity(); Activity activity = this.cordova.getActivity();
SharedPreferences settings = activity.getSharedPreferences(TAG, 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);
editor.commit(); editor.commit();
...@@ -130,9 +131,10 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -130,9 +131,10 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
JSONObject config = data.getJSONObject(0); JSONObject config = data.getJSONObject(0);
Log.i(TAG, "- configure: " + config.toString()); Log.i(TAG, "- configure: " + config.toString());
SharedPreferences settings = activity.getSharedPreferences(TAG, 0); SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("activityIsActive", true);
editor.putBoolean("isMoving", isMoving); editor.putBoolean("isMoving", isMoving);
if (config.has("distanceFilter")) { if (config.has("distanceFilter")) {
...@@ -145,7 +147,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -145,7 +147,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
editor.putInt("locationUpdateInterval", config.getInt("locationUpdateInterval")); editor.putInt("locationUpdateInterval", config.getInt("locationUpdateInterval"));
} }
if (config.has("activityRecognitionInterval")) { if (config.has("activityRecognitionInterval")) {
editor.putInt("activityRecognitionInterval", config.getInt("activityRecognitionInterval")); editor.putLong("activityRecognitionInterval", config.getLong("activityRecognitionInterval"));
} }
if (config.has("stopTimeout")) { if (config.has("stopTimeout")) {
editor.putLong("stopTimeout", config.getLong("stopTimeout")); editor.putLong("stopTimeout", config.getLong("stopTimeout"));
...@@ -153,6 +155,9 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -153,6 +155,9 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
if (config.has("debug")) { if (config.has("debug")) {
editor.putBoolean("debug", config.getBoolean("debug")); editor.putBoolean("debug", config.getBoolean("debug"));
} }
if (config.has("stopAfterElapsedMinutes")) {
editor.putInt("stopAfterElapsedMinutes", config.getInt("stopAfterElapsedMinutes"));
}
if (config.has("stopOnTerminate")) { if (config.has("stopOnTerminate")) {
editor.putBoolean("stopOnTerminate", config.getBoolean("stopOnTerminate")); editor.putBoolean("stopOnTerminate", config.getBoolean("stopOnTerminate"));
} }
...@@ -190,13 +195,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -190,13 +195,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
public void onPause(boolean multitasking) { public void onPause(boolean multitasking) {
Log.i(TAG, "- onPause"); Log.i(TAG, "- onPause");
if (isEnabled) { if (isEnabled) {
EventBus.getDefault().post(new PausedEvent(true));
} }
} }
public void onResume(boolean multitasking) { public void onResume(boolean multitasking) {
Log.i(TAG, "- onResume"); Log.i(TAG, "- onResume");
if (isEnabled) { if (isEnabled) {
EventBus.getDefault().post(new PausedEvent(false));
} }
} }
...@@ -207,8 +212,8 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -207,8 +212,8 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
public void onEventMainThread(Location location) { public void onEventMainThread(Location location) {
PluginResult result = new PluginResult(PluginResult.Status.OK, BackgroundGeolocationService.locationToJson(location)); PluginResult result = new PluginResult(PluginResult.Status.OK, BackgroundGeolocationService.locationToJson(location));
result.setKeepCallback(true); result.setKeepCallback(true);
if (location instanceof StationaryLocation) { if (location instanceof com.transistorsoft.locationmanager.BackgroundGeolocationService.StationaryLocation) {
isMoving = false; isMoving = false;
if (stationaryCallback != null) { if (stationaryCallback != null) {
runInBackground(stationaryCallback, result); runInBackground(stationaryCallback, result);
...@@ -234,7 +239,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -234,7 +239,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
}); });
} }
} }
/** /**
* Override method in CordovaPlugin. * Override method in CordovaPlugin.
* Checks to see if it should turn off * Checks to see if it should turn off
...@@ -244,6 +249,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin { ...@@ -244,6 +249,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
Log.i(TAG, " stopOnTerminate: " + stopOnTerminate); Log.i(TAG, " stopOnTerminate: " + stopOnTerminate);
Log.i(TAG, " isEnabled: " + isEnabled); Log.i(TAG, " isEnabled: " + isEnabled);
Activity activity = this.cordova.getActivity();
SharedPreferences settings = activity.getSharedPreferences("TSLocationManager", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("activityIsActive", false);
editor.commit();
if(isEnabled && stopOnTerminate) { if(isEnabled && stopOnTerminate) {
this.cordova.getActivity().stopService(backgroundServiceIntent); this.cordova.getActivity().stopService(backgroundServiceIntent);
} }
......
package com.transistorsoft.cordova.bggeo;
import de.greenrobot.event.EventBus;
import com.google.android.gms.location.FusedLocationProviderApi;
import android.app.IntentService;
import android.content.Intent;
import android.location.Location;
import android.util.Log;
public class LocationService extends IntentService {
private static final String TAG = "BackgroundGeolocation";
public LocationService() {
super("com.transistorsoft.cordova.bggeo.LocationUpdateService");
}
@Override
protected void onHandleIntent(Intent intent) {
final Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if (location != null) {
Log.i(TAG, "Location received: " + location.toString());
EventBus.getDefault().post(location);
}
}
}
\ No newline at end of file
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
// //
#import <Cordova/CDVPlugin.h> #import <Cordova/CDVPlugin.h>
#import "CDVLocation.h" #import <TSLocationManager/TSLocationManager.h>
#import <AudioToolbox/AudioToolbox.h>
@interface CDVBackgroundGeoLocation : CDVPlugin <CLLocationManagerDelegate> @interface CDVBackgroundGeolocation : CDVPlugin
@property (nonatomic, strong) NSString* syncCallbackId; @property (nonatomic, strong) NSString* syncCallbackId;
@property (nonatomic, strong) NSMutableArray* stationaryRegionListeners; @property (nonatomic, strong) NSMutableArray* stationaryRegionListeners;
...@@ -21,9 +20,6 @@ ...@@ -21,9 +20,6 @@
- (void) setConfig:(CDVInvokedUrlCommand*)command; - (void) setConfig:(CDVInvokedUrlCommand*)command;
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command; - (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command;
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command; - (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
- (void) onAppTerminate;
@end @end
This diff is collapsed.
Versions/Current/Headers
\ No newline at end of file
Versions/Current/Resources
\ No newline at end of file
Versions/Current/TSLocationManager
\ No newline at end of file
#import <CoreLocation/CoreLocation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <sqlite3.h>
@interface TSLocationManager : NSObject <CLLocationManagerDelegate>
@property (strong, nonatomic) NSString *databasePath;
@property (nonatomic) sqlite3 *db;
- (void) configure:(NSDictionary*)config;
- (void) start;
- (void) stop;
- (void) finish;
- (void) stopBackgroundTask;
- (void) onPaceChange:(BOOL)value;
- (void) setConfig:(NSDictionary*)command;
- (NSDictionary*) getStationaryLocation;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
- (void) onAppTerminate;
- (BOOL) isEnabled;
- (NSMutableDictionary*) locationToDictionary:(CLLocation*)location;
@end
framework module TSLocationManager {
umbrella header "TSLocationManager.h"
export *
module * { export * }
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
IDPizw9H7yMm0B/vqQy2MaU2iCs=
</data>
<key>Info.plist</key>
<data>
xolLvzV3rJusVEx/xOJXBAgSQRw=
</data>
<key>Modules/module.modulemap</key>
<data>
ZlH8rkma2jB7yWJU5dFqHfgbHZc=
</data>
</dict>
<key>files2</key>
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
IDPizw9H7yMm0B/vqQy2MaU2iCs=
</data>
<key>Modules/module.modulemap</key>
<data>
ZlH8rkma2jB7yWJU5dFqHfgbHZc=
</data>
</dict>
<key>rules</key>
<dict>
<key>^</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
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