cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [4/11] spec commit: [CB-2213] Added a new test for readAsDataURL.
Date Tue, 12 Feb 2013 03:15:59 GMT
[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/ba2711e2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/ba2711e2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/ba2711e2

Branch: refs/heads/master
Commit: ba2711e229a3c5a72bd0c2d998d9726069cba61d
Parents: d27c80d
Author: Max Woghiren <max.woghiren@gmail.com>
Authored: Wed Jan 16 11:45:44 2013 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Feb 11 21:18:02 2013 -0500

----------------------------------------------------------------------
 camera/index.html |   44 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 40 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/ba2711e2/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index 7e98d39..4462a21 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -104,12 +104,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.";
-        }
+            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:
" + e;
+        };
         navigator.camera.getPicture(
             function(data) {
                 var fileEntry = new FileEntry('image_name.png', data);
@@ -195,6 +229,8 @@
     <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="getImageUsingFileUri(true);">Upload to jitsu with
file 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>
     <h3>input type=file</h3>
     <input type="file" onchange="testNativeFile(this)">
     <h3>capture=camera</h3>


Mime
View raw message