Skip to content

Commit d540785

Browse files
committed
test: demo app update
1 parent 2baf738 commit d540785

15 files changed

+1604
-2499
lines changed

demo/app/app.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
@import "~nativescript-theme-core/css/core.css";
2-
1+

32
page {
43
background-color: #f4f4f4;
54
}

demo/app/characteristics-page-view-model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as dialogs from '@nativescript/core/ui/dialogs';
22
import { Observable } from '@nativescript/core/data/observable';
3-
import { Bluetooth, getBluetoothInstance, Peripheral, ReadResult, Service } from '@nativescript-community/ble';
3+
import { Bluetooth, Peripheral, ReadResult, Service, getBluetoothInstance } from '@nativescript-community/ble';
44
import { Prop } from './utils/obs-prop';
55

66
export class CharacteristicsViewModel extends Observable {
@@ -13,7 +13,6 @@ export class CharacteristicsViewModel extends Observable {
1313
super();
1414
this.service = navContext.service;
1515
this.peripheral = navContext.peripheral;
16-
this._bluetooth.debug = true;
1716
}
1817

1918
public onCharacteristicTap(args) {

demo/app/main-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export function onPeripheralTestTap(args) {
1111
}
1212
console.log('!!&&&&***** Long press item with index ', args.object.bindingContext);
1313
args.object.page.bindingContext.onPeripheralTestTap(args.object.bindingContext);
14-
}
14+
}

demo/app/main-view-model.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as dialogs from '@nativescript/core/ui/dialogs';
22
import { Observable } from '@nativescript/core/data/observable';
33
import { ObservableArray } from '@nativescript/core/data/observable-array';
4-
import { topmost } from '@nativescript/core/ui/frame';
54
import { Prop } from './utils/obs-prop';
65
import { Bluetooth, Peripheral, getBluetoothInstance } from '@nativescript-community/ble';
6+
import { Frame } from '@nativescript/core/ui/frame';
77

