Skip to content

Commit

Permalink
fix(android): improved native-api-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jan 23, 2023
1 parent 5a6da5e commit 6e5f065
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"version": "1.0.0",
"description": "Track GPS location updates",
"main": "src/gps.js",
"typings": "src/gps.d.ts",
"nativescript": {
"platforms": {
"android": "2.3.0",
"ios": "2.3.0"
}
},
"scripts": {
"build": "lerna run build",
"build.watch": "lerna run build.watch",
Expand All @@ -24,7 +16,6 @@
"start": "./node_modules/.bin/ntl -A -s 15 -o",
"submodules": "git submodule update --init",
"sync": "node ./tools/sync.js",
"sync.test": "node ./tools/sync.js",
"tsc": "cpy '**/*.d.ts' '../plugin' --parents --cwd=src && tsc -skipLibCheck -d",
"update": "node ./tools/update.js",
"doc": "node tools/builddoc.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/gps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
"scripts": {
"build": "npm run tsc && npm run readme",
"build": "npm run tsc",
"build.all": "npm run build",
"readme": "readme generate -c ../../tools/readme/blueprint.json",
"tsc": "cpy '**/*.d.ts' '../../packages/gps' --parents --cwd=../../src/gps && tsc -skipLibCheck -d",
Expand Down
17 changes: 9 additions & 8 deletions packages/gps/platforms/android/native-api-usage.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"uses": [
"android.location.GpsStatus*:*",
"android.location:Location*",
"android.location:LocationManager*",
"android.location:LocationProvider*",
"android.location:OnNmeaMessageListener*",
"android.location:LocationListener*",
"android.location:Criteria*",
"java.util:List*",
"android.location.GpsStatus:NmeaListener",
"android.location:Location",
"android.location:LocationManager",
"android.location:LocationProvider",
"android.location:OnNmeaMessageListener",
"android.location:LocationListener",
"android.location:Criteria",
"java.util:List",
"java.lang:System",
"android.os:SystemClock*"
]
}
35 changes: 17 additions & 18 deletions src/gps/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,23 @@ function createLocationListener<T = DefaultLatLonKeys>(successCallback: successC
}
}) as OnNmeaListener<T>;
} else {
// TODO: bring back when https://github.com/NativeScript/android-runtime/issues/1645 is fixed
// locationListener._nmeaListener = new android.location.GpsStatus.NmeaListener({
// onNmeaReceived(timestamp: number, nmea: string) {
// const locationListener = (this as NmeaListener<T>).locationListener && (this as NmeaListener<T>).locationListener.get();
// if (locationListener && nmea[0] === '$') {
// const tokens = nmea.split(',');
// const type = tokens[0];
// const alt = tokens[9];
// // Parse altitude above sea level, Detailed description of NMEA string here http://aprs.gids.nl/nmea/#gga
// if (type.endsWith('GGA')) {
// if (alt && alt.length > 0) {
// locationListener.mLastMslAltitudeTimestamp = timestamp;
// locationListener.mLastMslAltitude = parseFloat(alt);
// }
// }
// }
// },
// }) as NmeaListener<T>;
locationListener._nmeaListener = new android.location.GpsStatus.NmeaListener({
onNmeaReceived(timestamp: number, nmea: string) {
const locationListener = (this as NmeaListener<T>).locationListener && (this as NmeaListener<T>).locationListener.get();
if (locationListener && nmea[0] === '$') {
const tokens = nmea.split(',');
const type = tokens[0];
const alt = tokens[9];
// Parse altitude above sea level, Detailed description of NMEA string here http://aprs.gids.nl/nmea/#gga
if (type.endsWith('GGA')) {
if (alt && alt.length > 0) {
locationListener.mLastMslAltitudeTimestamp = timestamp;
locationListener.mLastMslAltitude = parseFloat(alt);
}
}
}
}
}) as NmeaListener<T>;
}
if (locationListener._nmeaListener) {
locationListener._nmeaListener.locationListener = new WeakRef(locationListener);
Expand Down

0 comments on commit 6e5f065

Please sign in to comment.