You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2016/03/24 02:33:29 UTC

cordova-plugin-camera git commit: Making focus handler work only for windows 10 phone

Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master fb871d40e -> 624ddd5ce


Making focus handler work only for windows 10 phone


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/624ddd5c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/624ddd5c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/624ddd5c

Branch: refs/heads/master
Commit: 624ddd5ced709659d2ddea5519bafc28f87ee8ed
Parents: fb871d4
Author: Raghav Katyal <ra...@microsoft.com>
Authored: Wed Mar 23 15:25:27 2016 -0700
Committer: Raghav Katyal <ra...@microsoft.com>
Committed: Wed Mar 23 18:33:09 2016 -0700

----------------------------------------------------------------------
 src/windows/CameraProxy.js | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/624ddd5c/src/windows/CameraProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js
index e0be5b8..0862f35 100644
--- a/src/windows/CameraProxy.js
+++ b/src/windows/CameraProxy.js
@@ -745,8 +745,9 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
     cameraCaptureUI.photoSettings.maxResolution = maxRes;
 
     var cameraPicture;
-    var savePhotoOnFocus = function() {
-
+    
+    // define focus handler for windows phone 10.0
+    var savePhotoOnFocus = function () {
         window.removeEventListener("focus", savePhotoOnFocus);
         // call only when the app is in focus again
         savePhoto(cameraPicture, {
@@ -758,16 +759,31 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
         }, successCallback, errorCallback);
     };
 
-    // add and delete focus eventHandler to capture the focus back from cameraUI to app 
-    window.addEventListener("focus", savePhotoOnFocus);
-    cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function(picture) {
+    // if windows phone 10, add and delete focus eventHandler to capture the focus back from cameraUI to app
+    if (navigator.appVersion.indexOf('Windows Phone 10.0') >= 0) { 
+        window.addEventListener("focus", savePhotoOnFocus);
+    }
+
+    cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function (picture) {
         if (!picture) {
             errorCallback("User didn't capture a photo.");
+            // Remove the focus handler if present
             window.removeEventListener("focus", savePhotoOnFocus);
             return;
         }
         cameraPicture = picture;
-    }, function() {
+
+        // If not windows 10, call savePhoto() now. If windows 10, wait for the app to be in focus again
+        if (navigator.appVersion.indexOf('Windows Phone 10.0') < 0) {
+            savePhoto(cameraPicture, {
+                destinationType: destinationType,
+                targetHeight: targetHeight,
+                targetWidth: targetWidth,
+                encodingType: encodingType,
+                saveToPhotoAlbum: saveToPhotoAlbum
+            }, successCallback, errorCallback);
+        }
+    }, function () {
         errorCallback("Fail to capture a photo.");
         window.removeEventListener("focus", savePhotoOnFocus);
     });


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