Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0885C10447 for ; Fri, 21 Jun 2013 21:16:08 +0000 (UTC) Received: (qmail 58100 invoked by uid 500); 21 Jun 2013 21:16:07 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 58078 invoked by uid 500); 21 Jun 2013 21:16:07 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 58071 invoked by uid 99); 21 Jun 2013 21:16:07 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Jun 2013 21:16:07 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A23D882D2D1; Fri, 21 Jun 2013 21:16:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lorinbeer@apache.org To: commits@cordova.apache.org Message-Id: <67161f188a4f4cb1a35ccb501b87a4f5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [CB-3652] camera plugin breakout blackberry10 initial commit Date: Fri, 21 Jun 2013 21:16:07 +0000 (UTC) Updated Branches: refs/heads/master 4db9a6c81 -> f02ae7697 [CB-3652] camera plugin breakout blackberry10 initial commit Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/f02ae769 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/f02ae769 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/f02ae769 Branch: refs/heads/master Commit: f02ae7697e5533c181088beee8f2d0feaf67e57b Parents: 4db9a6c Author: lorinbeer Authored: Fri Jun 21 14:16:01 2013 -0700 Committer: lorinbeer Committed: Fri Jun 21 14:16:01 2013 -0700 ---------------------------------------------------------------------- plugin.xml | 8 +++ src/blackberry10/index.js | 124 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/f02ae769/plugin.xml ---------------------------------------------------------------------- diff --git a/plugin.xml b/plugin.xml index cc9f925..304bb65 100644 --- a/plugin.xml +++ b/plugin.xml @@ -51,6 +51,14 @@ id="org.apache.cordova.core.CameraLauncher" + + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/f02ae769/src/blackberry10/index.js ---------------------------------------------------------------------- diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js new file mode 100644 index 0000000..922f049 --- /dev/null +++ b/src/blackberry10/index.js @@ -0,0 +1,124 @@ +/* + * Copyright 2010-2011 Research In Motion Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var PictureSourceType = { + PHOTOLIBRARY : 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android) + CAMERA : 1, // Take picture from camera + SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) + }, + DestinationType = { + DATA_URL: 0, // Return base64 encoded string + FILE_URI: 1, // Return file uri (content://media/external/images/media/2 for Android) + NATIVE_URI: 2 // Return native uri (eg. asset-library://... for iOS) + }; + +function encodeBase64(filePath, callback) { + var sandbox = window.qnx.webplatform.getController().setFileSystemSandbox, // save original sandbox value + errorHandler = function (err) { + var msg = "An error occured: "; + + switch (err.code) { + case FileError.NOT_FOUND_ERR: + msg += "File or directory not found"; + break; + + case FileError.NOT_READABLE_ERR: + msg += "File or directory not readable"; + break; + + case FileError.PATH_EXISTS_ERR: + msg += "File or directory already exists"; + break; + + case FileError.TYPE_MISMATCH_ERR: + msg += "Invalid file type"; + break; + + default: + msg += "Unknown Error"; + break; + }; + + // set it back to original value + window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; + callback(msg); + }, + gotFile = function (fileEntry) { + fileEntry.file(function (file) { + var reader = new FileReader(); + + reader.onloadend = function (e) { + // set it back to original value + window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; + callback(this.result); + }; + + reader.readAsDataURL(file); + }, errorHandler); + }, + onInitFs = function (fs) { + window.qnx.webplatform.getController().setFileSystemSandbox = false; + fs.root.getFile(filePath, {create: false}, gotFile, errorHandler); + }; + + window.webkitRequestFileSystem(window.TEMPORARY, 10 * 1024 * 1024, onInitFs, errorHandler); // set size to 10MB max +} + +module.exports = { + takePicture: function (success, fail, args, env) { + var destinationType = JSON.parse(decodeURIComponent(args[1])), + sourceType = JSON.parse(decodeURIComponent(args[2])), + result = new PluginResult(args, env), + done = function (data) { + if (destinationType === DestinationType.FILE_URI) { + data = "file://" + data; + result.callbackOk(data, false); + } else { + encodeBase64(data, function (data) { + if (/^data:/.test(data)) { + data = data.slice(data.indexOf(",") + 1); + result.callbackOk(data, false); + } else { + result.callbackError(data, false); + } + }); + } + }, + cancel = function (reason) { + result.callbackError(reason, false); + }, + invoked = function (error) { + if (error) { + result.callbackError(error, false); + } + }; + + switch(sourceType) { + case PictureSourceType.CAMERA: + window.qnx.webplatform.getApplication().cards.camera.open("photo", done, cancel, invoked); + break; + + case PictureSourceType.PHOTOLIBRARY: + case PictureSourceType.SAVEDPHOTOALBUM: + window.qnx.webplatform.getApplication().cards.filePicker.open({ + mode: "Picker", + type: ["picture"] + }, done, cancel, invoked); + break; + } + + result.noResult(true); + } +};