You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/05/09 17:27:02 UTC

[3/4] js commit: added show/hide preview and added camera.getPicture

added show/hide preview and added camera.getPicture


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

Branch: refs/heads/master
Commit: caa733bdf70d33832111bf1c43fb9f7460102a2f
Parents: 516c137
Author: Anis Kadri <an...@gmail.com>
Authored: Wed May 9 02:51:34 2012 -0700
Committer: Anis Kadri <an...@gmail.com>
Committed: Wed May 9 02:51:34 2012 -0700

----------------------------------------------------------------------
 lib/bada/plugin/bada/Camera.js |   80 +++++++++++++++++++++++-----------
 1 files changed, 54 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/caa733bd/lib/bada/plugin/bada/Camera.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/bada/Camera.js b/lib/bada/plugin/bada/Camera.js
index 6c7e40a..382f3ec 100644
--- a/lib/bada/plugin/bada/Camera.js
+++ b/lib/bada/plugin/bada/Camera.js
@@ -1,30 +1,58 @@
 module.exports = {
-      _mainCamera: null,
-      _cams: [],
-      getPicture: function(cameraSuccess, cameraFailure, cameraOptions) {
-       // TODO
-      },
-      getPreview: function() {
-       var self = this;
-       var onCreatePreviewNodeSuccess = function(previewObject) {
-           var previewDiv = document.getElementById("preview");
-           previewDiv.appendChild(previewObject);
-           previewObject.style.visibility = "visible";
-       };
-       var error = function(e) {
-           alert("An error occured: " + e.message);
-       };
+    _mainCamera: null,
+    _cams: [],
+    getPicture: function(success, fail, cameraOptions) {
+        var dataList = [];
+        dataList[0] = "type:camera";
+
+        var appcontrolobject = Osp.App.AppManager.findAppControl("osp.appcontrol.provider.camera", "osp.appcontrol.operation.capture");
+
+        if(appcontrolobject) {
+            appcontrolobject.start(dataList, function(cbtype, appControlId, operationId, resultList) {
+                var i;
+                if(cbtype === "onAppControlCompleted") {
+                    if(resultList.length > 1 && resultList[1]) {
+                        success(resultList[1]);
+                    }
+                } else {
+                    var error = {message: "An error occured while capturing image", code: 0};
+                    fail(error);
+                }
+            });
+        }
+    },
+    showPreview: function(nodeId) {
+        var self = this;
+        var onCreatePreviewNodeSuccess = function(previewObject) {
+            var previewDiv = document.getElementById(nodeId);
+            previewDiv.appendChild(previewObject);
+            previewObject.style.visibility = "visible";
+        };
+        var error = function(e) {
+            alert("An error occured: " + e.message);
+        };
+
+        var success = function(cams) {
+            if (cams.length > 0) {
+             self._cams = cams;
+                self._mainCamera = cams[0];
+                self._mainCamera.createPreviewNode(onCreatePreviewNodeSuccess, error);
+                return;
+            }
+            alert("Sorry, no cameras available.");
+        };
+        if(nodeId) {
+            deviceapis.camera.getCameras(success, error);
+        } else {
+            console.log("camera::getPreview: must provide a nodeId");
+        }
+    },
+    hidePreview: function(nodeId) {
+        var preview = document.getElementById(nodeId);
+        if(preview.childNodes[0]) {
+            preview.removeChild(preview.childNodes[0]);
+        }
+    }
 
-       var success = function(cams) {
-           if (cams.length > 0) {
-            self._cams = cams;
-               self._mainCamera = cams[0];
-               self._mainCamera.createPreviewNode(onCreatePreviewNodeSuccess, error);
-               return;
-           }
-           alert("Sorry, no cameras available.");
-       };
-       deviceapis.camera.getCameras(success, error);
-      }
 };