From bbbbb3e8d0040d132dfcc6de33bb3a47d8ca282f Mon Sep 17 00:00:00 2001 From: AndreasGassmann Date: Tue, 4 Oct 2016 21:12:39 +0200 Subject: [PATCH] feat(zBar): add zBar barcode scanner plugin (#634) --- src/index.ts | 3 ++ src/plugins/z-bar.ts | 91 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/plugins/z-bar.ts diff --git a/src/index.ts b/src/index.ts index f7e66519f..de7b6bef5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,6 +107,7 @@ import { VideoEditor } from './plugins/video-editor'; import { VideoPlayer } from './plugins/video-player'; import { WebIntent } from './plugins/webintent'; import { YoutubeVideoPlayer } from './plugins/youtube-video-player'; +import { ZBar } from './plugins/z-bar'; import { Zip } from './plugins/zip'; export * from './plugins/3dtouch'; export * from './plugins/background-geolocation'; @@ -217,6 +218,7 @@ Vibration, VideoPlayer, WebIntent, YoutubeVideoPlayer, +ZBar, Zip } @@ -326,6 +328,7 @@ window['IonicNative'] = { Vibration, WebIntent, YoutubeVideoPlayer, + ZBar, Zip }; diff --git a/src/plugins/z-bar.ts b/src/plugins/z-bar.ts new file mode 100644 index 000000000..185280c0b --- /dev/null +++ b/src/plugins/z-bar.ts @@ -0,0 +1,91 @@ +import { Plugin, Cordova } from './plugin'; + +/** + * @name ZBar + * @description + * The ZBar Scanner Plugin allows you to scan 2d barcodes. + * + * Requires Cordova plugin: `cordova-plugin-cszbar`. For more info, please see the [zBar plugin docs](https://github.com/tjwoon/csZBar). + * + * @usage + * ``` + * import { ZBar } from 'ionic-native'; + * + * let zBarOptions = { + * flash: "off", + * drawSight: false + * }; + * + * ZBar.scan(zBarOptions) + * .then(result => { + * console.log(result); // Scanned code + * }) + * .catch(error => { + * console.log(error); // Error message + * }); + * + * ``` + * + * @advanced + * zBar options + * + * | Option | Type | Values | Defaults | + * |--------------------|-----------|-----------------------------------------------------------------------------------------| + * | text_title |`string?` | | `"Scan QR Code"` (Android only) | + * | text_instructions |`string?` | | `"Please point your camera at the QR code."` (Android only) | + * | camera |`string?` | `"front"`, `"back"`, | `"back"` | + * | flash |`string?` | `"on"`, `"off"`, `"auto"` | `"auto"` | + * | drawSight |`boolean?` | `true`, `false` | `true` (Draws red line in center of scanner) | + * + */ +@Plugin({ + plugin: 'cordova-plugin-cszbar', + pluginRef: 'cloudSky.zBar', + repo: 'https://github.com/tjwoon/csZBar', + platforms: ['Android', 'iOS'] +}) +export class ZBar { + + /** + * Open the scanner + * @param options { ZBarOptions } Scan options + * @return Returns a Promise that resolves with the scanned string, or rejects with an error. + */ + @Cordova() + static scan(options: ZBarOptions): Promise { return; } + +} + +export interface ZBarOptions { + /** + * A string representing the title text (Android only). + * Default: "Scan QR Code" + */ + text_title?: string; + + /** + * A string representing the instruction text (Android only). + * Default: "Please point your camera at the QR code." + */ + text_instructions?: string; + + /** + * A string defining the active camera when opening the scanner. + * Possible values: "front", "back" + * Default: "back" + */ + camera?: string; + + /** + * A string defining the state of the flash. + * Possible values: "on", "off", "auto" + * Default: "auto" + */ + flash?: string; + + /** + * A boolean to show or hide a line in the center of the scanner. + * Default: true + */ + drawSight?: boolean; +}