|
1 | | -import { Observable, EventData, Page } from '@nativescript/core'; |
| 1 | +import { Observable, EventData, Page, Dialogs } from '@nativescript/core'; |
2 | 2 | import { DemoSharedMlkitCore } from '@demo/shared'; |
3 | | -import { MLKitView } from '@nativescript/mlkit-core'; |
4 | | - |
| 3 | +import { DetectionType, MLKitView } from '@nativescript/mlkit-core'; |
| 4 | +import { BarcodeResult } from '@nativescript/mlkit-barcode-scanning'; |
| 5 | +import { FaceResult } from '@nativescript/mlkit-face-detection'; |
| 6 | +import { ImageLabelingResult } from '@nativescript/mlkit-image-labeling'; |
| 7 | +import { ObjectResult } from '@nativescript/mlkit-object-detection'; |
| 8 | +import { PoseResult } from '@nativescript/mlkit-pose-detection'; |
| 9 | +import { TextResult } from '@nativescript/mlkit-text-recognition'; |
5 | 10 | export function navigatingTo(args: EventData) { |
6 | 11 | const page = <Page>args.object; |
7 | 12 | page.bindingContext = new DemoModel(); |
8 | 13 | } |
9 | 14 |
|
10 | 15 | export class DemoModel extends DemoSharedMlkitCore { |
11 | 16 | camera: MLKitView; |
| 17 | + detectorType = "all"; |
12 | 18 |
|
13 | | - onLoaded(args){ |
| 19 | + onLoaded(args) { |
14 | 20 | this.camera = args.object; |
15 | 21 | } |
16 | 22 |
|
17 | | - onDetection(data) { |
18 | | - console.log('onDetection', data); |
| 23 | + onDetection(data, type: DetectionType) { |
| 24 | + console.log('onDetection', data, type); |
19 | 25 | } |
20 | 26 |
|
21 | | - toggleCamera(){ |
| 27 | + toggleCamera() { |
22 | 28 | this.camera.toggleCamera(); |
23 | 29 | } |
| 30 | + |
| 31 | + requestPermission() { |
| 32 | + this.camera.requestCameraPermission(); |
| 33 | + } |
| 34 | + |
| 35 | + changeType(args) { |
| 36 | + Dialogs.action('Change Detector Type', 'Cancel', [ |
| 37 | + 'all', |
| 38 | + 'barcode', |
| 39 | + 'digitalInk (unsupport atm)', |
| 40 | + 'face', |
| 41 | + 'image', |
| 42 | + 'object', |
| 43 | + 'pose', |
| 44 | + 'text', |
| 45 | + 'none' |
| 46 | + ]).then(value => { |
| 47 | + if (value === 'Cancel') { return } |
| 48 | + if (value.indexOf('digitalInk') > -1) { |
| 49 | + Dialogs.alert('digitalInk is currently unsupported') |
| 50 | + this.set('detectorType', 'none'); |
| 51 | + } else { |
| 52 | + this.set('detectorType', value); |
| 53 | + } |
| 54 | + }) |
| 55 | + } |
24 | 56 | } |
| 57 | + |
0 commit comments