cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/8] cordova-plugin-camera git commit: CB-8706 use filePicker if saveToPhotoAlbum is true
Date Thu, 09 Apr 2015 23:39:54 GMT
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 <muratsu@microsoft.com>
Authored: Tue Feb 17 15:09:33 2015 -0800
Committer: Murat Sutunc <muratsu@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


Mime
View raw message