incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [9/11] js commit: Camera source image library
Date Fri, 20 Jul 2012 22:56:18 GMT
Camera source image library


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/0c458418
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/0c458418
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/0c458418

Branch: refs/heads/master
Commit: 0c4584181b9984c63ad766b9fc829be9cb649b68
Parents: ba3c88b
Author: Jesse <purplecabbage@gmail.com>
Authored: Mon Jul 16 03:40:03 2012 -0700
Committer: Jesse <purplecabbage@gmail.com>
Committed: Mon Jul 16 03:40:03 2012 -0700

----------------------------------------------------------------------
 lib/win8metro/exec.js |   88 ++++++++++++++++++++++++++++---------------
 1 files changed, 57 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0c458418/lib/win8metro/exec.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/exec.js b/lib/win8metro/exec.js
index d258d53..7e3ea1d 100644
--- a/lib/win8metro/exec.js
+++ b/lib/win8metro/exec.js
@@ -76,40 +76,64 @@ var NativeProxy = {
         // 9 saveToPhotoAlbum:false, 
         // 10 popoverOptions:null        
         "takePicture":function(win,lose,args) {
-            var dialog = new Windows.Media.Capture.CameraCaptureUI();
-            var allowCrop = !!args[7];
-            if(!allowCrop) {
-                dialog.photoSettings.allowCrop = false;
+            if(args[2] == Camera.PictureSourceType.CAMERA) {
+                // display the camera, and capture an image
+                var dialog = new Windows.Media.Capture.CameraCaptureUI();
+                var allowCrop = !!args[7];
+                if(!allowCrop) {
+                    dialog.photoSettings.allowCrop = false;
+                }
+                else {
+                    var aspectRatio = { width:args[3] > 0 ? args[3] : 1, height: args[4]
> 0 ? args[4] : 1};
+                    dialog.photoSettings.croppedAspectRatio = aspectRatio;
+                }
+                if(args[5] == Camera.EncodingType.JPEG) {
+                    dialog.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
+                }
+                else if (args[5] == Camera.EncodingType.PNG) {
+                    dialog.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.png;
+                }
+
+                dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(
+                    function(file){
+                        if(file) {
+                            console.log("got a file in success handler");
+                            if(args[1] == Camera.DestinationType.FILE_URI)
+                            {
+                                var imageBlobUrl = URL.createObjectURL(file);
+                                win(imageBlobUrl);
+                            }
+                        }
+                        else {
+                            console.log("success handler without file ...");
+                        }
+                    },
+                    function(err) {
+                        console.log("err in camerq");
+                    });
             }
             else {
-                var aspectRatio = { width:args[3] > 0 ? args[3] : 1, height: args[4] >
0 ? args[4] : 1};
-                dialog.photoSettings.croppedAspectRatio = aspectRatio;
-            }
-            if(args[5] == Camera.EncodingType.JPEG) {
-                dialog.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
-            }
-            else if (args[5] == Camera.EncodingType.PNG) {
-                dialog.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.png;
-            }
+                // grab from the photo library
+                var picker = new Windows.Storage.Pickers.FileOpenPicker();
+                picker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
+                picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
+
+                picker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
 
-            dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(
-                function(file){
-                    if(file) {
+                picker.pickSingleFileAsync().then(function (file) {
+                    if (file) {
                         console.log("got a file in success handler");
                         if(args[1] == Camera.DestinationType.FILE_URI)
                         {
                             var imageBlobUrl = URL.createObjectURL(file);
                             win(imageBlobUrl);
                         }
+                    } else {
+                        // cancelled ??
+                        console.log("success handler without file ...");
                     }
-                    else {
-                        console.log("success handler without file ...")
-                    }
-                },
-                function(err) {
-                    console.log("err in camerq")
                 });
-
+            }
 
         }
 
@@ -196,16 +220,14 @@ var NativeProxy = {
 
 module.exports = function(success, fail, service, action, args) {
 
-    var callbackId = service + cordova.callbackId++;
-    console.log("EXEC:" + service + " : " + action);
-
-    if (typeof success == "function" || typeof fail == "function")
-    {
-        cordova.callbacks[callbackId] = {success:success, fail:fail};
-    }
-
     if(NativeProxy[service] && NativeProxy[service][action]) {
 
+        var callbackId = service + cordova.callbackId++;
+        console.log("EXEC:" + service + " : " + action);
+
+        if (typeof success == "function" || typeof fail == "function") {
+            cordova.callbacks[callbackId] = {success:success, fail:fail};
+        }
         // pass it on to Notify
         try {
             NativeProxy[service][action](success, fail, args);
@@ -214,6 +236,10 @@ module.exports = function(success, fail, service, action, args) {
             console.log("Exception calling native with command :: " + service + " :: " +
action  + " ::exception=" + e);
         }
     }
+    else
+    {
+        if(fail) { fail("Missing Command Error"); };
+    }
 
 };
 


Mime
View raw message