This commit is contained in:
Murat Sutunc 2015-04-03 11:08:00 -07:00
parent 29c9ea387d
commit 9e11ab4dfb

View File

@ -158,7 +158,10 @@ function takePictureFromFile(successCallback, errorCallback, mediaType, destinat
}
fileOpenPicker.pickSingleFileAsync().done(function (file) {
if (file) {
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);
@ -183,9 +186,6 @@ function takePictureFromFile(successCallback, errorCallback, mediaType, destinat
}, errorCallback);
}
}
} else {
errorCallback("User didn't choose a file.");
}
}, function () {
errorCallback("User didn't choose a file.");
});
@ -240,7 +240,12 @@ 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) {
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;
@ -270,10 +275,6 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
destroyCameraPreview();
errorCallback('Camera intitialization error ' + err);
});
} else {
destroyCameraPreview();
errorCallback('Camera not found');
}
}, errorCallback);
};
@ -341,7 +342,11 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
}
};
if (saveToPhotoAlbum) {
if (!saveToPhotoAlbum) {
success(capturedFile);
return;
}
/*
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
@ -383,9 +388,6 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
savePicker.suggestedFileName = fileName;
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", cameraActivationHandler);
savePicker.pickSaveFileAndContinue();
} else {
success(capturedFile);
}
}, function(err) {
destroyCameraPreview();
errorCallback(err);
@ -432,7 +434,11 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
}
cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(function(picture) {
if (picture) {
if (!picture) {
errorCallback("User didn't capture a photo.");
return;
}
// save to photo album successCallback
var success = function() {
if (destinationType == Camera.DestinationType.FILE_URI) {
@ -462,7 +468,11 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
errorCallback("Save fail.");
};
if (saveToPhotoAlbum) {
if (!saveToPhotoAlbum) {
success();
return;
}
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
@ -496,12 +506,6 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
fail();
}
}, fail);
} else {
success();
}
} else {
errorCallback("User didn't capture a photo.");
}
}, function() {
errorCallback("Fail to capture a photo.");
});