You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/17 16:00:30 UTC
[2/3] spec commit: [CB-2213] Added a new test for readAsDataURL.
[CB-2213] Added a new test for readAsDataURL.
This test uses a FileEntry created using a native URI.
Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/485a9ef9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/485a9ef9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/485a9ef9
Branch: refs/heads/native-uri
Commit: 485a9ef9317a088ada77773b74cf31222f7a9437
Parents: 0c97fb3
Author: Max Woghiren <ma...@gmail.com>
Authored: Wed Jan 16 11:45:44 2013 -0500
Committer: Max Woghiren <ma...@gmail.com>
Committed: Wed Jan 16 13:17:46 2013 -0500
----------------------------------------------------------------------
camera/index.html | 61 +++++++++++++++++++++++++++++++++++++----------
1 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/485a9ef9/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index aa44085..969272b 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -27,25 +27,25 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
<title>Cordova Mobile Spec</title>
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova.js"></script>
+ <script type="text/javascript" charset="utf-8" src="../cordova.js"></script>
+
-
<script type="text/javascript" charset="utf-8">
var deviceReady = false;
//-------------------------------------------------------------------------
- // Camera
+ // Camera
//-------------------------------------------------------------------------
/**
* Capture picture
*/
function getPicture() {
-
- //navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
+
+ //navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
// destinationType: Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.CAMERA });
-
+
navigator.camera.getPicture(
function(data) {
var img = document.getElementById('camera_image');
@@ -89,12 +89,46 @@
*/
function getImageInfoUsingNativeUri() {
var onFileReceived = function(file) {
- document.getElementById('camera_status').innerHTML = "Success; fullPath: " + file.fullPath + ", name: " + file.name + ", type: " + file.type + ", size: " + file.size + ", date: " + file.lastModifiedDate;
- }
+ var img = document.getElementById('camera_image');
+ img.style.visibility = "hidden";
+ document.getElementById('camera_status').innerHTML = "Success; fullPath = " + file.fullPath + "; name = " + file.name + "; type = " + file.type + "; size = " + file.size + "; date = " + file.lastModifiedDate;
+ };
+ var onError = function(e) {
+ console.log("Error getting picture: " + e);
+ document.getElementById('camera_status').innerHTML = "Error getting picture: " + e;
+ };
+ navigator.camera.getPicture(
+ function(data) {
+ var fileEntry = new FileEntry('image_name.png', data);
+ var file = fileEntry.file(onFileReceived, onError);
+ },
+ onError,
+ { quality: 50, destinationType:
+ Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
+ };
+
+ /**
+ * Select image from library using a NATIVE_URI destination type
+ */
+ function getImageUsingNativeUri() {
+ var onFileReceived = function(file) {
+ var reader = new FileReader();
+ reader.onload = function(evt) {
+ var img = document.getElementById('camera_image');
+ img.style.visibility = "visible";
+ img.style.display = "block";
+ img.src = evt.target.result;
+ document.getElementById('camera_status').innerHTML = "Success";
+ };
+ reader.onerror = function(evt) {
+ onError(evt.target.error.code);
+ };
+ reader.readAsDataURL(file);
+ };
var onError = function(e) {
console.log("Error getting picture: " + e);
- document.getElementById('camera_status').innerHTML = "Error getting picture.";
- }
+ document.getElementById('camera_status').innerHTML = "Error getting picture: " + e;
+ };
navigator.camera.getPicture(
function(data) {
var fileEntry = new FileEntry('image_name.png', data);
@@ -124,7 +158,7 @@
</head>
<body onload="init();" id="stage" class="theme">
-
+
<h1>Camera</h1>
<div id="info">
<b>Status:</b> <span id="camera_status"></span><br>
@@ -133,7 +167,8 @@
<h2>Action</h2>
<div class="btn large" onclick="getPicture();">Take Picture</div>
<div class="btn large" onclick="getImageUsingFileUri();">Select Image Using File URI</div>
- <div class="btn large" onclick="getImageInfoUsingNativeUri();">Select Image Using Native URI</div>
+ <div class="btn large" onclick="getImageInfoUsingNativeUri();">Native URI: Select Image, Show Info</div>
+ <div class="btn large" onclick="getImageUsingNativeUri();">Native URI: Select Image, Show Image</div>
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
</body>
-</html>
+</html>