You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/04/10 01:39:53 UTC

[1/8] cordova-plugin-camera git commit: CB-8706 remove unnecessary capabilities from xml

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/old-ID 03a720808 -> 304599d80


CB-8706 remove unnecessary capabilities from xml


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/b8a70021
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/b8a70021
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/b8a70021

Branch: refs/heads/old-ID
Commit: b8a700215af0f5b217c91c6d5380da716d09dabd
Parents: 081aec5
Author: Murat Sutunc <mu...@microsoft.com>
Authored: Mon Feb 16 15:32:10 2015 -0800
Committer: Murat Sutunc <mu...@microsoft.com>
Committed: Wed Mar 18 10:58:37 2015 -0700

----------------------------------------------------------------------
 plugin.xml | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b8a70021/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8a2cf78..637b48d 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -241,16 +241,7 @@
 
     <!-- windows -->
     <platform name="windows">
-        <config-file target="package.windows.appxmanifest" parent="/Package/Capabilities">
-            <Capability Name="picturesLibrary" />
-            <DeviceCapability Name="webcam" />
-        </config-file>
-        <config-file target="package.windows80.appxmanifest" parent="/Package/Capabilities">
-            <Capability Name="picturesLibrary" />
-            <DeviceCapability Name="webcam" />
-        </config-file>
-        <config-file target="package.phone.appxmanifest" parent="/Package/Capabilities">
-            <Capability Name="picturesLibrary" />
+        <config-file target="package.appxmanifest" parent="/Package/Capabilities">
             <DeviceCapability Name="webcam" />
         </config-file>
         <js-module src="www/CameraPopoverHandle.js" name="CameraPopoverHandle">


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[6/8] cordova-plugin-camera git commit: CB-8706, CB-8707 saveToPhotoAlbum improvements and some refactoring

Posted by st...@apache.org.
CB-8706, CB-8707 saveToPhotoAlbum improvements and some refactoring

- On Windows we should use filePicker instead of programmatically
accessing user libs. This way the app doesnt have to depend on extra
capabilities.

- Some refactoring to help on navigating code easier

This closes #78


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/3927735d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/3927735d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/3927735d

Branch: refs/heads/old-ID
Commit: 3927735d09bbdfac0a20d9bfb0e78b55af836200
Parents: d1dfc1e 9e11ab4
Author: Vladimir Kotikov <an...@ya.ru>
Authored: Tue Apr 7 21:48:00 2015 +0300
Committer: Vladimir Kotikov <an...@ya.ru>
Committed: Tue Apr 7 21:48:00 2015 +0300

----------------------------------------------------------------------
 plugin.xml                 |  11 +-
 src/windows/CameraProxy.js | 769 ++++++++++++++++++++++------------------
 2 files changed, 422 insertions(+), 358 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/3927735d/plugin.xml
----------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[3/8] cordova-plugin-camera git commit: CB-8707 refactoring windows code to improve readability

Posted by st...@apache.org.
CB-8707 refactoring windows code to improve readability


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/29c9ea38
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/29c9ea38
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/29c9ea38

Branch: refs/heads/old-ID
Commit: 29c9ea387d24c2a4d5558a3af8f9de219c98bb9f
Parents: 5ef04e5
Author: Murat Sutunc <mu...@microsoft.com>
Authored: Tue Mar 17 17:16:38 2015 -0700
Committer: Murat Sutunc <mu...@microsoft.com>
Committed: Wed Mar 18 11:03:01 2015 -0700

----------------------------------------------------------------------
 src/windows/CameraProxy.js | 825 ++++++++++++++++++++--------------------
 1 file changed, 413 insertions(+), 412 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/29c9ea38/src/windows/CameraProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js
index d8b8e9e..aa2e391 100644
--- a/src/windows/CameraProxy.js
+++ b/src/windows/CameraProxy.js
@@ -19,11 +19,11 @@
  *
 */
 
-/*global Windows:true, URL:true */
+/*jshint unused:true, undef:true, browser:true */
+/*global Windows:true, URL:true, module:true, require:true */
 
 
-    var cordova = require('cordova'),
-        Camera = require('./Camera');
+var Camera = require('./Camera');
 
 module.exports = {
 
@@ -43,467 +43,468 @@ module.exports = {
     // 11 cameraDirection:0
 
     takePicture: function (successCallback, errorCallback, args) {
-        var encodingType = args[5];
-        var targetWidth = args[3];
-        var targetHeight = args[4];
         var sourceType = args[2];
-        var destinationType = args[1];
-        var mediaType = args[6];
-        var allowCrop = !!args[7];
-        var saveToPhotoAlbum = args[9];
-        var cameraDirection = args[11];
-
-        // resize method :)
-        var resizeImage = function (file) {
-            var tempPhotoFileName = "";
-            if (encodingType == Camera.EncodingType.PNG) {
-                tempPhotoFileName = "camera_cordova_temp_return.png";
-            } else {
-                tempPhotoFileName = "camera_cordova_temp_return.jpg";
-            }
-
-            var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
-            file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
-                Windows.Storage.FileIO.readBufferAsync(storageFile).then(function(buffer) {
-                    var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                    var imageData = "data:" + file.contentType + ";base64," + strBase64;
-                    var image = new Image();
-                    image.src = imageData;
-                    image.onload = function() {
-                        var imageWidth = targetWidth,
-                            imageHeight = targetHeight;
-                        var canvas = document.createElement('canvas');
-
-                        canvas.width = imageWidth;
-                        canvas.height = imageHeight;
 
-                        canvas.getContext("2d").drawImage(this, 0, 0, imageWidth, imageHeight);
-
-                        var fileContent = canvas.toDataURL(file.contentType).split(',')[1];
-
-                        var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+        if (sourceType != Camera.PictureSourceType.CAMERA) {
+            takePictureFromFile(successCallback, errorCallback, args);
+        } else {
+            takePictureFromCamera(successCallback, errorCallback, args);
+        }
+    }
+};
 
-                        storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (storagefile) {
-                            var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
-                            Windows.Storage.FileIO.writeBufferAsync(storagefile, content).then(function () {
-                                successCallback("ms-appdata:///local/" + storagefile.name);
-                            }, function () {
-                                errorCallback("Resize picture error.");
-                            });
-                        });
-                    };
-                });
-            }, function () {
-                errorCallback("Can't access localStorage folder");
-            });
 
