From 6e5f0659d62248d480f90b760739845f494f89d2 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Mon, 23 Jan 2023 17:05:13 +0100 Subject: [PATCH] fix(android): improved native-api-usage --- package.json | 9 ----- packages/gps/package.json | 2 +- .../platforms/android/native-api-usage.json | 17 ++++----- src/gps/index.android.ts | 35 +++++++++---------- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 0bd297b..3f5c8b2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/gps/package.json b/packages/gps/package.json index c8f312a..2d1c1b1 100644 --- a/packages/gps/package.json +++ b/packages/gps/package.json @@ -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", diff --git a/packages/gps/platforms/android/native-api-usage.json b/packages/gps/platforms/android/native-api-usage.json index 1aa0d60..49c858c 100644 --- a/packages/gps/platforms/android/native-api-usage.json +++ b/packages/gps/platforms/android/native-api-usage.json @@ -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*" ] } \ No newline at end of file diff --git a/src/gps/index.android.ts b/src/gps/index.android.ts index de4fd60..42a06dd 100644 --- a/src/gps/index.android.ts +++ b/src/gps/index.android.ts @@ -129,24 +129,23 @@ function createLocationListener(successCallback: successC } }) as OnNmeaListener; } 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).locationListener && (this as NmeaListener).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; + locationListener._nmeaListener = new android.location.GpsStatus.NmeaListener({ + onNmeaReceived(timestamp: number, nmea: string) { + const locationListener = (this as NmeaListener).locationListener && (this as NmeaListener).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; } if (locationListener._nmeaListener) { locationListener._nmeaListener.locationListener = new WeakRef(locationListener);