9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2024-10-06 18:32:07 +08:00
customCamera/www/customCamera.js

69 lines
2.8 KiB
JavaScript
Raw Normal View History

"use strict";
(function(require, module) {
// Get cordova plugin.
var exec = require("cordova/exec");
// constructor.
function CustomCameraExport() {}
CustomCameraExport.prototype.FlashModes = {DISABLE: 0, ACTIVE: 1, AUTO: 2};
/**
* Start custom camera.
*
* @param {object} options Options to plugin.
* @param {function} successFct Callback function to success action.
* @param {function} failFct Callback function to fail action.
*/
CustomCameraExport.prototype.startCamera = function(options, successFct, failFct) {
var defaultOptions = {
imgBackgroundBase64: null, // background picture in base64.
imgBackgroundBase64OtherOrientation: null, // background picture in base64 for second orientation. If it's not defined, imgBackgroundBase64 is used.
miniature: true, // active or disable the miniature function.
saveInGallery: false, // save or not the picture in gallery.
cameraBackgroundColor: "#e26760", // color of the camera button.
cameraBackgroundColorPressed: "#dc453d", // color of the pressed camera button.
// To get supported color formats, go to see method parseColor : http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
quality: 100, // picture's quality : range 0 - 100 : http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream) (parameter "quality")
opacity: true, // active or disable the opacity function.
defaultFlash: this.FlashModes.DISABLE, // default state for flash. Corrects values = 0 (disable) / 1 (active) / 2 (auto)
switchFlash: true // active or disable the switch flash button.
};
for (var nameOption in defaultOptions) {
if (options[nameOption] === undefined) {
options[nameOption] = defaultOptions[nameOption];
}
}
function successFctCallback(data) {
successFct(data);
}
function failFctCallback(data) {
failFct(data.code, data.message);
}
exec(
successFctCallback,
failFctCallback,
"CustomCamera",
"startCamera",
[
options.imgBackgroundBase64,
options.imgBackgroundBase64OtherOrientation,
options.miniature,
options.saveInGallery,
options.cameraBackgroundColor,
options.cameraBackgroundColorPressed,
options.quality,
options.opacity,
options.defaultFlash,
options.switchFlash
]
);
};
module.exports = new CustomCameraExport();
})(require, module);