-        };
+// Resize method
+function resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType) {
+    var tempPhotoFileName = "";
+    if (encodingType == Camera.EncodingType.PNG) {
+        tempPhotoFileName = "camera_cordova_temp_return.png";
+    } else {
+        tempPhotoFileName = "camera_cordova_temp_return.jpg";
+    }
 
-        // because of asynchronous method, so let the successCallback be called in it.
-        var resizeImageBase64 = function (file) {
+    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+    file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting)
+        .then(function (storageFile) { return Windows.Storage.FileIO.readBufferAsync(storageFile); })
+        .then(function(buffer) {
+            var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+            var imageData = "data:" + file.contentType + ";base64," + strBase64;
+            var image = new Image();
+            image.src = imageData;
+            image.onload = function() {
+                var imageWidth = targetWidth,
+                    imageHeight = targetHeight;
+                var canvas = document.createElement('canvas');
+                var storageFileName;
+
+                canvas.width = imageWidth;
+                canvas.height = imageHeight;
+
+                canvas.getContext("2d").drawImage(this, 0, 0, imageWidth, imageHeight);
+
+                var fileContent = canvas.toDataURL(file.contentType).split(',')[1];
+
+                var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+
+                storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName)
+                    .then(function (storagefile) {
+                        var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
+                        storageFileName = storagefile.name;
+                        return Windows.Storage.FileIO.writeBufferAsync(storagefile, content);
+                    })
+                    .done(function () {
+                        successCallback("ms-appdata:///local/" + storageFileName);
+                    }, errorCallback);
+            };
+        })
+        .done(null, function(err) {
+            errorCallback(err);
+        }
+    );
+}
 
-            Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
-                var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                var imageData = "data:" + file.contentType + ";base64," + strBase64;
+// Because of asynchronous method, so let the successCallback be called in it.
+function resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight) {
+    Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
+        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+        var imageData = "data:" + file.contentType + ";base64," + strBase64;
 
-                var image = new Image();
-                image.src = imageData;
+        var image = new Image();
+        image.src = imageData;
 
-                image.onload = function() {
-                    var imageWidth = targetWidth,
-                        imageHeight = targetHeight;
-                    var canvas = document.createElement('canvas');
+        image.onload = function() {
+            var imageWidth = targetWidth,
+                imageHeight = targetHeight;
+            var canvas = document.createElement('canvas');
 
-                    canvas.width = imageWidth;
-                    canvas.height = imageHeight;
+            canvas.width = imageWidth;
+            canvas.height = imageHeight;
 
-                    var ctx = canvas.getContext("2d");
-                    ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
+            var ctx = canvas.getContext("2d");
+            ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
 
-                    // The resized file ready for upload
-                    var finalFile = canvas.toDataURL(file.contentType);
+            // The resized file ready for upload
+            var finalFile = canvas.toDataURL(file.contentType);
 
-                    // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
-                    var arr = finalFile.split(",");
-                    var newStr = finalFile.substr(arr[0].length + 1);
-                    successCallback(newStr);
-                };
-            });
+            // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
+            var arr = finalFile.split(",");
+            var newStr = finalFile.substr(arr[0].length + 1);
+            successCallback(newStr);
         };
+    }, function(err) { errorCallback(err); });
+}
+
+function takePictureFromFile(successCallback, errorCallback, mediaType, destinationType, targetWidth, targetHeight, encodingType) {
+    // TODO: Add WP8.1 support
+    // WP8.1 doesn't allow to use of pickSingleFileAsync method
+    // see http://msdn.microsoft.com/en-us/library/windows/apps/br207852.aspx for details
+    // replacement of pickSingleFileAsync - pickSingleFileAndContinue method
+    // will take application to suspended state and this require additional logic to wake application up
+    if (navigator.appVersion.indexOf('Windows Phone 8.1') >= 0 ) {
+        errorCallback('Not supported');
+        return;
+    }
 
-        if (sourceType != Camera.PictureSourceType.CAMERA) {
+    var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
+    fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
+    if (mediaType == Camera.MediaType.PICTURE) {
+        fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
+    }
+    else if (mediaType == Camera.MediaType.VIDEO) {
+        fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov", ".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
+    }
+    else {
+        fileOpenPicker.fileTypeFilter.replaceAll(["*"]);
+    }
 
-            // TODO: Add WP8.1 support
-            // WP8.1 doesn't allow to use of pickSingleFileAsync method
-            // see http://msdn.microsoft.com/en-us/library/windows/apps/br207852.aspx for details
-            // replacement of pickSingleFileAsync - pickSingleFileAndContinue method
-            // will take application to suspended state and this require additional logic to wake application up
-            if (navigator.appVersion.indexOf('Windows Phone 8.1') >= 0 ) {
-                errorCallback('Not supported');
-                return;
-            }
+    fileOpenPicker.pickSingleFileAsync().done(function (file) {
+        if (file) {
+            if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
+                if (targetHeight > 0 && targetWidth > 0) {
+                    resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
+                }
+                else {
+                    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+                    file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
+                        successCallback(URL.createObjectURL(storageFile));
+                    }, function () {
+                        errorCallback("Can't access localStorage folder.");
+                    });
 
-            var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
-            fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
-            if (mediaType == Camera.MediaType.PICTURE) {
-                fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
-            }
-            else if (mediaType == Camera.MediaType.VIDEO) {
-                fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov", ".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
+                }
             }
             else {
-                fileOpenPicker.fileTypeFilter.replaceAll(["*"]);
-            }
-
-            fileOpenPicker.pickSingleFileAsync().done(function (file) {
-                if (file) {
-                    if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
-                        if (targetHeight > 0 && targetWidth > 0) {
-                            resizeImage(file);
-                        }
-                        else {
-
-                            var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
-                            file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
-                                successCallback(URL.createObjectURL(storageFile));
-                            }, function () {
-                                errorCallback("Can't access localStorage folder.");
-                            });
-
-                        }
-                    }
-                    else {
-                        if (targetHeight > 0 && targetWidth > 0) {
-                            resizeImageBase64(file);
-                        } else {
-                            Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
-                                var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                                successCallback(strBase64);
-                            });
-                        }
-
-                    }
-
+                if (targetHeight > 0 && targetWidth > 0) {
+                    resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
                 } else {
-                    errorCallback("User didn't choose a file.");
+                    Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
+                        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+                        successCallback(strBase64);
+                    }, errorCallback);
                 }
