cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject webworks commit: [CB-3368] Moving capture to a plugin
Date Fri, 28 Jun 2013 13:39:15 GMT
Updated Branches:
  refs/heads/master dcda56868 -> a633dceae


[CB-3368] Moving capture to a plugin

Reviewed by Bryan Higgins <bhiggins@blackberry.com>
Tested by Tracy Li <tli@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/a633dcea
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/a633dcea
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/a633dcea

Branch: refs/heads/master
Commit: a633dceae4ab8a1bdb8ea4d15667a68a34d409b5
Parents: dcda568
Author: Jeffrey Heifetz <jheifetz@blackberry.com>
Authored: Fri May 10 11:00:02 2013 -0400
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Fri Jun 28 09:42:35 2013 -0400

----------------------------------------------------------------------
 blackberry10/javascript/cordova.blackberry10.js | 66 +-------------
 blackberry10/plugins/Capture/plugin.xml         | 30 +++++++
 .../plugins/Capture/src/blackberry10/index.js   | 94 ++++++++++++++++++++
 3 files changed, 126 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a633dcea/blackberry10/javascript/cordova.blackberry10.js
----------------------------------------------------------------------
diff --git a/blackberry10/javascript/cordova.blackberry10.js b/blackberry10/javascript/cordova.blackberry10.js
index 7936b1b..37fab51 100644
--- a/blackberry10/javascript/cordova.blackberry10.js
+++ b/blackberry10/javascript/cordova.blackberry10.js
@@ -376,7 +376,7 @@ function checkArgs(spec, functionName, args, opt_callee) {
     if (errMsg) {
         errMsg += ', but got ' + typeName + '.';
         errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee,
i) + '" of ' + functionName + ': ' + errMsg;
-        // Don't log when running jake test.
+        // Don't log when running unit tests.
         if (typeof jasmine == 'undefined') {
             console.error(errMsg);
         }
@@ -794,7 +794,6 @@ define("cordova/exec", function(require, exports, module) {
 var cordova = require('cordova'),
     plugins = {
         'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
-        'Capture' : require('cordova/plugin/blackberry10/capture'),
         'FileTransfer': require('cordova/plugin/blackberry10/fileTransfer')
     };
 
@@ -3217,67 +3216,6 @@ module.exports = {
 
 });
 
-// file: lib/blackberry10/plugin/blackberry10/capture.js
-define("cordova/plugin/blackberry10/capture", function(require, exports, module) {
-
-var cordova = require('cordova');
-
-function capture(action, win, fail) {
-    var noop = function () {};
-
-    blackberry.invoke.card.invokeCamera(action, function (path) {
-        var sb = blackberry.io.sandbox;
-        blackberry.io.sandbox = false;
-        window.webkitRequestFileSystem(window.PERSISTENT, 1024, function (fs) {
-            fs.root.getFile(path, {}, function (fe) {
-                fe.file(function (file) {
-                    file.fullPath = fe.fullPath;
-                    win([file]);
-                    blackberry.io.sandbox = sb;
-                }, fail);
-            }, fail);
-        }, fail);
-    }, noop, noop);
-}
-
-module.exports = {
-    getSupportedAudioModes: function (args, win, fail) {
-        return {"status": cordova.callbackStatus.OK, "message": []};
-    },
-    getSupportedImageModes: function (args, win, fail) {
-        return {"status": cordova.callbackStatus.OK, "message": []};
-    },
-    getSupportedVideoModes: function (args, win, fail) {
-        return {"status": cordova.callbackStatus.OK, "message": []};
-    },
-    captureImage: function (args, win, fail) {
-        if (args[0].limit > 0) {
-            capture("photo", win, fail);
-        }
-        else {
-            win([]);
-        }
-
-        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
-    },
-    captureVideo: function (args, win, fail) {
-        if (args[0].limit > 0) {
-            capture("video", win, fail);
-        }
-        else {
-            win([]);
-        }
-
-        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
-    },
-    captureAudio: function (args, win, fail) {
-        fail("Capturing Audio not supported");
-        return {"status": cordova.callbackStatus.NO_RESULT, "message": "WebWorks Is On It"};
-    }
-};
-
-});
-
 // file: lib/blackberry10/plugin/blackberry10/compass.js
 define("cordova/plugin/blackberry10/compass", function(require, exports, module) {
 
@@ -6937,4 +6875,4 @@ document.addEventListener("DOMContentLoaded", function () {
 }(window));
 
 
-})();
\ No newline at end of file
+})();

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a633dcea/blackberry10/plugins/Capture/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Capture/plugin.xml b/blackberry10/plugins/Capture/plugin.xml
new file mode 100644
index 0000000..a13486d
--- /dev/null
+++ b/blackberry10/plugins/Capture/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.core.Capture"
+    version="0.0.1">
+
+    <name>Capture</name>
+
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Capture" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="media-capture" value="Capture"/>
+        </config-file>
+      </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a633dcea/blackberry10/plugins/Capture/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Capture/src/blackberry10/index.js b/blackberry10/plugins/Capture/src/blackberry10/index.js
new file mode 100644
index 0000000..d7c5627
--- /dev/null
+++ b/blackberry10/plugins/Capture/src/blackberry10/index.js
@@ -0,0 +1,94 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+//cordova-js/lib/common/plugin/CaptureError.js
+var INTERNAL_ERROR_CODE = 0,
+    APPLICATION_BUSY_ERROR_CODE = 1,
+    INVALID_ARGUMENT_ERROR_CODE = 2,
+    NO_MEDIA_FILES_ERROR_CODE = 3,
+    NOT_SUPPORTED_ERROR_CODE = 20;
+
+function capture(action, options, result, webview) {
+    var noop = function () {},
+        limit = options.limit || 1,
+        fail = function (error) {
+            result.callbackError({code: INTERNAL_ERROR_CODE});
+        },
+        onCaptured = function (path) {
+            var sb = webview.setFileSystemSandbox;
+            webview.setFileSystemSandbox = false;
+            window.webkitRequestFileSystem(window.PERSISTENT, 1024, function (fs) {
+                fs.root.getFile(path, {}, function (fe) {
+                    fe.file(function (file) {
+                        file.fullPath = fe.fullPath;
+                        webview.setFileSystemSandbox = sb;
+                        result.callbackOk([file]);
+                    }, fail);
+                }, fail);
+            }, fail);
+        },
+        onCancelled = function () {
+            result.callbackError({code: NO_MEDIA_FILES_ERROR_CODE });
+        },
+        onInvoked = function (error) {
+            if (error) {
+                result.callbackError({code: APPLICATION_BUSY_ERROR_CODE});
+            }
+        };
+
+    if (limit < 0) {
+        result.error({code: INVALID_ARGUMENT_ERROR_CODE});
+    } else {
+        window.qnx.webplatform.getApplication().cards.camera.open(action, onCaptured, onCancelled,
onInvoked);
+        result.noResult(true);
+    }
+}
+
+module.exports = {
+    getSupportedAudioModes: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.ok([]);
+    },
+    getSupportedImageModes: function (win, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.ok([]);
+    },
+    getSupportedVideoModes: function (win, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.ok([]);
+    },
+    captureImage: function (win, fail, args, env) {
+        var result = new PluginResult(args, env),
+            options = args[0] === "undefined" ? {} : JSON.parse(decodeURIComponent(args[0]));
+
+        capture("photo", options,  result, env.webview);
+    },
+    captureVideo: function (win, fail, args, env) {
+        var result = new PluginResult(args, env),
+            options = args[0] === "undefined" ? {} : JSON.parse(decodeURIComponent(args[0]));
+
+        capture("video", options, result, env.webview);
+    },
+    captureAudio: function (win, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error({code: NOT_SUPPORTED_ERROR_CODE});
+    }
+};


Mime
View raw message