mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-05-05 21:22:54 +08:00
Making focus handler work only for windows 10 phone
This commit is contained in:
parent
fb871d40e2
commit
624ddd5ced
@ -745,8 +745,9 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
|
|||||||
cameraCaptureUI.photoSettings.maxResolution = maxRes;
|
cameraCaptureUI.photoSettings.maxResolution = maxRes;
|
||||||
|
|
||||||
var cameraPicture;
|
var cameraPicture;
|
||||||
var savePhotoOnFocus = function() {
|
|
||||||
|
|
||||||
|
// define focus handler for windows phone 10.0
|
||||||
|
var savePhotoOnFocus = function () {
|
||||||
window.removeEventListener("focus", savePhotoOnFocus);
|
window.removeEventListener("focus", savePhotoOnFocus);
|
||||||
// call only when the app is in focus again
|
// call only when the app is in focus again
|
||||||
savePhoto(cameraPicture, {
|
savePhoto(cameraPicture, {
|
||||||
@ -758,16 +759,31 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
|
|||||||
}, successCallback, errorCallback);
|
}, successCallback, errorCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
// add and delete focus eventHandler to capture the focus back from cameraUI to app
|
// if windows phone 10, add and delete focus eventHandler to capture the focus back from cameraUI to app
|
||||||
window.addEventListener("focus", savePhotoOnFocus);
|
if (navigator.appVersion.indexOf('Windows Phone 10.0') >= 0) {
|
||||||
cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function(picture) {
|
window.addEventListener("focus", savePhotoOnFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function (picture) {
|
||||||
if (!picture) {
|
if (!picture) {
|
||||||
errorCallback("User didn't capture a photo.");
|
errorCallback("User didn't capture a photo.");
|
||||||
|
// Remove the focus handler if present
|
||||||
window.removeEventListener("focus", savePhotoOnFocus);
|
window.removeEventListener("focus", savePhotoOnFocus);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cameraPicture = picture;
|
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.");
|
errorCallback("Fail to capture a photo.");
|
||||||
window.removeEventListener("focus", savePhotoOnFocus);
|
window.removeEventListener("focus", savePhotoOnFocus);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user