-            }, function () {
-                errorCallback("User didn't choose a file.");
-            });
+            }
         } else {
+            errorCallback("User didn't choose a file.");
+        }
+    }, function () {
+        errorCallback("User didn't choose a file.");
+    });
+}
+
+function takePictureFromCamera(successCallback, errorCallback, args) {
+    // Check if necessary API available
+    if (!Windows.Media.Capture.CameraCaptureUI) {
+        takePictureFromCameraWP(successCallback, errorCallback, args);
+    } else {
+        takePictureFromCameraWindows(successCallback, errorCallback, args);
+    }
+}
+
+function takePictureFromCameraWP(successCallback, errorCallback, args) {
+    // We are running on WP8.1 which lacks CameraCaptureUI class
+    // so we need to use MediaCapture class instead and implement custom UI for camera
+    var destinationType = args[1],
+        targetWidth = args[3],
+        targetHeight = args[4],
+        encodingType = args[5],
+        saveToPhotoAlbum = args[9],
+        cameraDirection = args[11],
+        capturePreview = null,
+        captureCancelButton = null,
+        capture = null,
+        captureSettings = null,
+        CaptureNS = Windows.Media.Capture;
+
+    var createCameraUI = function () {
+        // Create fullscreen preview
+        capturePreview = document.createElement("video");
+
+        // z-order style element for capturePreview and captureCancelButton elts
+        // is necessary to avoid overriding by another page elements, -1 sometimes is not enough
+        capturePreview.style.cssText = "position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-order: 999";
+
+        // Create cancel button
+        captureCancelButton = document.createElement("button");
+        captureCancelButton.innerText = "Cancel";
+        captureCancelButton.style.cssText = "position: fixed; right: 0; bottom: 0; display: block; margin: 20px; z-order: 1000";
+
+        capture = new CaptureNS.MediaCapture();
+
+        captureSettings = new CaptureNS.MediaCaptureInitializationSettings();
+        captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video;
+    };
+
+    var startCameraPreview = function () {
+        // Search for available camera devices
+        // This is necessary to detect which camera (front or back) we should use
+        var expectedPanel = cameraDirection === 1 ? Windows.Devices.Enumeration.Panel.front : Windows.Devices.Enumeration.Panel.back;
+        Windows.Devices.Enumeration.DeviceInformation.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture)
+        .done(function (devices) {
+            if (devices.length > 0) {
+                devices.forEach(function(currDev) {
+                    if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == expectedPanel) {
+                        captureSettings.videoDeviceId = currDev.id;
+                    }
+                });
 
-            var CaptureNS = Windows.Media.Capture;
-
-            // Check if necessary API available
-            if (!CaptureNS.CameraCaptureUI) {
-                // We are running on WP8.1 which lacks CameraCaptureUI class
-                // so we need to use MediaCapture class instead and implement custom UI for camera
-
-                var capturePreview = null,
-                    captureCancelButton = null,
-                    capture = null,
-                    captureSettings = null;
-
-                var createCameraUI = function () {
-
-                    // Create fullscreen preview
-                    capturePreview = document.createElement("video");
+                capture.initializeAsync(captureSettings).done(function () {
+                    // This is necessary since WP8.1 MediaCapture outputs video stream rotated 90 degrees CCW
+                    // TODO: This can be not consistent across devices, need additional testing on various devices
+                    capture.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
+                    // msdn.microsoft.com/en-us/library/windows/apps/hh452807.aspx
+                    capturePreview.msZoom = true;
+                    capturePreview.src = URL.createObjectURL(capture);
+                    capturePreview.play();
+
+                    // Insert preview frame and controls into page
+                    document.body.appendChild(capturePreview);
+                    document.body.appendChild(captureCancelButton);
+
+                    // Bind events to controls
+                    capturePreview.addEventListener('click', captureAction);
+                    captureCancelButton.addEventListener('click', function () {
+                        destroyCameraPreview();
+                        errorCallback('Cancelled');
+                    }, false);
+                }, function (err) {
+                    destroyCameraPreview();
+                    errorCallback('Camera intitialization error ' + err);
+                });
+            } else {
+                destroyCameraPreview();
+                errorCallback('Camera not found');
+            }
+        }, errorCallback);
+    };
+
+    var destroyCameraPreview = function () {
+        capturePreview.pause();
+        capturePreview.src = null;
+        [capturePreview, captureCancelButton].forEach(function(elem) {
+            if (elem /* && elem in document.body.childNodes */) {
+                document.body.removeChild(elem);
+            }
+        });
+        if (capture) {
+            capture.stopRecordAsync();
+            capture = null;
+        }
+    };
 
-                    // z-order style element for capturePreview and captureCancelButton elts
-                    // is necessary to avoid overriding by another page elements, -1 sometimes is not enough
-                    capturePreview.style.cssText = "position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-order: 999";
+    var captureAction = function () {
 
-                    // Create cancel button
-                    captureCancelButton = document.createElement("button");
-                    captureCancelButton.innerText = "Cancel";
-                    captureCancelButton.style.cssText = "position: fixed; right: 0; bottom: 0; display: block; margin: 20px; z-order: 1000";
+        var encodingProperties,
+            fileName,
+            generateUniqueCollisionOption = Windows.Storage.CreationCollisionOption.generateUniqueName,
+            tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder,
+            capturedFile;
 
-                    capture = new CaptureNS.MediaCapture();
+        if (encodingType == Camera.EncodingType.PNG) {
+            fileName = 'photo.png';
+            encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createPng();
+        } else {
+            fileName = 'photo.jpg';
+            encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createJpeg();
+        }
 
-                    captureSettings = new CaptureNS.MediaCaptureInitializationSettings();
-                    captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video;
-                };
+        tempFolder.createFileAsync(fileName, generateUniqueCollisionOption)
+            .then(function(tempCapturedFile) {
+                capturedFile = tempCapturedFile;
+                return capture.capturePhotoToStorageFileAsync(encodingProperties, capturedFile);
+            })
+            .done(function() {
+                destroyCameraPreview();
 
-                var startCameraPreview = function () {
-
-                    // Search for available camera devices
-                    // This is necessary to detect which camera (front or back) we should use
-                    var expectedPanel = cameraDirection === 1 ? Windows.Devices.Enumeration.Panel.front : Windows.Devices.Enumeration.Panel.back;
-                    Windows.Devices.Enumeration.DeviceInformation.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture)
-                    .done(function (devices) {
-                        if (devices.length > 0) {
-                            devices.forEach(function(currDev) {
-                                if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == expectedPanel) {
-                                    captureSettings.videoDeviceId = currDev.id;
-                                }
-                            });
-
-                            capture.initializeAsync(captureSettings).done(function () {
-                                // This is necessary since WP8.1 MediaCapture outputs video stream rotated 90 degrees CCW
-                                // TODO: This can be not consistent across devices, need additional testing on various devices
-                                capture.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
-                                // msdn.microsoft.com/en-us/library/windows/apps/hh452807.aspx
-                                capturePreview.msZoom = true;
-                                capturePreview.src = URL.createObjectURL(capture);
-                                capturePreview.play();
-
-                                // Insert preview frame and controls into page
-                                document.body.appendChild(capturePreview);
-                                document.body.appendChild(captureCancelButton);
-
-                                // Bind events to controls
-                                capturePreview.addEventListener('click', captureAction);
-                                captureCancelButton.addEventListener('click', function () {
-                                    destroyCameraPreview();
-                                    errorCallback('Cancelled');
-                                }, false);
-                            }, function (err) {
-                                destroyCameraPreview();
-                                errorCallback('Camera intitialization error ' + err);
-                            });
+                // success callback for capture operation
+                var success = function(capturedfile) {
+                    if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
+                        if (targetHeight > 0 && targetWidth > 0) {
+                            resizeImage(successCallback, errorCallback, capturedFile, targetWidth, targetHeight, encodingType);
                         } else {
-                            destroyCameraPreview();
-                            errorCallback('Camera not found');
+                            capturedfile.copyAsync(Windows.Storage.ApplicationData.current.localFolder, capturedfile.name, generateUniqueCollisionOption).done(function(copiedfile) {
+                                successCallback("ms-appdata:///local/" + copiedfile.name);
+                            }, errorCallback);
                         }
-                    });
-                };
-
-                var destroyCameraPreview = function () {
-                    capturePreview.pause();
-                    capturePreview.src = null;
-                    [capturePreview, captureCancelButton].forEach(function(elem) {
-                        if (elem /* && elem in document.body.childNodes */) {
-                            document.body.removeChild(elem);
+                    } else {
+                        if (targetHeight > 0 && targetWidth > 0) {
+                            resizeImageBase64(successCallback, errorCallback, capturedfile, targetWidth, targetHeight);
+                        } else {
+                            Windows.Storage.FileIO.readBufferAsync(capturedfile).done(function(buffer) {
+                                var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+                                capturedfile.deleteAsync().done(function() {
+                                    successCallback(strBase64);
+                                }, function(err) {
+                                    errorCallback(err);
+                                });
+                            }, errorCallback);
                         }
-                    });
-                    if (capture) {
-                        capture.stopRecordAsync();
-                        capture = null;
                     }
                 };
 
-                var captureAction = function () {
-
-                    var encodingProperties,
-                        fileName,
-                        generateUniqueCollisionOption = Windows.Storage.CreationCollisionOption.generateUniqueName,
-                        tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder;
-
-                    if (encodingType == Camera.EncodingType.PNG) {
-                        fileName = 'photo.png';
-                        encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createPng();
-                    } else {
-                        fileName = 'photo.jpg';
-                        encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createJpeg();
-                    }
-
-                    tempFolder.createFileAsync(fileName, generateUniqueCollisionOption).done(function(capturedFile) {
-                        capture.capturePhotoToStorageFileAsync(encodingProperties, capturedFile).done(function() {
-
-                            destroyCameraPreview();
-
-                            // success callback for capture operation
-                            var success = function(capturedfile) {
-                                if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
-                                    if (targetHeight > 0 && targetWidth > 0) {
-                                        resizeImage(capturedfile);
-                                    } else {
-                                        capturedfile.copyAsync(Windows.Storage.ApplicationData.current.localFolder, capturedfile.name, generateUniqueCollisionOption).done(function(copiedfile) {
-                                            successCallback("ms-appdata:///local/" + copiedfile.name);
-                                        }, errorCallback);
-                                    }
-                                } else {
-                                    if (targetHeight > 0 && targetWidth > 0) {
-                                        resizeImageBase64(capturedfile);
-                                    } else {
-                                        Windows.Storage.FileIO.readBufferAsync(capturedfile).done(function(buffer) {
-                                            var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                                            capturedfile.deleteAsync().done(function() {
-                                                successCallback(strBase64);
-                                            }, function(err) {
-                                                console.error(err);
-                                                successCallback(strBase64);
-                                            });
-                                        }, errorCallback);
-                                    }
-                                }
-                            };
-
-                            if (saveToPhotoAlbum) {
-                                /*
-                                    Need to add and remove an event listener to catch activation state
-                                    Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
-                                    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
-                                */
-                                function cameraActivationHandler(eventArgs) {
-                                    if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
-                                        var file = eventArgs.file;
-                                        if (file) {
-                                            // Prevent updates to the remote version of the file until we're done
-                                            Windows.Storage.CachedFileManager.deferUpdates(file);
-                                            capturedFile.moveAndReplaceAsync(file)
-                                                .then(function() {
-                                                    // Let Windows know that we're finished changing the file so
-                                                    // the other app can update the remote version of the file.
-                                                    return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
-                                                })
-                                                .done(
-                                                    function(updateStatus) {
-                                                        if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
-                                                            success(capturedFile);
-                                                        } else {
-                                                            errorCallback();
-                                                        }
-                                                    }, errorCallback
-                                                );
-                                        } else {
-                                            errorCallback();
-                                        }
-                                        Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
-                                    }
-                                }
-
-                                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
-                                savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
-                                if (encodingType === Camera.EncodingType.PNG) {
-                                    savePicker.fileTypeChoices.insert("PNG", [".png"]);
-                                } else {
-                                    savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
-                                }
-                                savePicker.suggestedFileName = fileName;
-                                Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
-                                savePicker.pickSaveFileAndContinue();
+                if (saveToPhotoAlbum) {
+                    /*
+                        Need to add and remove an event listener to catch activation state
+                        Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
+                        https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
+                    */
+                    var cameraActivationHandler = function(eventArgs) {
+                        if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
+                            var file = eventArgs.file;
+                            if (file) {
+                                // Prevent updates to the remote version of the file until we're done
+                                Windows.Storage.CachedFileManager.deferUpdates(file);
+                                capturedFile.moveAndReplaceAsync(file)
+                                    .then(function() {
+                                        // Let Windows know that we're finished changing the file so
+                                        // the other app can update the remote version of the file.
+                                        return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                                    })
+                                    .done(function(updateStatus) {
+                                            if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                                success(capturedFile);
+                                            } else {
+                                                errorCallback();
+                                            }
+                                    }, errorCallback);
                             } else {
-                                success(capturedFile);
+                                errorCallback();
                             }
+                            Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
+                        }
+                    };
 
-
-                        }, function(err) {
-                            destroyCameraPreview();
-                            errorCallback(err);
-                        });
-                    }, function(err) {
-                        destroyCameraPreview();
-                        errorCallback(err);
-                    });
-                };
-
-                try {
-                    createCameraUI();
-                    startCameraPreview();
-                } catch (ex) {
-                    errorCallback(ex);
+                    var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+                    savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+                    if (encodingType === Camera.EncodingType.PNG) {
+                        savePicker.fileTypeChoices.insert("PNG", [".png"]);
+                    } else {
+                        savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+                    }
+                    savePicker.suggestedFileName = fileName;
+                    Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
+                    savePicker.pickSaveFileAndContinue();
+                } else {
+                    success(capturedFile);
                 }
+            }, function(err) {
+                    destroyCameraPreview();
+                    errorCallback(err);
+            });
+    };
 
-            } else {
+    try {
+        createCameraUI();
+        startCameraPreview();
+    } catch (ex) {
+        errorCallback(ex);
+    }
+}
+
+function takePictureFromCameraWindows(successCallback, errorCallback, args) {
+    var destinationType = args[1],
+        targetWidth = args[3],
+        targetHeight = args[4],
+        encodingType = args[5],
+        allowCrop = !!args[7],
+        saveToPhotoAlbum = args[9],
+        cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
+    cameraCaptureUI.photoSettings.allowCropping = allowCrop;
+
+    if (encodingType == Camera.EncodingType.PNG) {
+        cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.png;
+    } else {
+        cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
+    }
 
-                var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
-                cameraCaptureUI.photoSettings.allowCropping = allowCrop;
+    // decide which max pixels should be supported by targetWidth or targetHeight.
+    if (targetWidth >= 1280 || targetHeight >= 960) {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
+    } else if (targetWidth >= 1024 || targetHeight >= 768) {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
+    } else if (targetWidth >= 800 || targetHeight >= 600) {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
+    } else if (targetWidth >= 640 || targetHeight >= 480) {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.smallVga;
+    } else if (targetWidth >= 320 || targetHeight >= 240) {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.verySmallQvga;
+    } else {
+        cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
+    }
 
-                if (encodingType == Camera.EncodingType.PNG) {
-                    cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.png;
+    cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(function(picture) {
+        if (picture) {
+            // save to photo album successCallback
+            var success = function() {
+                if (destinationType == Camera.DestinationType.FILE_URI) {
+                    if (targetHeight > 0 && targetWidth > 0) {
+                        resizeImage(successCallback, errorCallback, picture, targetWidth, targetHeight, encodingType);
+                    } else {
+                        var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+                        picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function(storageFile) {
+                            successCallback("ms-appdata:///local/" + storageFile.name);
+                        }, errorCallback);
+                    }
                 } else {
-                    cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
+                    if (targetHeight > 0 && targetWidth > 0) {
+                        resizeImageBase64(successCallback, errorCallback, picture, targetWidth, targetHeight);
+                    } else {
+                        Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
+                            var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+                            successCallback(strBase64);
+                        }, errorCallback);
+                    }
                 }
+            };
 
-                // decide which max pixels should be supported by targetWidth or targetHeight.
-                if (targetWidth >= 1280 || targetHeight >= 960) {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
-                } else if (targetWidth >= 1024 || targetHeight >= 768) {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
-                } else if (targetWidth >= 800 || targetHeight >= 600) {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
-                } else if (targetWidth >= 640 || targetHeight >= 480) {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.smallVga;
-                } else if (targetWidth >= 320 || targetHeight >= 240) {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.verySmallQvga;
+            // save to photo album errorCallback
+            var fail = function() {
+                //errorCallback("FileError, code:" + fileError.code);
+                errorCallback("Save fail.");
+            };
+
+            if (saveToPhotoAlbum) {
+                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+
+                savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+                if (encodingType === Camera.EncodingType.PNG) {
+                    savePicker.fileTypeChoices.insert("PNG", [".png"]);
+                    savePicker.suggestedFileName = "photo.png";
                 } else {
-                    cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
+                    savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+                    savePicker.suggestedFileName = "photo.jpg";
                 }
 
-                cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function(picture) {
-                    if (picture) {
-                        // save to photo album successCallback
-                        var success = function() {
-                            if (destinationType == Camera.DestinationType.FILE_URI) {
-                                if (targetHeight > 0 && targetWidth > 0) {
-                                    resizeImage(picture);
-                                } else {
-
-                                    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
-                                    picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function(storageFile) {
-                                        successCallback("ms-appdata:///local/" + storageFile.name);
-                                    }, function() {
-                                        errorCallback("Can't access localStorage folder.");
-                                    });
-                                }
-                            } else {
-                                if (targetHeight > 0 && targetWidth > 0) {
-                                    resizeImageBase64(picture);
-                                } else {
-                                    Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
-                                        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                                        successCallback(strBase64);
-                                    });
-                                }
-                            }
-                        };
-                        // save to photo album errorCallback
-                        var fail = function() {
-                            //errorCallback("FileError, code:" + fileError.code);
-                            errorCallback("Save fail.");
-                        };
-
-                        if (saveToPhotoAlbum) {
-                            var savePicker = new Windows.Storage.Pickers.FileSavePicker();
-
-                            savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
-                            if (encodingType === Camera.EncodingType.PNG) {
-                                savePicker.fileTypeChoices.insert("PNG", [".png"]);
-                                savePicker.suggestedFileName = "photo.png";
-                            } else {
-                                savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
-                                savePicker.suggestedFileName = "photo.jpg";
-                            }
-
-                            savePicker.pickSaveFileAsync()
-                                .then(function(file) {
-                                    if (file) {
-                                        // Prevent updates to the remote version of the file until we're done
-                                        Windows.Storage.CachedFileManager.deferUpdates(file);
-                                        picture.moveAndReplaceAsync(file)
-                                            .then(function() {
-                                                // Let Windows know that we're finished changing the file so
-                                                // the other app can update the remote version of the file.
-                                                return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
-                                            })
-                                            .done(
-                                                function(updateStatus) {
-                                                    if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
-                                                        success();
-                                                    } else {
-                                                        fail();
-                                                    }
-                                                }, function() {
-                                                    fail();
-                                                }
-                                            );
+                savePicker.pickSaveFileAsync()
+                    .done(function(file) {
+                        if (file) {
+                            // Prevent updates to the remote version of the file until we're done
+                            Windows.Storage.CachedFileManager.deferUpdates(file);
+                            picture.moveAndReplaceAsync(file)
+                                .then(function() {
+                                    // Let Windows know that we're finished changing the file so
+                                    // the other app can update the remote version of the file.
+                                    return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                                })
+                                .done(function(updateStatus) {
+                                    if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                        success();
                                     } else {
                                         fail();
                                     }
-                                });
+                                }, fail);
                         } else {
-                            success();
+                            fail();
                         }
-                    } else {
-                        errorCallback("User didn't capture a photo.");
-                    }
-                }, function() {
-                    errorCallback("Fail to capture a photo.");
-                });
+                    }, fail);
+            } else {
+                success();
             }
+        } else {
+            errorCallback("User didn't capture a photo.");
         }
-    }
-};
+    }, function() {
+        errorCallback("Fail to capture a photo.");
+    });
+}
 
 require("cordova/exec/proxy").add("Camera",module.exports);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[7/8] cordova-plugin-camera git commit: Merge branch 'master' into old-ID

Posted by st...@apache.org.
Merge branch 'master' into old-ID


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/d82bad30
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/d82bad30
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/d82bad30

Branch: refs/heads/old-ID
Commit: d82bad305b4ce6f25ff798198815be462798ee9a
Parents: 03a7208 3927735
Author: Steve Gill <st...@gmail.com>
Authored: Thu Apr 9 14:39:47 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Thu Apr 9 14:39:47 2015 -0700

----------------------------------------------------------------------
 package.json               |   3 +
 plugin.xml                 |  11 +-
 src/windows/CameraProxy.js | 769 ++++++++++++++++++++++------------------
 tests/plugin.xml           |   2 +-
 4 files changed, 426 insertions(+), 359 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d82bad30/package.json
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d82bad30/plugin.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d82bad30/tests/plugin.xml
----------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[8/8] cordova-plugin-camera git commit: Revert "CB-8747 updated dependency, added peer dependency"

Posted by st...@apache.org.
Revert "CB-8747 updated dependency, added peer dependency"

This reverts commit d1dfc1e8ee9ac5bcaa329396eb003e4bcc432ddb.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/304599d8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/304599d8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/304599d8

Branch: refs/heads/old-ID
Commit: 304599d809c4b045797c34b5d4850f041ba558ac
Parents: d82bad3
Author: Steve Gill <st...@gmail.com>
Authored: Thu Apr 9 16:39:42 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Thu Apr 9 16:39:42 2015 -0700

----------------------------------------------------------------------
 package.json     | 3 ---
 tests/plugin.xml | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/304599d8/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index d93c758..8daeeae 100644
--- a/package.json
+++ b/package.json
@@ -38,9 +38,6 @@
     "cordova-browser",
     "cordova-windows"
   ],
-  "peerDependencies": {
-    "cordova-plugin-file": ">=1.0.1"
-  },
   "author": "Apache Software Foundation",
   "license": "Apache 2.0"
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/304599d8/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index 5a09248..44e44c0 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -26,7 +26,7 @@
     <name>Cordova Camera Plugin Tests</name>
     <license>Apache 2.0</license>
     
-    <dependency id="cordova-plugin-file" version=">=1.0.1" />
+    <dependency id="org.apache.cordova.file" version=">=1.0.1" />
 
     <js-module src="tests.js" name="tests">
     </js-module>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/8] cordova-plugin-camera git commit: CB-8706 use filePicker if saveToPhotoAlbum is true

Posted by st...@apache.org.
CB-8706 use filePicker if saveToPhotoAlbum is true


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/5ef04e55
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/5ef04e55
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/5ef04e55

Branch: refs/heads/old-ID
Commit: 5ef04e552c1b1ca3914fe56c83cc6956c11a81b8
Parents: b8a7002
Author: Murat Sutunc <mu...@microsoft.com>
Authored: Tue Feb 17 15:09:33 2015 -0800
Committer: Murat Sutunc <mu...@microsoft.com>
Committed: Wed Mar 18 10:59:18 2015 -0700

----------------------------------------------------------------------
 src/windows/CameraProxy.js | 90 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 79 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/5ef04e55/src/windows/CameraProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js
index 0924e5c..d8b8e9e 100644
--- a/src/windows/CameraProxy.js
+++ b/src/windows/CameraProxy.js
@@ -190,7 +190,6 @@ module.exports = {
             }, function () {
                 errorCallback("User didn't choose a file.");
             });
-
         } else {
 
             var CaptureNS = Windows.Media.Capture;
@@ -331,10 +330,49 @@ module.exports = {
                             };
 
                             if (saveToPhotoAlbum) {
-                                capturedFile.copyAsync(Windows.Storage.KnownFolders.picturesLibrary, capturedFile.name, generateUniqueCollisionOption)
-                                .done(function() {
-                                    success(capturedFile);
-                                }, errorCallback);
+                                /*
+                                    Need to add and remove an event listener to catch activation state
+                                    Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
+                                    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
+                                */
+                                function cameraActivationHandler(eventArgs) {
+                                    if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
+                                        var file = eventArgs.file;
+                                        if (file) {
+                                            // Prevent updates to the remote version of the file until we're done
+                                            Windows.Storage.CachedFileManager.deferUpdates(file);
+                                            capturedFile.moveAndReplaceAsync(file)
+                                                .then(function() {
+                                                    // Let Windows know that we're finished changing the file so
+                                                    // the other app can update the remote version of the file.
+                                                    return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                                                })
+                                                .done(
+                                                    function(updateStatus) {
+                                                        if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                                            success(capturedFile);
+                                                        } else {
+                                                            errorCallback();
+                                                        }
+                                                    }, errorCallback
+                                                );
+                                        } else {
+                                            errorCallback();
+                                        }
+                                        Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
+                                    }
+                                }
+
+                                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+                                savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+                                if (encodingType === Camera.EncodingType.PNG) {
+                                    savePicker.fileTypeChoices.insert("PNG", [".png"]);
+                                } else {
+                                    savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+                                }
+                                savePicker.suggestedFileName = fileName;
+                                Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
+                                savePicker.pickSaveFileAndContinue();
                             } else {
                                 success(capturedFile);
                             }
