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/04/28 02:27:55 UTC

[12/17] bada-wac commit: adding image/video capture support

adding image/video capture support


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

Branch: refs/heads/master
Commit: cb955492c283f307fc437d948293b62561740ef6
Parents: 06e81dd
Author: Anis Kadri <an...@gmail.com>
Authored: Tue Apr 10 18:39:27 2012 -0700
Committer: Anis Kadri <an...@gmail.com>
Committed: Tue Apr 10 18:39:27 2012 -0700

----------------------------------------------------------------------
 Res/index.html    |   24 +++++++++++++++++++-
 Res/js/capture.js |   53 ++++++++++++++++++++++++++++++++++++++++++++++++
 Res/js/sample.js  |   32 +++++++++++++++++++++++++++-
 3 files changed, 105 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/cb955492/Res/index.html
----------------------------------------------------------------------
diff --git a/Res/index.html b/Res/index.html
index d75caae..adc420f 100644
--- a/Res/index.html
+++ b/Res/index.html
@@ -16,6 +16,17 @@ button.btn {
 			border-color: #696 #363 #363 #696;
 			/* filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#ffffffff',EndColorStr='#ffeeddaa'); */ 
 		  } 
+		  
+		  button.btn2 {
+			color:#050;
+			font: bold 24px 'trebuchet ms',helvetica,sans-serif;
+			background-color:#fed;
+			width: 200px;
+			height: 100px;
+			border: 1px solid;
+			border-color: #696 #363 #363 #696;
+			/* filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#ffffffff',EndColorStr='#ffeeddaa'); */ 
+		  } 
 </style>
 <script type="text/javascript" src="osp://webapp/js/webapp_core.js"> </script>
 <script type="text/javascript" src="osp://webapp/js/webapp_ui.js"> </script>
@@ -101,12 +112,21 @@ button.btn {
 		<li>
 			<h3>Camera</h3>
 			<div>
-				<button type="button" class="btn" onclick="getCameraPreview();">Camera</button>
+				<button type="button" class="btn" onclick="cameraPreview();">cameraPreview</button>
+			</div>
+			<div id="cameraControls" style="display:none;">
+				<span>
+					<button type="button" class="btn2" onclick="startVideoCapture();">startVideoCapture</button>
+					<button type="button" class="btn2" onclick="stopVideoCapture();">stopVideoCapture</button>
+				</span>
+				<div>
+					<button type="button" class="btn" onclick="captureImage();">captureImage</button>
+				</div>
 			</div>
 			<div id="preview"></div>
 		</li>
 	</ul>
-<script type="text/javascript" src="./js/camera.js"></script>
+<script type="text/javascript" src="./js/capture.js"></script>
 <script type="text/javascript" src="./js/notification.js"></script>
 <script type="text/javascript" src="./js/connection.js"></script>
 <script type="text/javascript" src="./js/accelerometer.js"></script>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/cb955492/Res/js/capture.js
----------------------------------------------------------------------
diff --git a/Res/js/capture.js b/Res/js/capture.js
new file mode 100644
index 0000000..4ef19b1
--- /dev/null
+++ b/Res/js/capture.js
@@ -0,0 +1,53 @@
+navigator.camera = {
+		_mainCamera: null,
+		_cams: [],
+		getPicture: function(cameraSuccess, cameraFailure, cameraOptions) {
+			// TODO
+		},
+		getPreview: function() {
+			var self = this;
+			var onCreatePreviewNodeSuccess = function(previewObject) {
+			    var previewDiv = document.getElementById("preview");
+			    previewId = previewObject.id;
+			    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.");
+			};
+			deviceapis.camera.getCameras(success, error);
+		}
+};
+
+navigator.capture = {
+		captureAudio: function() {
+			console.log("navigator.capture.captureAudio unsupported!");
+		},
+		captureVideo: function(success, fail, options) {
+	        var camera = navigator.camera._mainCamera;
+			camera.startVideoCapture(success, fail, options);
+	        if(options.duration) {
+	        	Osp.Core.Function.delay(camera.stopVideoCapture, options.duration, camera);
+	        }
+		},
+		stopVideoCapture: function() {
+			navigator.camera._mainCamera.stopVideoCapture();
+		},
+		captureImage: function(success, fail, options) {
+			try {
+				navigator.camera._mainCamera.captureImage(success, fail, options);
+			} catch(exp) {
+				alert("Exception :[" + exp.code + "] " + exp.message);
+			}
+		}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/cb955492/Res/js/sample.js
----------------------------------------------------------------------
diff --git a/Res/js/sample.js b/Res/js/sample.js
index a0e58f3..e44b187 100644
--- a/Res/js/sample.js
+++ b/Res/js/sample.js
@@ -200,6 +200,34 @@ function notificationLightOn() {
 	navigator.notification.lightOn(2000);
 }
 
-function getCameraPreview() {
-	navigator.camera.getPreview();
+function cameraPreview() {
+    var preview = document.getElementById("preview");
+    if(preview.childNodes[0]) {
+    	preview.removeChild(preview.childNodes[0]);
+    	document.getElementById("cameraControls").style.display = "none";
+    } else {
+    	navigator.camera.getPreview();
+    	document.getElementById("cameraControls").style.display = "";
+    }
+}
+
+function startVideoCapture() {
+	var success = function(filename) {console.log(filename); };
+	var fail = function(error) { console.log("ERROR "+JSON.stringify(error)); };
+	navigator.capture.captureVideo(success, fail, {duration: 5000, destinationFilename: "videos/a.3gp"});
+}
+
+function stopVideoCapture() {
+	navigator.capture.stopVideoCapture();
+}
+
+function captureImage() {
+	var success = function(filename) {
+		console.log(filename);
+	};
+	var fail = function(error) {
+		console.log("ERROR"+JSON.stringify(error));
+	};
+	var options = { destinationFilename: "images/cam01.jpg", highRes: false};
+	navigator.capture.captureImage(success, fail, options);
 }
\ No newline at end of file