Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-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-plugin-background-geolocation
Commits
1f7459c5
Commit
1f7459c5
authored
Oct 15, 2013
by
Chris Scott
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from christocracy/android
Android
parents
3f569226
2038b1c0
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
580 additions
and
4 deletions
+580
-4
.gitignore
.gitignore
+1
-0
plugin.xml
plugin.xml
+23
-4
BackgroundGpsPlugin.java
src/android/BackgroundGpsPlugin.java
+47
-0
CDVBackgroundGeoLocation.java
src/android/CDVBackgroundGeoLocation.java
+0
-0
LocationUpdateService.java
src/android/LocationUpdateService.java
+291
-0
android-support-v4.jar
src/android/android-support-v4.jar
+0
-0
DAOFactory.java
src/android/data/DAOFactory.java
+12
-0
Location.java
src/android/data/Location.java
+48
-0
LocationDAO.java
src/android/data/LocationDAO.java
+7
-0
LocationOpenHelper.java
src/android/data/sqlite/LocationOpenHelper.java
+38
-0
SQLiteLocationDAO.java
src/android/data/sqlite/SQLiteLocationDAO.java
+113
-0
notification.png
src/android/notification.png
+0
-0
No files found.
.gitignore
0 → 100644
View file @
1f7459c5
.DS_Store
plugin.xml
View file @
1f7459c5
...
...
@@ -18,13 +18,32 @@
<!-- android -->
<platform
name=
"android"
>
<source-file
src=
"src/android/BackgroundGpsPlugin.java"
target-dir=
"src/com/tenforwardconsulting/cordova/bgloc"
/>
<source-file
src=
"src/android/LocationUpdateService.java"
target-dir=
"src/com/tenforwardconsulting/cordova/bgloc"
/>
<source-file
src=
"src/android/data/DAOFactory.java"
target-dir=
"src/com/tenforwardconsulting/cordova/bgloc/data"
/>
<source-file
src=
"src/android/data/Location.java"
target-dir=
"src/com/tenforwardconsulting/cordova/bgloc/data"
/>
<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"
/>
<source-file
src=
"src/android/notification.png"
target-dir=
"res/drawable"
/>
<source-file
src=
"src/android/android-support-v4.jar"
target-dir=
"libs"
/>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<service
android:enabled=
"true"
android:name=
"com.tenforwardconsulting.cordova.bgloc.LocationUpdateService"
android:process=
":remote"
/>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
</config-file>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<feature
name=
"BackgroundGeoLocation"
>
<param
name=
"android-package"
value=
"
CDVBackgroundGeolocatio
n"
/>
<param
name=
"android-package"
value=
"
com.tenforwardconsulting.cordova.bgloc.BackgroundGpsPlugi
n"
/>
</feature>
</config-file>
<source-file
src=
"src/android/CDVBackgroundGeoLocation.java"
target-dir=
"src/org/transistorsoft/background-geolocation"
/>
</config-file>
</platform>
<platform
name=
"ios"
>
...
...
src/android/BackgroundGpsPlugin.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
;
import
org.apache.cordova.CallbackContext
;
import
org.apache.cordova.CordovaPlugin
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
android.app.Activity
;
import
android.content.Intent
;
public
class
BackgroundGpsPlugin
extends
CordovaPlugin
{
public
static
final
String
ACTION_START
=
"start"
;
public
static
final
String
ACTION_STOP
=
"stop"
;
public
static
final
String
ACTION_CONFIGURE
=
"configure"
;
private
String
authToken
;
private
String
url
;
@Override
public
boolean
execute
(
String
action
,
JSONArray
data
,
CallbackContext
callbackContext
)
{
Activity
activity
=
this
.
cordova
.
getActivity
();
Intent
updateServiceIntent
=
new
Intent
(
activity
,
LocationUpdateService
.
class
);
if
(
ACTION_START
.
equalsIgnoreCase
(
action
))
{
if
(
authToken
==
null
||
url
==
null
)
{
callbackContext
.
error
(
"Call configure before calling start"
);
return
false
;
}
updateServiceIntent
.
putExtra
(
"authToken"
,
authToken
);
updateServiceIntent
.
putExtra
(
"url"
,
url
);
activity
.
startService
(
updateServiceIntent
);
}
else
if
(
ACTION_STOP
.
equalsIgnoreCase
(
action
))
{
activity
.
stopService
(
updateServiceIntent
);
}
else
if
(
ACTION_CONFIGURE
.
equalsIgnoreCase
(
action
))
{
try
{
this
.
authToken
=
data
.
getString
(
0
);
this
.
url
=
data
.
getString
(
1
);
}
catch
(
JSONException
e
)
{
callbackContext
.
error
(
"authToken/url required as parameters: "
+
e
.
getMessage
());
return
false
;
}
}
return
true
;
}
}
src/android/CDVBackgroundGeoLocation.java
deleted
100644 → 0
View file @
3f569226
src/android/LocationUpdateService.java
0 → 100644
View file @
1f7459c5
This diff is collapsed.
Click to expand it.
src/android/android-support-v4.jar
0 → 100644
View file @
1f7459c5
File added
src/android/data/DAOFactory.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
;
import
android.content.Context
;
import
com.tenforwardconsulting.cordova.bgloc.data.sqlite.SQLiteLocationDAO
;
public
abstract
class
DAOFactory
{
public
static
LocationDAO
createLocationDAO
(
Context
context
)
{
//Very basic for now
return
new
SQLiteLocationDAO
(
context
);
}
}
src/android/data/Location.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
;
import
java.util.Date
;
import
android.os.SystemClock
;
public
class
Location
{
private
String
latitude
;
private
String
longitude
;
private
Date
recordedAt
;
private
Long
id
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getLatitude
()
{
return
latitude
;
}
public
void
setLatitude
(
String
latitude
)
{
this
.
latitude
=
latitude
;
}
public
String
getLongitude
()
{
return
longitude
;
}
public
void
setLongitude
(
String
longitude
)
{
this
.
longitude
=
longitude
;
}
public
Date
getRecordedAt
()
{
return
recordedAt
;
}
public
void
setRecordedAt
(
Date
recordedAt
)
{
this
.
recordedAt
=
recordedAt
;
}
public
static
Location
fromAndroidLocation
(
android
.
location
.
Location
originalLocation
)
{
Location
location
=
new
Location
();
location
.
setRecordedAt
(
new
Date
(
originalLocation
.
getTime
()));
location
.
setLongitude
(
String
.
valueOf
(
originalLocation
.
getLongitude
()));
location
.
setLatitude
(
String
.
valueOf
(
originalLocation
.
getLatitude
()));
return
location
;
}
}
src/android/data/LocationDAO.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
;
public
interface
LocationDAO
{
public
Location
[]
getAllLocations
();
public
boolean
persistLocation
(
Location
l
);
public
void
deleteLocation
(
Location
l
);
}
src/android/data/sqlite/LocationOpenHelper.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
sqlite
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
android.util.Log
;
public
class
LocationOpenHelper
extends
SQLiteOpenHelper
{
private
static
final
String
SQLITE_DATABASE_NAME
=
"cordova_bg_locations"
;
private
static
final
int
DATABASE_VERSION
=
1
;
public
static
final
String
LOCATION_TABLE_NAME
=
"location"
;
private
static
final
String
LOCATION_TABLE_COLUMNS
=
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
+
" recordedAt TEXT,"
+
" latitude TEXT,"
+
" longitude TEXT"
;
private
static
final
String
LOCATION_TABLE_CREATE
=
"CREATE TABLE "
+
LOCATION_TABLE_NAME
+
" ("
+
LOCATION_TABLE_COLUMNS
+
");"
;
LocationOpenHelper
(
Context
context
)
{
super
(
context
,
SQLITE_DATABASE_NAME
,
null
,
DATABASE_VERSION
);
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
LOCATION_TABLE_CREATE
);
Log
.
d
(
this
.
getClass
().
getName
(),
LOCATION_TABLE_CREATE
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
// TODO Auto-generated method stub
}
}
\ No newline at end of file
src/android/data/sqlite/SQLiteLocationDAO.java
0 → 100644
View file @
1f7459c5
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
sqlite
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.util.Log
;
import
com.tenforwardconsulting.cordova.bgloc.data.Location
;
import
com.tenforwardconsulting.cordova.bgloc.data.LocationDAO
;
public
class
SQLiteLocationDAO
implements
LocationDAO
{
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
final
String
TAG
=
"SQLiteLocationDAO"
;
private
Context
context
;
public
SQLiteLocationDAO
(
Context
context
)
{
this
.
context
=
context
;
}
public
Location
[]
getAllLocations
()
{
SQLiteDatabase
db
=
null
;
Cursor
c
=
null
;
List
<
Location
>
all
=
new
ArrayList
<
Location
>();
try
{
db
=
new
LocationOpenHelper
(
context
).
getReadableDatabase
();
c
=
db
.
query
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
null
);
while
(
c
.
moveToNext
())
{
all
.
add
(
hydrate
(
c
));
}
}
finally
{
if
(
c
!=
null
)
{
c
.
close
();
}
if
(
db
!=
null
)
{
db
.
close
();
}
}
return
all
.
toArray
(
new
Location
[
all
.
size
()]);
}
public
boolean
persistLocation
(
Location
location
)
{
SQLiteDatabase
db
=
new
LocationOpenHelper
(
context
).
getWritableDatabase
();
db
.
beginTransaction
();
ContentValues
values
=
getContentValues
(
location
);
long
rowId
=
db
.
insert
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
values
);
Log
.
d
(
TAG
,
"After insert, rowId = "
+
rowId
);
db
.
setTransactionSuccessful
();
db
.
endTransaction
();
db
.
close
();
if
(
rowId
>
-
1
)
{
location
.
setId
(
rowId
);
return
true
;
}
else
{
return
false
;
}
}
public
void
deleteLocation
(
Location
location
)
{
SQLiteDatabase
db
=
new
LocationOpenHelper
(
context
).
getWritableDatabase
();
db
.
beginTransaction
();
db
.
delete
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
"id = ?"
,
new
String
[]{
location
.
getId
().
toString
()});
db
.
setTransactionSuccessful
();
db
.
endTransaction
();
db
.
close
();
}
private
Location
hydrate
(
Cursor
c
)
{
Location
l
=
new
Location
();
l
.
setId
(
c
.
getLong
(
c
.
getColumnIndex
(
"id"
)));
l
.
setRecordedAt
(
stringToDate
(
c
.
getString
(
c
.
getColumnIndex
(
"recordedAt"
))));
l
.
setLatitude
(
c
.
getString
(
c
.
getColumnIndex
(
"latitude"
)));
l
.
setLongitude
(
c
.
getString
(
c
.
getColumnIndex
(
"longitude"
)));
return
l
;
}
private
ContentValues
getContentValues
(
Location
location
)
{
ContentValues
values
=
new
ContentValues
();
values
.
put
(
"latitude"
,
location
.
getLatitude
());
values
.
put
(
"longitude"
,
location
.
getLongitude
());
values
.
put
(
"recordedAt"
,
dateToString
(
location
.
getRecordedAt
()));
return
values
;
}
public
Date
stringToDate
(
String
dateTime
)
{
SimpleDateFormat
iso8601Format
=
new
SimpleDateFormat
(
DATE_FORMAT
);
Date
date
=
null
;
try
{
date
=
iso8601Format
.
parse
(
dateTime
);
}
catch
(
ParseException
e
)
{
Log
.
e
(
"DBUtil"
,
"Parsing ISO8601 datetime ("
+
dateTime
+
") failed"
,
e
);
}
return
date
;
}
public
String
dateToString
(
Date
date
)
{
SimpleDateFormat
iso8601Format
=
new
SimpleDateFormat
(
DATE_FORMAT
);
return
iso8601Format
.
format
(
date
);
}
}
src/android/notification.png
0 → 100644
View file @
1f7459c5
3.58 KB
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