Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-background-geolocation
Commits
cb5d84e0
Commit
cb5d84e0
authored
Jun 16, 2015
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs with forceReload
parent
22680f76
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
44 deletions
+77
-44
CDVBackgroundGeolocation.java
src/android/CDVBackgroundGeolocation.java
+77
-44
transistor-locationmanager.jar
src/android/libs/transistor-locationmanager.jar
+0
-0
No files found.
src/android/CDVBackgroundGeolocation.java
View file @
cb5d84e0
...
@@ -28,7 +28,7 @@ import android.media.AudioManager;
...
@@ -28,7 +28,7 @@ import android.media.AudioManager;
import
android.media.ToneGenerator
;
import
android.media.ToneGenerator
;
public
class
CDVBackgroundGeolocation
extends
CordovaPlugin
{
public
class
CDVBackgroundGeolocation
extends
CordovaPlugin
{
private
static
final
String
TAG
=
"
BackgroundGeolocation
"
;
private
static
final
String
TAG
=
"
TSLocationManager
"
;
private
static
CordovaWebView
gWebView
;
private
static
CordovaWebView
gWebView
;
public
static
Boolean
forceReload
=
false
;
public
static
Boolean
forceReload
=
false
;
...
@@ -51,6 +51,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -51,6 +51,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
public
static
final
String
ACTION_GET_GEOFENCES
=
"getGeofences"
;
public
static
final
String
ACTION_GET_GEOFENCES
=
"getGeofences"
;
public
static
final
String
ACTION_ON_GEOFENCE
=
"onGeofence"
;
public
static
final
String
ACTION_ON_GEOFENCE
=
"onGeofence"
;
public
static
final
String
ACTION_PLAY_SOUND
=
"playSound"
;
public
static
final
String
ACTION_PLAY_SOUND
=
"playSound"
;
public
static
final
String
ACTION_ACTIVITY_RELOAD
=
"activityReload"
;
private
Boolean
isEnabled
=
false
;
private
Boolean
isEnabled
=
false
;
private
Boolean
stopOnTerminate
=
false
;
private
Boolean
stopOnTerminate
=
false
;
...
@@ -147,7 +148,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -147,7 +148,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
this
.
stationaryCallback
=
callbackContext
;
this
.
stationaryCallback
=
callbackContext
;
}
else
if
(
ACTION_ADD_MOTION_CHANGE_LISTENER
.
equalsIgnoreCase
(
action
))
{
}
else
if
(
ACTION_ADD_MOTION_CHANGE_LISTENER
.
equalsIgnoreCase
(
action
))
{
result
=
true
;
result
=
true
;
motionChangeCallbacks
.
add
(
callbackContext
);
this
.
addMotionChangeListener
(
callbackContext
);
}
else
if
(
ACTION_GET_LOCATIONS
.
equalsIgnoreCase
(
action
))
{
}
else
if
(
ACTION_GET_LOCATIONS
.
equalsIgnoreCase
(
action
))
{
result
=
true
;
result
=
true
;
Bundle
event
=
new
Bundle
();
Bundle
event
=
new
Bundle
();
...
@@ -192,7 +193,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -192,7 +193,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
}
}
}
else
if
(
ACTION_ON_GEOFENCE
.
equalsIgnoreCase
(
action
))
{
}
else
if
(
ACTION_ON_GEOFENCE
.
equalsIgnoreCase
(
action
))
{
result
=
true
;
result
=
true
;
geofenceCallbacks
.
add
(
callbackContext
);
addGeofenceListener
(
callbackContext
);
}
else
if
(
ACTION_GET_GEOFENCES
.
equalsIgnoreCase
(
action
))
{
}
else
if
(
ACTION_GET_GEOFENCES
.
equalsIgnoreCase
(
action
))
{
result
=
true
;
result
=
true
;
getGeofencesCallback
=
callbackContext
;
getGeofencesCallback
=
callbackContext
;
...
@@ -231,6 +232,33 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -231,6 +232,33 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
}
}
}
}
private
void
addGeofenceListener
(
CallbackContext
callbackContext
)
{
geofenceCallbacks
.
add
(
callbackContext
);
Activity
activity
=
this
.
cordova
.
getActivity
();
Intent
launchIntent
=
activity
.
getIntent
();
if
(
launchIntent
.
hasExtra
(
"forceReload"
)
&&
launchIntent
.
hasExtra
(
"geofencingEvent"
))
{
try
{
JSONObject
geofencingEvent
=
new
JSONObject
(
launchIntent
.
getStringExtra
(
"geofencingEvent"
));
handleGeofencingEvent
(
geofencingEvent
);
}
catch
(
JSONException
e
)
{
Log
.
w
(
TAG
,
e
);
}
}
}
private
void
addMotionChangeListener
(
CallbackContext
callbackContext
)
{
motionChangeCallbacks
.
add
(
callbackContext
);
Activity
activity
=
this
.
cordova
.
getActivity
();
Intent
launchIntent
=
activity
.
getIntent
();
if
(
launchIntent
.
hasExtra
(
"forceReload"
))
{
if
(
launchIntent
.
getStringExtra
(
"name"
).
equalsIgnoreCase
(
ACTION_ON_MOTION_CHANGE
))
{
Bundle
event
=
launchIntent
.
getExtras
();
this
.
onEventMainThread
(
event
);
}
}
}
private
Boolean
onRemoveGeofence
(
String
identifier
)
{
private
Boolean
onRemoveGeofence
(
String
identifier
)
{
Bundle
event
=
new
Bundle
();
Bundle
event
=
new
Bundle
();
event
.
putString
(
"name"
,
ACTION_REMOVE_GEOFENCE
);
event
.
putString
(
"name"
,
ACTION_REMOVE_GEOFENCE
);
...
@@ -243,8 +271,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -243,8 +271,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
private
void
setEnabled
(
boolean
value
)
{
private
void
setEnabled
(
boolean
value
)
{
isEnabled
=
value
;
isEnabled
=
value
;
Activity
activity
=
this
.
cordova
.
getActivity
();
Intent
launchIntent
=
this
.
cordova
.
getActivity
().
getIntent
();
if
(
launchIntent
.
hasExtra
(
"forceReload"
)
&&
launchIntent
.
hasExtra
(
"location"
))
{
try
{
JSONObject
location
=
new
JSONObject
(
launchIntent
.
getStringExtra
(
"location"
));
onLocationChange
(
location
);
}
catch
(
JSONException
e
)
{
Log
.
w
(
TAG
,
e
);
}
}
Activity
activity
=
this
.
cordova
.
getActivity
();
SharedPreferences
settings
=
activity
.
getSharedPreferences
(
"TSLocationManager"
,
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
);
...
@@ -310,9 +348,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -310,9 +348,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if
(
config
.
has
(
"startOnBoot"
))
{
if
(
config
.
has
(
"startOnBoot"
))
{
editor
.
putBoolean
(
"startOnBoot"
,
config
.
getBoolean
(
"startOnBoot"
));
editor
.
putBoolean
(
"startOnBoot"
,
config
.
getBoolean
(
"startOnBoot"
));
}
}
if
(
config
.
has
(
"forceReload"
))
{
editor
.
putBoolean
(
"forceReload"
,
config
.
getBoolean
(
"forceReload"
));
}
if
(
config
.
has
(
"forceReloadOnLocationChange"
))
{
if
(
config
.
has
(
"forceReloadOnLocationChange"
))
{
editor
.
putBoolean
(
"forceReloadOnLocationChange"
,
config
.
getBoolean
(
"forceReloadOnLocationChange"
));
editor
.
putBoolean
(
"forceReloadOnLocationChange"
,
config
.
getBoolean
(
"forceReloadOnLocationChange"
));
}
}
...
@@ -322,6 +357,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -322,6 +357,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if
(
config
.
has
(
"forceReloadOnMotionChange"
))
{
if
(
config
.
has
(
"forceReloadOnMotionChange"
))
{
editor
.
putBoolean
(
"forceReloadOnMotionChange"
,
config
.
getBoolean
(
"forceReloadOnMotionChange"
));
editor
.
putBoolean
(
"forceReloadOnMotionChange"
,
config
.
getBoolean
(
"forceReloadOnMotionChange"
));
}
}
if
(
config
.
has
(
"forceReloadOnGeofence"
))
{
editor
.
putBoolean
(
"forceReloadOnGeofence"
,
config
.
getBoolean
(
"forceReloadOnGeofence"
));
}
if
(
config
.
has
(
"url"
))
{
if
(
config
.
has
(
"url"
))
{
editor
.
putString
(
"url"
,
config
.
getString
(
"url"
));
editor
.
putString
(
"url"
,
config
.
getString
(
"url"
));
}
}
...
@@ -427,6 +465,11 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -427,6 +465,11 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
runInBackground
(
getGeofencesCallback
,
result
);
runInBackground
(
getGeofencesCallback
,
result
);
}
}
}
else
if
(
ACTION_ON_MOTION_CHANGE
.
equalsIgnoreCase
(
name
))
{
}
else
if
(
ACTION_ON_MOTION_CHANGE
.
equalsIgnoreCase
(
name
))
{
this
.
onMotionChange
(
event
);
}
}
private
void
onMotionChange
(
Bundle
event
)
{
PluginResult
result
;
PluginResult
result
;
try
{
try
{
JSONObject
params
=
new
JSONObject
();
JSONObject
params
=
new
JSONObject
();
...
@@ -443,8 +486,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -443,8 +486,6 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
runInBackground
(
callback
,
result
);
runInBackground
(
callback
,
result
);
}
}
}
}
}
/**
/**
* EventBus listener for ARS
* EventBus listener for ARS
* @param {ActivityRecognitionResult} result
* @param {ActivityRecognitionResult} result
...
@@ -459,14 +500,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -459,14 +500,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
* @param {Location} location
* @param {Location} location
*/
*/
public
void
onEventMainThread
(
Location
location
)
{
public
void
onEventMainThread
(
Location
location
)
{
this
.
onLocationChange
(
BackgroundGeolocationService
.
locationToJson
(
location
,
currentActivity
));
}
private
void
onLocationChange
(
JSONObject
location
)
{
PluginResult
result
;
PluginResult
result
;
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
BackgroundGeolocationService
.
locationToJson
(
location
,
currentActivity
)
);
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
location
);
result
.
setKeepCallback
(
true
);
result
.
setKeepCallback
(
true
);
isMoving
=
true
;
isMoving
=
true
;
result
.
setKeepCallback
(
true
);
result
.
setKeepCallback
(
true
);
runInBackground
(
locationCallback
,
result
);
runInBackground
(
locationCallback
,
result
);
}
}
/**
/**
* EventBus handler for Geofencing events
* EventBus handler for Geofencing events
*/
*/
...
@@ -475,30 +520,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
...
@@ -475,30 +520,18 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
if
(!
geofenceCallbacks
.
isEmpty
())
{
if
(!
geofenceCallbacks
.
isEmpty
())
{
for
(
Geofence
geofence
:
geofenceEvent
.
getTriggeringGeofences
())
{
for
(
Geofence
geofence
:
geofenceEvent
.
getTriggeringGeofences
())
{
JSONObject
params
=
new
JSONObject
();
JSONObject
params
=
BackgroundGeolocationService
.
geofencingEventToJson
(
geofenceEvent
,
geofence
);
String
action
=
""
;
handleGeofencingEvent
(
params
);
int
transitionType
=
geofenceEvent
.
getGeofenceTransition
();
}
if
(
transitionType
==
Geofence
.
GEOFENCE_TRANSITION_ENTER
)
{
action
=
"ENTER"
;
}
else
if
(
transitionType
==
Geofence
.
GEOFENCE_TRANSITION_EXIT
)
{
action
=
"EXIT"
;
}
else
{
action
=
"DWELL"
;
}
}
try
{
params
.
put
(
"identifier"
,
geofence
.
getRequestId
());
params
.
put
(
"action"
,
action
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
private
void
handleGeofencingEvent
(
JSONObject
params
)
{
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
params
);
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
params
);
result
.
setKeepCallback
(
true
);
result
.
setKeepCallback
(
true
);
for
(
CallbackContext
callback
:
geofenceCallbacks
)
{
for
(
CallbackContext
callback
:
geofenceCallbacks
)
{
runInBackground
(
callback
,
result
);
runInBackground
(
callback
,
result
);
}
}
}
}
}
}
private
void
playSound
(
int
soundId
)
{
private
void
playSound
(
int
soundId
)
{
int
duration
=
1000
;
int
duration
=
1000
;
...
...
src/android/libs/transistor-locationmanager.jar
View file @
cb5d84e0
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment