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
9593a6c4
Commit
9593a6c4
authored
Apr 04, 2015
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-organize methods
parent
4b1df825
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
97 deletions
+115
-97
index.js
example/SampleApp/www/js/index.js
+3
-0
BackgroundGeolocationPlugin.java
src/android/BackgroundGeolocationPlugin.java
+22
-26
BackgroundGeolocationService.java
src/android/BackgroundGeolocationService.java
+90
-71
No files found.
example/SampleApp/www/js/index.js
View file @
9593a6c4
...
...
@@ -182,6 +182,9 @@ var app = {
headers
:
{
"
X-FOO
"
:
"
bar
"
},
params
:
{
"
auth_token
"
:
"
bar
"
},
forceReload
:
false
,
activityType
:
'
AutomotiveNavigation
'
,
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
...
...
src/android/BackgroundGeolocationPlugin.java
View file @
9593a6c4
...
...
@@ -41,6 +41,9 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
private
Location
stationaryLocation
;
public
static
boolean
isActive
()
{
return
gWebView
!=
null
;
}
@Override
protected
void
pluginInitialize
()
{
...
...
@@ -52,19 +55,20 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
public
boolean
execute
(
String
action
,
JSONArray
data
,
CallbackContext
callbackContext
)
throws
JSONException
{
Log
.
d
(
TAG
,
"execute / action : "
+
action
);
Boolean
result
=
false
;
Activity
activity
=
this
.
cordova
.
getActivity
();
Boolean
result
=
false
;
if
(
ACTION_START
.
equalsIgnoreCase
(
action
)
&&
!
isEnabled
)
{
result
=
true
;
isEnabled
=
true
;
if
(!
BackgroundGeolocationService
.
isInstanceCreated
())
{
this
.
cordova
.
getActivity
()
.
startService
(
backgroundServiceIntent
);
activity
.
startService
(
backgroundServiceIntent
);
}
}
else
if
(
ACTION_STOP
.
equalsIgnoreCase
(
action
))
{
result
=
true
;
isEnabled
=
false
;
this
.
cordova
.
getActivity
()
.
stopService
(
backgroundServiceIntent
);
activity
.
stopService
(
backgroundServiceIntent
);
callbackContext
.
success
();
}
else
if
(
ACTION_CONFIGURE
.
equalsIgnoreCase
(
action
))
{
result
=
applyConfig
(
data
);
...
...
@@ -83,11 +87,11 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
callbackContext
.
success
();
}
}
else
if
(
ACTION_SET_CONFIG
.
equalsIgnoreCase
(
action
))
{
this
.
cordova
.
getActivity
()
.
stopService
(
backgroundServiceIntent
);
activity
.
stopService
(
backgroundServiceIntent
);
result
=
applyConfig
(
data
);
// TODO reconfigure Service
if
(
result
)
{
this
.
cordova
.
getActivity
()
.
stopService
(
backgroundServiceIntent
);
activity
.
stopService
(
backgroundServiceIntent
);
callbackContext
.
success
();
}
else
{
callbackContext
.
error
(
"- Configuration error!"
);
...
...
@@ -96,9 +100,9 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
result
=
true
;
this
.
stationaryCallback
=
callbackContext
;
}
return
result
;
}
private
boolean
applyConfig
(
JSONArray
data
)
{
// This is the IntentService we'll provide to google-play API.
Activity
activity
=
this
.
cordova
.
getActivity
();
...
...
@@ -149,10 +153,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
}
}
public
static
boolean
isActive
()
{
return
gWebView
!=
null
;
}
public
void
onPause
(
boolean
multitasking
)
{
Log
.
i
(
TAG
,
"- onPause"
);
if
(
isEnabled
)
{
...
...
@@ -165,30 +165,26 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
//removeLocationUpdates();
}
}
/**
* EventBus listener
* @param {Location} location
*/
public
void
onEventMainThread
(
Location
location
)
{
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
BackgroundGeolocationService
.
locationToJson
(
location
));
result
.
setKeepCallback
(
true
);
if
(
location
instanceof
StationaryLocation
)
{
stationaryLocation
=
location
;
fireStationaryListener
();
if
(
stationaryCallback
!=
null
)
{
runInBackground
(
stationaryCallback
,
result
);
}
}
else
{
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
BackgroundGeolocationService
.
locationToJson
(
location
));
result
.
setKeepCallback
(
true
);
runInBackground
(
locationCallback
,
result
);
}
}
/**
* Execute onStationary javascript callback when device is determined to have just stopped
*/
private
void
fireStationaryListener
()
{
Log
.
i
(
TAG
,
"- fire stationary listener"
);
if
(
(
stationaryCallback
!=
null
)
&&
(
stationaryLocation
!=
null
)
)
{
final
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
BackgroundGeolocationService
.
locationToJson
(
stationaryLocation
));
result
.
setKeepCallback
(
true
);
runInBackground
(
stationaryCallback
,
result
);
}
}
/**
* Run a javascript callback in Background
* @param cb
...
...
src/android/BackgroundGeolocationService.java
View file @
9593a6c4
This diff is collapsed.
Click to expand it.
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