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/02/12 04:15:59 UTC

[1/11] spec commit: [CB-2213] Added tests for copyTo and moveTo.

[CB-2213] Added tests for copyTo and moveTo.


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/0306175e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/0306175e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/0306175e

Branch: refs/heads/master
Commit: 0306175e566a84482dbe119e1c3bf75413821d24
Parents: a8a137e
Author: Max Woghiren <ma...@gmail.com>
Authored: Thu Jan 17 14:12:00 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Feb 11 21:18:02 2013 -0500

----------------------------------------------------------------------
 camera/index.html |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/0306175e/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index 53bd4c5..9bf9071 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -224,6 +224,46 @@
         reader.readAsDataURL(file);
     }
 
+    function copyImageUsingNativeUri() {
+        var onFileMoved = function(fileEntry) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.moveTo <b>error</b>: moveTo succeeded when it should fail<br />";
+        };
+
+        var onFileMoveError = function(e) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.moveTo <b>success</b> (failed as expected): " + e.code + "<br />"
+        };
+
+        var onFileCopied = function(fileEntry) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.copyTo <b>success</b>: file copied to " + fileEntry.fullPath + "<br />";
+        };
+
+        var onFileCopyError = function(e) {
+            document.getElementById('camera_status').innerHTML += "FileEntry.copyTo <b>error</b>: " + e.code + "<br />";
+        };
+
+        var onError = function(e) {
+            console.log("Error getting picture: " + e.code);
+            document.getElementById('camera_status').innerHTML += "<b>Error</b> getting picture: " + e.code + "<br />";
+        };
+
+        var onFileSystemReceived = function(fileSystem) {
+            navigator.camera.getPicture(
+                function(data) {
+                    var fileEntry = new FileEntry('image_name.png', data);
+                    var destDirEntry = fileSystem.root;
+
+                    // Test FileEntry API here.
+                    fileEntry.moveTo(destDirEntry, 'moved_file.png', onFileMoved, onFileMoveError);
+                    fileEntry.copyTo(destDirEntry, 'copied_file.png', onFileCopied, onFileCopyError);
+                },
+                onError,
+                { quality: 50, destinationType:
+                Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
+        };
+
+        window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null);
+    };
+
     /**
      * Function called when page has finished loading.
      */
@@ -257,6 +297,7 @@
     <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>
     <div class="btn large" onclick="getImageUsingNativeUri();">Select Image Using Native URI</div>
+    <div class="btn large" onclick="copyImageUsingNativeUri();">Copy Image Using Native URI</div>
     <h3>input type=file</h3>
     <input type="file" onchange="testNativeFile(this)">
     <h3>capture=camera</h3>