88
export class DemoAppModel extends Observable {
99
@Prop() public isLoading = false;
@@ -14,7 +14,6 @@ export class DemoAppModel extends Observable {
1414
constructor() {
1515
super();
1616
// enables the console.logs from the Bluetooth source code
17-
this._bluetooth.debug = true;
1817

1918
// using an event listener instead of the 'onDiscovered' callback of 'startScanning'
2019
this._bluetooth.on(Bluetooth.device_discovered_event, (eventData: any) => {
@@ -72,7 +71,7 @@ export class DemoAppModel extends Observable {
7271
},
7372
animated: true
7473
};
75-
topmost().navigate(navigationEntry);
74+
Frame.topmost().navigate(navigationEntry);
7675
}
7776

7877
public onPeripheralTestTap(peri) {
@@ -87,7 +86,7 @@ export class DemoAppModel extends Observable {
8786
},
8887
animated: true
8988
};
90-
topmost().navigate(navigationEntry);
89+
Frame.topmost().navigate(navigationEntry);
9190
}
9291

9392
// this one 'manually' checks for permissions

demo/app/package.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

demo/app/services-page-view-model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as dialogs from '@nativescript/core/ui/dialogs';
2-
import { topmost } from '@nativescript/core/ui/frame';
32
import { ObservableArray } from '@nativescript/core/data/observable-array';
4-
import { fromObject, Observable } from '@nativescript/core/data/observable';
5-
import { AdvertismentData, Bluetooth, getBluetoothInstance, Peripheral, Service } from '@nativescript-community/ble';
3+
import { Observable, fromObject } from '@nativescript/core/data/observable';
4+
import { AdvertismentData, Bluetooth, Peripheral, Service, getBluetoothInstance } from '@nativescript-community/ble';
65
import { Prop } from './utils/obs-prop';
6+
import { Frame } from '@nativescript/core/ui/frame';
77

8+
//@ts-ignore
89
const companyIdentifier = require('./companyIdentifiers.json');
910

1011
export class ServicesViewModel extends Observable {
@@ -19,7 +20,6 @@ export class ServicesViewModel extends Observable {
1920

2021
constructor(navContext) {
2122
super();
22-
this._bluetooth.debug = true;
2323
this.peripheral = navContext.peripheral;
2424
this.advertismentData = navContext.peripheral.advertismentData as AdvertismentData;
2525
console.log('peripheral', JSON.stringify(this.peripheral));
@@ -85,7 +85,7 @@ export class ServicesViewModel extends Observable {
8585
animated: true
8686
};
8787

88-
topmost().navigate(navigationEntry);
88+
Frame.topmost().navigate(navigationEntry);
8989
}
9090

9191
public onConnectTap(args) {

demo/app/test-page-model.ts

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import { AdvertismentData, getBluetoothInstance, Peripheral, Service } from '@nativescript-community/ble';
2-
import { GPS, Options as GeolocationOptions } from 'nativescript-gps';
3-
import { ApplicationEventData, on as applicationOn, resumeEvent, suspendEvent } from '@nativescript/core/application';
1+
import { AdvertismentData, Peripheral, Service, getBluetoothInstance } from '@nativescript-community/ble';
42
import { Observable } from '@nativescript/core/data/observable';
53
import { ObservableArray } from '@nativescript/core/data/observable-array';
64
import * as dialogs from '@nativescript/core/ui/dialogs';
7-
import { Accuracy } from '@nativescript/core/ui/enums/enums';
8-
import { topmost } from '@nativescript/core/ui/frame';
5+
import { Frame } from '@nativescript/core/ui/frame';
96
import { Prop } from './utils/obs-prop';
107

118

12-
const geolocation = new GPS();
139
export class TestViewModel extends Observable {
1410
@Prop() public discoveredServices = new ObservableArray<Service>();
1511
@Prop() public isLoading = false;
@@ -22,11 +18,9 @@ export class TestViewModel extends Observable {
2218
_isIOSBackgroundMode = false;
2319
watchId;
2420
currentWatcher: Function;
25-
_deferringUpdates =false
2621

2722
constructor(navContext) {
2823
super();
29-
this._bluetooth.debug = false;
3024
this.peripheral = navContext.peripheral;
3125
this.advertismentData = navContext.peripheral.advertismentData as AdvertismentData;
3226
console.log('peripheral', JSON.stringify(this.peripheral));
@@ -35,8 +29,6 @@ export class TestViewModel extends Observable {
3529
console.log('uuids', this.advertismentData.serviceUUIDs);
3630
console.log('txPowerLevel', this.advertismentData.txPowerLevel);
3731

38-
applicationOn(suspendEvent, this.onAppPause, this);
39-
applicationOn(resumeEvent, this.onAppResume, this);
4032
// console.log('localName', this.advertismentData.localName);
4133
// console.log('serviceUUIDs', this.advertismentData.serviceUUIDs);
4234
// console.log('txPowerLevel', this.advertismentData.txPowerLevel);
@@ -45,76 +37,6 @@ export class TestViewModel extends Observable {
4537
// console.log('manufacturerData', this.advertismentData.manufacturerData);
4638
// console.log('serviceData', this.advertismentData.serviceData);
4739
}
48-
onAppResume(args: ApplicationEventData) {
49-
if (args.ios) {
50-
this._isIOSBackgroundMode = false;
51-
// For iOS applications, args.ios is UIApplication.
52-
console.log('UIApplication: resumeEvent', this.isWatching());
53-
if (this.isWatching()) {
54-
const watcher = this.currentWatcher;
55-
this.stopWatch();
56-
this.startWatch(watcher);
57-
}
58-
}
59-
}
60-
onAppPause(args: ApplicationEventData) {
61-
if (args.ios) {
62-
this._isIOSBackgroundMode = true;
63-
// For iOS applications, args.ios is UIApplication.
64-
console.log('UIApplication: suspendEvent', this.isWatching());
65-
if (this.isWatching()) {
66-
const watcher = this.currentWatcher;
67-
this.stopWatch();
68-
this.startWatch(watcher);
69-
}
70-
}
71-
}
72-
onDeferred() {
73-
this._deferringUpdates = false;
74-
}
75-
onLocation(loc, manager?: any) {
76-
77-
if (manager && this._isIOSBackgroundMode && !this._deferringUpdates) {
78-
this._deferringUpdates = true;
79-
manager.allowDeferredLocationUpdatesUntilTraveledTimeout(0, 10);
80-
}
81-
}
82-
startWatch(onLoc?: Function) {
83-
this.currentWatcher = onLoc;
84-
const options: GeolocationOptions = { desiredAccuracy: Accuracy.high, minimumUpdateTime: 1000, onDeferred:this.onDeferred.bind(this) };
85-
86-
// if (!isAndroid) {
87-
// if (this._isIOSBackgroundMode) {
88-
// options.pausesLocationUpdatesAutomatically = false;
89-
// options.allowsBackgroundLocationUpdates = true;
90-
// options.activityType = CLActivityType.Fitness;
91-
// } else {
92-
options.pausesLocationUpdatesAutomatically = false;
93-
options.allowsBackgroundLocationUpdates = true;
94-
options.activityType = 3;
95-
// }
96-
// } else {
97-
// if (!gVars.isWatch) {
98-
// options.provider = 'gps';
99-
// }
100-
// }
101-
console.log('startWatch', options);
102-
103-
return geolocation.watchLocation(this.onLocation.bind(this), () => {}, options).then(id => (this.watchId = id));
104-
}
105-
106-
stopWatch() {
107-
console.log('stopWatch', this.watchId);
108-
if (this.watchId) {
109-
geolocation.clearWatch(this.watchId);
110-
this.watchId = null;
111-
this.currentWatcher = null;
112-
}
113-
}
114-
115-
isWatching() {
116-
return !!this.watchId;
117-
}
11840
formatData(title: string, advKey: string) {
11941
return title + ': ' + JSON.stringify(this.advertismentData[advKey]);
12042
}
@@ -160,7 +82,6 @@ export class TestViewModel extends Observable {
16082
onConnected: peripheral => {
16183
this.connected = true;
16284
console.log('------- Peripheral connected: ' + JSON.stringify(peripheral));
163-
this.startWatch();
16485
peripheral.services.forEach(value => {
16586
console.log('---- ###### adding service: ' + value.UUID);
16687
this.discoveredServices.push(value);
@@ -197,7 +118,7 @@ export class TestViewModel extends Observable {
197118
animated: true
198119
};
199120

200-
topmost().navigate(navigationEntry);
121+
Frame.topmost().navigate(navigationEntry);
201122
}
202123

203124
public onStartTap(args) {

demo/app/utils/obs-prop.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Observable } from "@nativescript/core/data/observable";
1+
import { Observable } from '@nativescript/core/data/observable';
22

33
export function Prop() {
4-
return (target: Observable, propertyKey: string) => {
5-
Object.defineProperty(target, propertyKey, {
6-
get() {
7-
return this["_" + propertyKey];
8-
},
9-
set(value) {
10-
if (this["_" + propertyKey] === value) {
11-
return;
12-
}
4+
return (target: Observable, propertyKey: string) => {
5+
Object.defineProperty(target, propertyKey, {
6+
get() {
7+
return this['_' + propertyKey];
8+
},
9+
set(value) {
10+
if (this['_' + propertyKey] === value) {
11+
return;
12+
}
1313

14-
this["_" + propertyKey] = value;
15-
this.notifyPropertyChange(propertyKey, value);
16-
},
17-
enumerable: true,
18-
configurable: true
19-
});
20-
};
14+
this['_' + propertyKey] = value;
15+
this.notifyPropertyChange(propertyKey, value);
16+
},
17+
enumerable: true,
18+
configurable: true
19+
});
20+
};
2121
}

demo/nativescript.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NativeScriptConfig } from '@nativescript/core';
2+
3+
export default {
4+
id: 'org.nativescript.bluetoothdemo',
5+
appResourcesPath: 'app/App_Resources',
6+
android: {
7+
v8Flags: '--expose_gc',
8+
markingMode: 'none'
9+
},
10+
appPath: 'app'
11+
} as NativeScriptConfig;

demo/nsconfig.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)