@@ -417,13 +455,43 @@ module.exports = {
                         };
 
                         if (saveToPhotoAlbum) {
-                            Windows.Storage.StorageFile.getFileFromPathAsync(picture.path).then(function(storageFile) {
-                                storageFile.copyAsync(Windows.Storage.KnownFolders.picturesLibrary, picture.name, Windows.Storage.NameCollisionOption.generateUniqueName).then(function(storageFile) {
-                                    success();
-                                }, function() {
-                                    fail();
+                            var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+
+                            savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+                            if (encodingType === Camera.EncodingType.PNG) {
+                                savePicker.fileTypeChoices.insert("PNG", [".png"]);
+                                savePicker.suggestedFileName = "photo.png";
+                            } else {
+                                savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+                                savePicker.suggestedFileName = "photo.jpg";
+                            }
+
+                            savePicker.pickSaveFileAsync()
+                                .then(function(file) {
+                                    if (file) {
+                                        // Prevent updates to the remote version of the file until we're done
+                                        Windows.Storage.CachedFileManager.deferUpdates(file);
+                                        picture.moveAndReplaceAsync(file)
+                                            .then(function() {
+                                                // Let Windows know that we're finished changing the file so
+                                                // the other app can update the remote version of the file.
+                                                return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                                            })
+                                            .done(
+                                                function(updateStatus) {
+                                                    if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                                        success();
+                                                    } else {
+                                                        fail();
+                                                    }
+                                                }, function() {
+                                                    fail();
+                                                }
+                                            );
+                                    } else {
+                                        fail();
+                                    }
                                 });
-                            });
                         } else {
                             success();
                         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[4/8] cordova-plugin-camera git commit: CB-8747 updated dependency, added peer dependency

Posted by st...@apache.org.
CB-8747 updated dependency, added peer dependency


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/d1dfc1e8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/d1dfc1e8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/d1dfc1e8

Branch: refs/heads/old-ID
Commit: d1dfc1e8ee9ac5bcaa329396eb003e4bcc432ddb
Parents: ee4ac0d
Author: Steve Gill <st...@gmail.com>
Authored: Wed Apr 1 23:01:47 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Wed Apr 1 23:01:47 2015 -0700

----------------------------------------------------------------------
 package.json     | 3 +++
 tests/plugin.xml | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d1dfc1e8/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index fb4a454..7cfee23 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,9 @@
     "cordova-browser",
     "cordova-windows"
   ],
+  "peerDependencies": {
+    "cordova-plugin-file": ">=1.0.1"
+  },
   "author": "Apache Software Foundation",
   "license": "Apache 2.0"
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/d1dfc1e8/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index 9be8509..a71d83e 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -26,7 +26,7 @@
     <name>Cordova Camera Plugin Tests</name>
     <license>Apache 2.0</license>
     
-    <dependency id="org.apache.cordova.file" version=">=1.0.1" />
+    <dependency id="cordova-plugin-file" version=">=1.0.1" />
 
     <js-module src="tests.js" name="tests">
     </js-module>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[5/8] cordova-plugin-camera git commit: CR fixes

Posted by st...@apache.org.
CR fixes


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/9e11ab4d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/9e11ab4d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/9e11ab4d

Branch: refs/heads/old-ID
Commit: 9e11ab4dfb03222b3da57632c6ae9fb6fee9f826
Parents: 29c9ea3
Author: Murat Sutunc <mu...@microsoft.com>
Authored: Fri Apr 3 11:08:00 2015 -0700
Committer: Murat Sutunc <mu...@microsoft.com>
Committed: Fri Apr 3 11:08:00 2015 -0700

----------------------------------------------------------------------
 src/windows/CameraProxy.js | 320 ++++++++++++++++++++--------------------
 1 file changed, 162 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/9e11ab4d/src/windows/CameraProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js
index aa2e391..3d4d24b 100644
--- a/src/windows/CameraProxy.js
+++ b/src/windows/CameraProxy.js
@@ -158,33 +158,33 @@ function takePictureFromFile(successCallback, errorCallback, mediaType, destinat
     }
 
     fileOpenPicker.pickSingleFileAsync().done(function (file) {
-        if (file) {
-            if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
-                if (targetHeight > 0 && targetWidth > 0) {
-                    resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
-                }
-                else {
-                    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
-                    file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
-                        successCallback(URL.createObjectURL(storageFile));
-                    }, function () {
-                        errorCallback("Can't access localStorage folder.");
-                    });
-
-                }
+        if (!file) {
+            errorCallback("User didn't choose a file.");
+            return;
+        }
+        if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
+            if (targetHeight > 0 && targetWidth > 0) {
+                resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
             }
             else {
-                if (targetHeight > 0 && targetWidth > 0) {
-                    resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
-                } else {
-                    Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
-                        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                        successCallback(strBase64);
-                    }, errorCallback);
-                }
+                var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+                file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
+                    successCallback(URL.createObjectURL(storageFile));
+                }, function () {
+                    errorCallback("Can't access localStorage folder.");
+                });
+
+            }
+        }
+        else {
+            if (targetHeight > 0 && targetWidth > 0) {
+                resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
+            } else {
+                Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
+                    var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+                    successCallback(strBase64);
+                }, errorCallback);
             }
-        } else {
-            errorCallback("User didn't choose a file.");
         }
     }, function () {
         errorCallback("User didn't choose a file.");
@@ -240,40 +240,41 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
         var expectedPanel = cameraDirection === 1 ? Windows.Devices.Enumeration.Panel.front : Windows.Devices.Enumeration.Panel.back;
         Windows.Devices.Enumeration.DeviceInformation.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture)
         .done(function (devices) {
-            if (devices.length > 0) {
-                devices.forEach(function(currDev) {
-                    if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == expectedPanel) {
-                        captureSettings.videoDeviceId = currDev.id;
-                    }
-                });
-
-                capture.initializeAsync(captureSettings).done(function () {
-                    // This is necessary since WP8.1 MediaCapture outputs video stream rotated 90 degrees CCW
-                    // TODO: This can be not consistent across devices, need additional testing on various devices
-                    capture.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
-                    // msdn.microsoft.com/en-us/library/windows/apps/hh452807.aspx
-                    capturePreview.msZoom = true;
-                    capturePreview.src = URL.createObjectURL(capture);
-                    capturePreview.play();
-
-                    // Insert preview frame and controls into page
-                    document.body.appendChild(capturePreview);
-                    document.body.appendChild(captureCancelButton);
-
-                    // Bind events to controls
-                    capturePreview.addEventListener('click', captureAction);
-                    captureCancelButton.addEventListener('click', function () {
-                        destroyCameraPreview();
-                        errorCallback('Cancelled');
-                    }, false);
-                }, function (err) {
-                    destroyCameraPreview();
-                    errorCallback('Camera intitialization error ' + err);
-                });
-            } else {
+            if (devices.length <= 0) {
                 destroyCameraPreview();
                 errorCallback('Camera not found');
+                return;
             }
+
+            devices.forEach(function(currDev) {
+                if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == expectedPanel) {
+                    captureSettings.videoDeviceId = currDev.id;
+                }
+            });
+
+            capture.initializeAsync(captureSettings).done(function () {
+                // This is necessary since WP8.1 MediaCapture outputs video stream rotated 90 degrees CCW
+                // TODO: This can be not consistent across devices, need additional testing on various devices
+                capture.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
+                // msdn.microsoft.com/en-us/library/windows/apps/hh452807.aspx
+                capturePreview.msZoom = true;
+                capturePreview.src = URL.createObjectURL(capture);
+                capturePreview.play();
+
+                // Insert preview frame and controls into page
+                document.body.appendChild(capturePreview);
+                document.body.appendChild(captureCancelButton);
+
+                // Bind events to controls
+                capturePreview.addEventListener('click', captureAction);
+                captureCancelButton.addEventListener('click', function () {
+                    destroyCameraPreview();
+                    errorCallback('Cancelled');
+                }, false);
+            }, function (err) {
+                destroyCameraPreview();
+                errorCallback('Camera intitialization error ' + err);
+            });
         }, errorCallback);
     };
 
@@ -341,51 +342,52 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
                     }
                 };
 
