2016-07-20 23:17:09 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
2016-09-22 04:04:46 +08:00
|
|
|
import { Observable } from 'rxjs/Observable';
|
2016-07-20 23:17:09 +08:00
|
|
|
|
2016-08-19 21:10:05 +08:00
|
|
|
export interface CameraPreviewRect {
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
x: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
y: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
width: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
height: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-17 16:50:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CameraPreviewSize {
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
maxWidth: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-20 23:17:09 +08:00
|
|
|
maxHeight: number;
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-17 16:50:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name CameraPreview
|
|
|
|
* @description
|
|
|
|
* Showing camera preview in HTML
|
|
|
|
*
|
2016-11-18 01:53:24 +08:00
|
|
|
* For more info, please see the [Cordova Camera Preview Plugin Docs](https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview).
|
2016-07-17 16:50:18 +08:00
|
|
|
*
|
2016-09-07 11:12:35 +08:00
|
|
|
* @usage
|
|
|
|
* ```
|
2016-11-20 21:54:38 +08:00
|
|
|
* import { CameraPreview, CameraPreviewRect } from 'ionic-native';
|
2016-09-07 11:12:35 +08:00
|
|
|
*
|
|
|
|
* // camera options (Size and location)
|
|
|
|
* let cameraRect: CameraPreviewRect = {
|
|
|
|
* x: 100,
|
|
|
|
* y: 100,
|
|
|
|
* width: 200,
|
|
|
|
* height: 200
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // start camera
|
|
|
|
* CameraPreview.startCamera(
|
|
|
|
* cameraRect, // position and size of preview
|
|
|
|
* 'front', // default camera
|
2016-11-18 01:53:24 +08:00
|
|
|
* true, // tap to take picture
|
2016-09-07 11:12:35 +08:00
|
|
|
* false, // disable drag
|
2016-12-01 01:58:22 +08:00
|
|
|
* false, // keep preview in front. Set to true (back of the screen) to apply overlaying elements
|
2016-11-28 17:24:23 +08:00
|
|
|
* 1 // set the preview alpha
|
2016-09-07 11:12:35 +08:00
|
|
|
* );
|
|
|
|
*
|
|
|
|
* // Set the handler to run every time we take a picture
|
|
|
|
* CameraPreview.setOnPictureTakenHandler().subscribe((result) => {
|
|
|
|
* console.log(result);
|
|
|
|
* // do something with the result
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // take a picture
|
|
|
|
* CameraPreview.takePicture({
|
|
|
|
* maxWidth: 640,
|
|
|
|
* maxHeight: 640
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* // Switch camera
|
|
|
|
* CameraPreview.switchCamera();
|
|
|
|
*
|
|
|
|
* // set color effect to negative
|
|
|
|
* CameraPreview.setColorEffect('negative');
|
|
|
|
*
|
|
|
|
* // Stop the camera preview
|
|
|
|
* CameraPreview.stopCamera();
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*
|
2016-12-06 21:58:38 +08:00
|
|
|
* @interfaces
|
|
|
|
* CameraPreviewRect
|
|
|
|
* CameraPreviewSize
|
2016-07-17 16:50:18 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-10-28 01:48:50 +08:00
|
|
|
pluginName: 'CameraPreview',
|
2016-11-19 06:30:06 +08:00
|
|
|
plugin: 'cordova-plugin-camera-preview',
|
2016-07-17 16:50:18 +08:00
|
|
|
pluginRef: 'cordova.plugins.camerapreview',
|
2016-11-19 06:30:06 +08:00
|
|
|
repo: 'https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview',
|
2016-07-17 16:50:18 +08:00
|
|
|
platforms: ['Android', 'iOS']
|
|
|
|
})
|
|
|
|
export class CameraPreview {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the camera preview instance.
|
2016-08-19 21:10:05 +08:00
|
|
|
* @param {CameraPreviewRect} position and size of the preview window - {x: number, y: number, width: number, height: number}
|
|
|
|
* @param {string} which camera to use - 'front' | 'back'
|
|
|
|
* @param {boolean} enable tap to take picture
|
|
|
|
* @param {boolean} enable preview box drag across the screen
|
|
|
|
* @param {boolean} send preview box to the back of the webview
|
|
|
|
* @param {number} alpha of the preview box
|
2016-07-17 16:50:18 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static startCamera(rect: CameraPreviewRect, defaultCamera: string, tapEnabled: boolean, dragEnabled: boolean, toBack: boolean, alpha: number): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the camera preview instance.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static stopCamera(): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take the picture, the parameter size is optional
|
2016-08-19 21:10:05 +08:00
|
|
|
* @param {CameraPreviewSize} optional - size of the picture to take
|
2016-07-17 16:50:18 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-12-14 09:49:46 +08:00
|
|
|
static takePicture(size?: CameraPreviewSize): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a callback function that receives the original picture and the image captured from the preview box.
|
2016-11-30 06:40:50 +08:00
|
|
|
* @returns {Observable<any>}
|
2016-07-17 16:50:18 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static setOnPictureTakenHandler(): Observable<any> { return; }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch from the rear camera and front camera, if available.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static switchCamera(): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the camera preview box.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static show(): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the camera preview box.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static hide(): void { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables the camera preview
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
static disable(): void { }
|
2016-07-17 16:50:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set camera color effect.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-11-23 21:16:02 +08:00
|
|
|
static setColorEffect(effect: string): void { }
|
2016-12-06 21:02:00 +08:00
|
|
|
|
2016-07-17 16:50:18 +08:00
|
|
|
}
|