Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo/app/app.css
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
@import '~nativescript-theme-core/css/core.light.css';
.ns-dark Button{
color:black;
}
4 changes: 2 additions & 2 deletions demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as application from 'tns-core-modules/application';
application.run({ moduleName: "app-root" });
import { Application as application } from '@nativescript/core';
application.run({ moduleName: "app-root" });
18 changes: 10 additions & 8 deletions demo/app/background-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as geolocation from "nativescript-geolocation";
import { Accuracy } from "tns-core-modules/ui/enums";
import * as application from "tns-core-modules/application";
import { device } from "tns-core-modules/platform";
import * as Toast from "nativescript-toast";
import { Accuracy } from "@nativescript/core/ui/enums";
import {Application as application, Device as device } from "@nativescript/core";

let watchId;

Expand All @@ -19,8 +17,10 @@ function _startWatch() {
watchId = geolocation.watchLocation(
function (loc) {
if (loc) {
let toast = Toast.makeText('Background Location: \n' + loc.latitude + ', ' + loc.longitude);
toast.show();

android.widget.Toast.makeText(application.android.context, 'Background Location: \n' + loc.latitude + ', ' + loc.longitude, android.widget.Toast.LENGTH_SHORT).show();
// let toast = new Toasty({text:'Background Location: \n' + loc.latitude + ', ' + loc.longitude});
// toast.show();
console.log('Background Location: ' + loc.latitude + ' ' + loc.longitude);
}
},
Expand All @@ -42,7 +42,8 @@ application.on(application.exitEvent, _clearWatch);
export function getBackgroundServiceClass() {
if (application.android) {
if (device.sdkVersion < "26") {
@JavaProxy("com.nativescript.location.BackgroundService")
@NativeClass()
@JavaProxy('com.nativescript.location.BackgroundService')
class BackgroundService extends (<any>android).app.Service {
constructor() {
super();
Expand Down Expand Up @@ -70,7 +71,8 @@ export function getBackgroundServiceClass() {
}
return BackgroundService;
} else {
@JavaProxy("com.nativescript.location.BackgroundService26")
@NativeClass()
@JavaProxy('com.nativescript.location.BackgroundService26')
class BackgroundService26 extends (<any>android.app).job.JobService {
constructor() {
super();
Expand Down
8 changes: 2 additions & 6 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as geolocation from "nativescript-geolocation";
import { Accuracy } from "tns-core-modules/ui/enums";
import { EventData } from "tns-core-modules/data/observable";
import { Page } from "tns-core-modules/ui/page";
import { Accuracy } from "@nativescript/core/ui/enums";
import { EventData, Page, Application as application, Device as device, Utils as utils } from "@nativescript/core";
import { MainViewModel } from "./main-view-model";
const utils = require("tns-core-modules/utils/utils");
import * as application from "tns-core-modules/application";
import { device } from "tns-core-modules/platform";
import { BackgroundServiceClass } from "./background-service";

let page: Page;
Expand Down
3 changes: 1 addition & 2 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as geolocation from "nativescript-geolocation";
import { Observable } from "tns-core-modules/data/observable";
import { ObservableArray } from "tns-core-modules/data/observable-array";
import { Observable, ObservableArray } from "@nativescript/core";

export class MainViewModel extends Observable {
private _locations: ObservableArray<geolocation.Location>;
Expand Down
8 changes: 0 additions & 8 deletions demo/app/package.json

This file was deleted.

14 changes: 14 additions & 0 deletions demo/nativescript.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NativeScriptConfig } from '@nativescript/core';

export default {
id: 'org.nativescript.demo',
appResourcesPath: 'app/App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
requireModules: {
0: 'nativescript-geolocation',
},
},
appPath: 'app',
} as NativeScriptConfig;
27 changes: 10 additions & 17 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
{
"nativescript": {
"id": "org.nativescript.demo",
"tns-android": {
"version": "6.2.0"
},
"tns-ios": {
"version": "6.2.0"
}
},
"dependencies": {
"@nativescript/core": "7.0.0",
"@nativescript/webpack": "3.0.0",
"nativescript-geolocation": "../src",
"nativescript-theme-core": "^1.0.4",
"nativescript-toast": "~2.0.0",
"nativescript-unit-test-runner": "0.7.0",
"tns-core-modules": "^6.0.0"
"nativescript-unit-test-runner": "0.7.0"
},
"devDependencies": {
"@nativescript/android": "7.0.0",
"@nativescript/ios": "7.0.1",
"@nativescript/types": "7.0.0",
"jasmine-core": "^2.5.2",
"karma": "4.1.0",
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "^0.4.0",
"karma-webpack": "3.0.5",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-webpack": "^1.3.0",
"tns-platform-declarations": "^6.0.0",
"tslint": "~5.11.0",
"karma-webpack": "3.0.5",
"typescript": "~3.4.5"
"typescript": "3.9.7"
},
"scripts": {
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'",
"build.plugin": "cd ../src && npm run build"
}
},
"main": "app.js"
}
12 changes: 7 additions & 5 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "es2017",
"module": "esnext",
"declaration": false,
"removeComments": true,
"removeComments": false,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom",
"es2015.iterable"
"es2015.iterable",
"es2017"
],
"pretty": true,
"allowUnreachableCode": false,
Expand All @@ -30,7 +31,8 @@
"~/*": [
"app/*"
]
}
},
"moduleResolution": "node"
},
"include": [
"../src",
Expand Down
27 changes: 13 additions & 14 deletions src/geolocation.android.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { on as applicationOn, android as androidAppInstance, AndroidApplication, uncaughtErrorEvent, UnhandledErrorEventData } from "application";
import { Accuracy } from "tns-core-modules/ui/enums";
import { setTimeout, clearTimeout } from "tns-core-modules/timer";
import { Application, AndroidApplication, UnhandledErrorEventData, Enums } from "@nativescript/core";
import { setTimeout, clearTimeout } from "@nativescript/core/timer";
import { LocationBase, defaultGetLocationTimeout, fastestTimeUpdate, minTimeUpdate } from "./geolocation.common";
import { Options, successCallbackType, errorCallbackType } from "./location-monitor";
import * as permissions from "nativescript-permissions";
Expand All @@ -18,10 +17,10 @@ let attachedForErrorHandling = false;
function _ensureLocationClient() {
// Wrapped in a function as we should not access java object there because of the snapshots.
fusedLocationClient = fusedLocationClient ||
com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(androidAppInstance.context);
com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Application.android.context);
}

androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: any) {
Application.android.on(AndroidApplication.activityResultEvent, function (args: any) {
if (args.requestCode === REQUEST_ENABLE_LOCATION) {
if (args.resultCode === 0) {
if (_onEnableLocationFail) {
Expand All @@ -34,13 +33,13 @@ androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: an
});

function isAirplaneModeOn(): boolean {
return android.provider.Settings.System.getInt(androidAppInstance.context.getContentResolver(),
return android.provider.Settings.System.getInt(Application.android.context.getContentResolver(),
android.provider.Settings.System.AIRPLANE_MODE_ON) !== 0;
}

function isProviderEnabled(provider: string): boolean {
try {
const locationManager: android.location.LocationManager = (<android.content.Context>androidAppInstance.context)
const locationManager: android.location.LocationManager = (<android.content.Context>Application.android.context)
.getSystemService(android.content.Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(provider);
} catch (ex) {
Expand Down Expand Up @@ -115,7 +114,7 @@ function _getLocationRequest(options: Options): any {
if (options.updateDistance) {
mLocationRequest.setSmallestDisplacement(options.updateDistance);
}
if (options.desiredAccuracy === Accuracy.high) {
if (options.desiredAccuracy === Enums.Accuracy.high) {
mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_HIGH_ACCURACY);
} else {
mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
Expand Down Expand Up @@ -178,7 +177,7 @@ export function watchLocation(successCallback: successCallbackType, errorCallbac

if (!attachedForErrorHandling) {
attachedForErrorHandling = true;
applicationOn(uncaughtErrorEvent, errorHandler.bind(this));
Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this));
}

let locationRequest = _getLocationRequest(options);
Expand Down Expand Up @@ -215,7 +214,7 @@ export function enableLocationRequest(always?: boolean): Promise<void> {
// on REQUEST_ENABLE_LOCATION Activity Result
_onEnableLocationSuccess = resolve;
_onEnableLocationFail = reject;
return ex.startResolutionForResult(androidAppInstance.foregroundActivity, REQUEST_ENABLE_LOCATION);
return ex.startResolutionForResult(Application.android.foregroundActivity, REQUEST_ENABLE_LOCATION);
} catch (sendEx) {
// Ignore the error.
return resolve();
Expand All @@ -240,7 +239,7 @@ function _makeGooglePlayServicesAvailable(): Promise<void> {
return;
}
let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
googleApiAvailability.makeGooglePlayServicesAvailable(androidAppInstance.foregroundActivity)
googleApiAvailability.makeGooglePlayServicesAvailable(Application.android.foregroundActivity)
.addOnSuccessListener(_getTaskSuccessListener(resolve))
.addOnFailureListener(_getTaskFailListener(reject));
});
Expand All @@ -253,7 +252,7 @@ function _isGooglePlayServicesAvailable(): boolean {

let isLocationServiceEnabled = true;
let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(androidAppInstance.context);
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(Application.android.context);
if (resultCode !== com.google.android.gms.common.ConnectionResult.SUCCESS) {
isLocationServiceEnabled = false;
}
Expand All @@ -268,12 +267,12 @@ function _isLocationServiceEnabled(options?: Options): Promise<boolean> {
return;
}

options = options || { desiredAccuracy: Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 };
options = options || { desiredAccuracy: Enums.Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 };
let locationRequest = _getLocationRequest(options);
let locationSettingsBuilder = new com.google.android.gms.location.LocationSettingsRequest.Builder();
locationSettingsBuilder.addLocationRequest(locationRequest);
locationSettingsBuilder.setAlwaysShow(true);
let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(androidAppInstance.context);
let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(Application.android.context);
locationSettingsClient.checkLocationSettings(locationSettingsBuilder.build())
.addOnSuccessListener(_getTaskSuccessListener(resolve))
.addOnFailureListener(_getTaskFailListener(reject));
Expand Down
17 changes: 8 additions & 9 deletions src/geolocation.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Accuracy } from "tns-core-modules/ui/enums";
import { setTimeout, clearTimeout } from "tns-core-modules/timer";
import { on as applicationOn, uncaughtErrorEvent, UnhandledErrorEventData } from "tns-core-modules/application";
import { Enums, Device, Application, UnhandledErrorEventData} from "@nativescript/core";
import { setTimeout, clearTimeout } from "@nativescript/core/timer";

import {
LocationBase,
Expand All @@ -12,13 +11,13 @@ import {
successCallbackType,
errorCallbackType
} from "./location-monitor";
import * as Platform from "platform";

const locationManagers = {};
const locationListeners = {};
let watchId = 0;
let attachedForErrorHandling = false;

@NativeClass
class LocationListenerImpl extends NSObject implements CLLocationManagerDelegate {
public static ObjCProtocols = [CLLocationManagerDelegate]; // tslint:disable-line:variable-name

Expand Down Expand Up @@ -140,7 +139,7 @@ function errorHandler(errData: UnhandledErrorEventData) {
}

function getVersionMaj () {
return parseInt(Platform.device.osVersion.split(".")[0]);
return parseInt(Device.osVersion.split(".")[0]);
}

// options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout
Expand Down Expand Up @@ -184,7 +183,7 @@ export function getCurrentLocation(options: Options): Promise<Location> {
return;
}

if (options.desiredAccuracy !== Accuracy.any && !initLocation) {
if (options.desiredAccuracy !== Enums.Accuracy.any && !initLocation) {
// regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested
initLocation = location;
return;
Expand Down Expand Up @@ -223,7 +222,7 @@ export function watchLocation(successCallback: successCallbackType,
options: Options): number {
if (!attachedForErrorHandling) {
attachedForErrorHandling = true;
applicationOn(uncaughtErrorEvent, errorHandler.bind(this));
Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this));
}

let zonedSuccessCallback = (<any>global).zonedCallback(successCallback);
Expand Down Expand Up @@ -359,7 +358,7 @@ export class LocationMonitor {
static createiOSLocationManager(locListener: any, options: Options): CLLocationManager {
let iosLocManager = new CLLocationManager();
iosLocManager.delegate = locListener;
iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high;
iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high;
iosLocManager.distanceFilter = options ? options.updateDistance : minRangeUpdate;
locationManagers[locListener.id] = iosLocManager;
locationListeners[locListener.id] = locListener;
Expand All @@ -384,7 +383,7 @@ function getIOSLocationManager(locListener: any, options: Options): CLLocationMa
let manager = new iosLocationManager();

manager.delegate = locListener;
manager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high;
manager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high;
manager.distanceFilter = options ? options.updateDistance : minRangeUpdate;

locationManagers[locListener.id] = manager;
Expand Down
11 changes: 6 additions & 5 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"typings": "index.d.ts",
"nativescript": {
"platforms": {
"android": "4.0.0",
"ios": "4.0.0"
"android": "7.0.0",
"ios": "7.0.0"
}
},
"scripts": {
Expand Down Expand Up @@ -38,9 +38,10 @@
"homepage": "https://github.com/NativeScript/nativescript-geolocation",
"readmeFilename": "README.md",
"devDependencies": {
"tns-core-modules": "^5.0.0",
"tns-platform-declarations": "^5.0.0",
"typescript": "~3.1.6",
"@nativescript/core": "7.0.0",
"@nativescript/types": "7.0.0",
"@nativescript/webpack": "~3.0.0",
"typescript": "~3.9.0",
"prompt": "~1.0.0",
"rimraf": "~2.6.2",
"tslint": "~5.11.0"
Expand Down
3 changes: 1 addition & 2 deletions src/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />
5 changes: 3 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "ES2017",
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"removeComments": true,
"preserveConstEnums": true,
Expand Down