-                if (saveToPhotoAlbum) {
-                    /*
-                        Need to add and remove an event listener to catch activation state
-                        Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
-                        https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
-                    */
-                    var cameraActivationHandler = function(eventArgs) {
-                        if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
-                            var file = eventArgs.file;
-                            if (file) {
-                                // Prevent updates to the remote version of the file until we're done
-                                Windows.Storage.CachedFileManager.deferUpdates(file);
-                                capturedFile.moveAndReplaceAsync(file)
-                                    .then(function() {
-                                        // Let Windows know that we're finished changing the file so
-                                        // the other app can update the remote version of the file.
-                                        return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
-                                    })
-                                    .done(function(updateStatus) {
-                                            if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
-                                                success(capturedFile);
-                                            } else {
-                                                errorCallback();
-                                            }
-                                    }, errorCallback);
-                            } else {
-                                errorCallback();
-                            }
-                            Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
-                        }
-                    };
+                if (!saveToPhotoAlbum) {
+                    success(capturedFile);
+                    return;
+                }
 
-                    var savePicker = new Windows.Storage.Pickers.FileSavePicker();
-                    savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
-                    if (encodingType === Camera.EncodingType.PNG) {
-                        savePicker.fileTypeChoices.insert("PNG", [".png"]);
-                    } else {
-                        savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+                /*
+                    Need to add and remove an event listener to catch activation state
+                    Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
+                    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
+                */
+                var cameraActivationHandler = function(eventArgs) {
+                    if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
+                        var file = eventArgs.file;
+                        if (file) {
+                            // Prevent updates to the remote version of the file until we're done
+                            Windows.Storage.CachedFileManager.deferUpdates(file);
+                            capturedFile.moveAndReplaceAsync(file)
+                                .then(function() {
+                                    // Let Windows know that we're finished changing the file so
+                                    // the other app can update the remote version of the file.
+                                    return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                                })
+                                .done(function(updateStatus) {
+                                        if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                            success(capturedFile);
+                                        } else {
+                                            errorCallback();
+                                        }
+                                }, errorCallback);
+                        } else {
+                            errorCallback();
+                        }
+                        Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
                     }
-                    savePicker.suggestedFileName = fileName;
-                    Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
-                    savePicker.pickSaveFileAndContinue();
+                };
+
+                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+                savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+                if (encodingType === Camera.EncodingType.PNG) {
+                    savePicker.fileTypeChoices.insert("PNG", [".png"]);
                 } else {
-                    success(capturedFile);
+                    savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
                 }
+                savePicker.suggestedFileName = fileName;
+                Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
+                savePicker.pickSaveFileAndContinue();
             }, function(err) {
                     destroyCameraPreview();
                     errorCallback(err);
@@ -432,76 +434,78 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
     }
 
     cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(function(picture) {
-        if (picture) {
-            // save to photo album successCallback
-            var success = function() {
-                if (destinationType == Camera.DestinationType.FILE_URI) {
-                    if (targetHeight > 0 && targetWidth > 0) {
-                        resizeImage(successCallback, errorCallback, picture, targetWidth, targetHeight, encodingType);
-                    } else {
-                        var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
-                        picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function(storageFile) {
-                            successCallback("ms-appdata:///local/" + storageFile.name);
-                        }, errorCallback);
-                    }
+        if (!picture) {
+            errorCallback("User didn't capture a photo.");
+            return;
+        }
+
+        // save to photo album successCallback
+        var success = function() {
+            if (destinationType == Camera.DestinationType.FILE_URI) {
+                if (targetHeight > 0 && targetWidth > 0) {
+                    resizeImage(successCallback, errorCallback, picture, targetWidth, targetHeight, encodingType);
                 } else {
-                    if (targetHeight > 0 && targetWidth > 0) {
-                        resizeImageBase64(successCallback, errorCallback, picture, targetWidth, targetHeight);
-                    } else {
-                        Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
-                            var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
-                            successCallback(strBase64);
-                        }, errorCallback);
-                    }
+                    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
+                    picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function(storageFile) {
+                        successCallback("ms-appdata:///local/" + storageFile.name);
+                    }, errorCallback);
                 }
-            };
+            } else {
+                if (targetHeight > 0 && targetWidth > 0) {
+                    resizeImageBase64(successCallback, errorCallback, picture, targetWidth, targetHeight);
+                } else {
+                    Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
+                        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+                        successCallback(strBase64);
+                    }, errorCallback);
+                }
+            }
+        };
 
-            // save to photo album errorCallback
-            var fail = function() {
-                //errorCallback("FileError, code:" + fileError.code);
-                errorCallback("Save fail.");
-            };
+        // save to photo album errorCallback
+        var fail = function() {
+            //errorCallback("FileError, code:" + fileError.code);
+            errorCallback("Save fail.");
+        };
 
-            if (saveToPhotoAlbum) {
-                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+        if (!saveToPhotoAlbum) {
+            success();
+            return;
+        }
 
-                savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
-                if (encodingType === Camera.EncodingType.PNG) {
-                    savePicker.fileTypeChoices.insert("PNG", [".png"]);
-                    savePicker.suggestedFileName = "photo.png";
-                } else {
-                    savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
-                    savePicker.suggestedFileName = "photo.jpg";
-                }
+        var savePicker = new Windows.Storage.Pickers.FileSavePicker();
 
-                savePicker.pickSaveFileAsync()
-                    .done(function(file) {
-                        if (file) {
-                            // Prevent updates to the remote version of the file until we're done
-                            Windows.Storage.CachedFileManager.deferUpdates(file);
-                            picture.moveAndReplaceAsync(file)
-                                .then(function() {
-                                    // Let Windows know that we're finished changing the file so
-                                    // the other app can update the remote version of the file.
-                                    return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
-                                })
-                                .done(function(updateStatus) {
-                                    if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
-                                        success();
-                                    } else {
-                                        fail();
-                                    }
-                                }, fail);
-                        } else {
-                            fail();
-                        }
-                    }, fail);
-            } else {
-                success();
-            }
+        savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
+        if (encodingType === Camera.EncodingType.PNG) {
+            savePicker.fileTypeChoices.insert("PNG", [".png"]);
+            savePicker.suggestedFileName = "photo.png";
         } else {
-            errorCallback("User didn't capture a photo.");
+            savePicker.fileTypeChoices.insert("JPEG", [".jpg"]);
+            savePicker.suggestedFileName = "photo.jpg";
         }
+
+        savePicker.pickSaveFileAsync()
+            .done(function(file) {
+                if (file) {
+                    // Prevent updates to the remote version of the file until we're done
+                    Windows.Storage.CachedFileManager.deferUpdates(file);
+                    picture.moveAndReplaceAsync(file)
+                        .then(function() {
+                            // Let Windows know that we're finished changing the file so
+                            // the other app can update the remote version of the file.
+                            return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
+                        })
+                        .done(function(updateStatus) {
+                            if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
+                                success();
+                            } else {
+                                fail();
+                            }
+                        }, fail);
+                } else {
+                    fail();
+                }
+            }, fail);
     }, function() {
         errorCallback("Fail to capture a photo.");
     });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org