CB-8707 refactoring windows code to improve readability
This commit is contained in:
parent
5ef04e552c
commit
29c9ea387d
@ -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'),
|
var Camera = require('./Camera');
|
||||||
Camera = require('./Camera');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
@ -43,18 +43,19 @@ module.exports = {
|
|||||||
// 11 cameraDirection:0
|
// 11 cameraDirection:0
|
||||||
|
|
||||||
takePicture: function (successCallback, errorCallback, args) {
|
takePicture: function (successCallback, errorCallback, args) {
|
||||||
var encodingType = args[5];
|
|
||||||
var targetWidth = args[3];
|
|
||||||
var targetHeight = args[4];
|
|
||||||
var sourceType = args[2];
|
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 :)
|
if (sourceType != Camera.PictureSourceType.CAMERA) {
|
||||||
var resizeImage = function (file) {
|
takePictureFromFile(successCallback, errorCallback, args);
|
||||||
|
} else {
|
||||||
|
takePictureFromCamera(successCallback, errorCallback, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Resize method
|
||||||
|
function resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType) {
|
||||||
var tempPhotoFileName = "";
|
var tempPhotoFileName = "";
|
||||||
if (encodingType == Camera.EncodingType.PNG) {
|
if (encodingType == Camera.EncodingType.PNG) {
|
||||||
tempPhotoFileName = "camera_cordova_temp_return.png";
|
tempPhotoFileName = "camera_cordova_temp_return.png";
|
||||||
@ -63,8 +64,9 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting)
|
||||||
Windows.Storage.FileIO.readBufferAsync(storageFile).then(function(buffer) {
|
.then(function (storageFile) { return Windows.Storage.FileIO.readBufferAsync(storageFile); })
|
||||||
|
.then(function(buffer) {
|
||||||
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
||||||
var imageData = "data:" + file.contentType + ";base64," + strBase64;
|
var imageData = "data:" + file.contentType + ";base64," + strBase64;
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
@ -73,6 +75,7 @@ module.exports = {
|
|||||||
var imageWidth = targetWidth,
|
var imageWidth = targetWidth,
|
||||||
imageHeight = targetHeight;
|
imageHeight = targetHeight;
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
var storageFileName;
|
||||||
|
|
||||||
canvas.width = imageWidth;
|
canvas.width = imageWidth;
|
||||||
canvas.height = imageHeight;
|
canvas.height = imageHeight;
|
||||||
@ -83,25 +86,25 @@ module.exports = {
|
|||||||
|
|
||||||
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
|
|
||||||
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (storagefile) {
|
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName)
|
||||||
|
.then(function (storagefile) {
|
||||||
var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
|
var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
|
||||||
Windows.Storage.FileIO.writeBufferAsync(storagefile, content).then(function () {
|
storageFileName = storagefile.name;
|
||||||
successCallback("ms-appdata:///local/" + storagefile.name);
|
return Windows.Storage.FileIO.writeBufferAsync(storagefile, content);
|
||||||
}, function () {
|
})
|
||||||
errorCallback("Resize picture error.");
|
.done(function () {
|
||||||
});
|
successCallback("ms-appdata:///local/" + storageFileName);
|
||||||
});
|
}, errorCallback);
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
}, function () {
|
.done(null, function(err) {
|
||||||
errorCallback("Can't access localStorage folder");
|
errorCallback(err);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
// because of asynchronous method, so let the successCallback be called in it.
|
|
||||||
var resizeImageBase64 = function (file) {
|
|
||||||
|
|
||||||
|
// 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) {
|
Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
|
||||||
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
||||||
var imageData = "data:" + file.contentType + ";base64," + strBase64;
|
var imageData = "data:" + file.contentType + ";base64," + strBase64;
|
||||||
@ -128,11 +131,10 @@ module.exports = {
|
|||||||
var newStr = finalFile.substr(arr[0].length + 1);
|
var newStr = finalFile.substr(arr[0].length + 1);
|
||||||
successCallback(newStr);
|
successCallback(newStr);
|
||||||
};
|
};
|
||||||
});
|
}, function(err) { errorCallback(err); });
|
||||||
};
|
}
|
||||||
|
|
||||||
if (sourceType != Camera.PictureSourceType.CAMERA) {
|
|
||||||
|
|
||||||
|
function takePictureFromFile(successCallback, errorCallback, mediaType, destinationType, targetWidth, targetHeight, encodingType) {
|
||||||
// TODO: Add WP8.1 support
|
// TODO: Add WP8.1 support
|
||||||
// WP8.1 doesn't allow to use of pickSingleFileAsync method
|
// WP8.1 doesn't allow to use of pickSingleFileAsync method
|
||||||
// see http://msdn.microsoft.com/en-us/library/windows/apps/br207852.aspx for details
|
// see http://msdn.microsoft.com/en-us/library/windows/apps/br207852.aspx for details
|
||||||
@ -159,12 +161,11 @@ module.exports = {
|
|||||||
if (file) {
|
if (file) {
|
||||||
if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
|
if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(file);
|
resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
|
||||||
successCallback(URL.createObjectURL(storageFile));
|
successCallback(URL.createObjectURL(storageFile));
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Can't access localStorage folder.");
|
errorCallback("Can't access localStorage folder.");
|
||||||
@ -174,38 +175,47 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImageBase64(file);
|
resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
|
||||||
} else {
|
} else {
|
||||||
Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
|
Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer) {
|
||||||
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
||||||
successCallback(strBase64);
|
successCallback(strBase64);
|
||||||
});
|
}, errorCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorCallback("User didn't choose a file.");
|
errorCallback("User didn't choose a file.");
|
||||||
}
|
}
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("User didn't choose a file.");
|
errorCallback("User didn't choose a file.");
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
var CaptureNS = Windows.Media.Capture;
|
|
||||||
|
|
||||||
|
function takePictureFromCamera(successCallback, errorCallback, args) {
|
||||||
// Check if necessary API available
|
// Check if necessary API available
|
||||||
if (!CaptureNS.CameraCaptureUI) {
|
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
|
// We are running on WP8.1 which lacks CameraCaptureUI class
|
||||||
// so we need to use MediaCapture class instead and implement custom UI for camera
|
// so we need to use MediaCapture class instead and implement custom UI for camera
|
||||||
|
var destinationType = args[1],
|
||||||
var capturePreview = null,
|
targetWidth = args[3],
|
||||||
|
targetHeight = args[4],
|
||||||
|
encodingType = args[5],
|
||||||
|
saveToPhotoAlbum = args[9],
|
||||||
|
cameraDirection = args[11],
|
||||||
|
capturePreview = null,
|
||||||
captureCancelButton = null,
|
captureCancelButton = null,
|
||||||
capture = null,
|
capture = null,
|
||||||
captureSettings = null;
|
captureSettings = null,
|
||||||
|
CaptureNS = Windows.Media.Capture;
|
||||||
|
|
||||||
var createCameraUI = function () {
|
var createCameraUI = function () {
|
||||||
|
|
||||||
// Create fullscreen preview
|
// Create fullscreen preview
|
||||||
capturePreview = document.createElement("video");
|
capturePreview = document.createElement("video");
|
||||||
|
|
||||||
@ -225,7 +235,6 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var startCameraPreview = function () {
|
var startCameraPreview = function () {
|
||||||
|
|
||||||
// Search for available camera devices
|
// Search for available camera devices
|
||||||
// This is necessary to detect which camera (front or back) we should use
|
// 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;
|
var expectedPanel = cameraDirection === 1 ? Windows.Devices.Enumeration.Panel.front : Windows.Devices.Enumeration.Panel.back;
|
||||||
@ -265,7 +274,7 @@ module.exports = {
|
|||||||
destroyCameraPreview();
|
destroyCameraPreview();
|
||||||
errorCallback('Camera not found');
|
errorCallback('Camera not found');
|
||||||
}
|
}
|
||||||
});
|
}, errorCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
var destroyCameraPreview = function () {
|
var destroyCameraPreview = function () {
|
||||||
@ -287,7 +296,8 @@ module.exports = {
|
|||||||
var encodingProperties,
|
var encodingProperties,
|
||||||
fileName,
|
fileName,
|
||||||
generateUniqueCollisionOption = Windows.Storage.CreationCollisionOption.generateUniqueName,
|
generateUniqueCollisionOption = Windows.Storage.CreationCollisionOption.generateUniqueName,
|
||||||
tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder;
|
tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder,
|
||||||
|
capturedFile;
|
||||||
|
|
||||||
if (encodingType == Camera.EncodingType.PNG) {
|
if (encodingType == Camera.EncodingType.PNG) {
|
||||||
fileName = 'photo.png';
|
fileName = 'photo.png';
|
||||||
@ -297,16 +307,19 @@ module.exports = {
|
|||||||
encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createJpeg();
|
encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createJpeg();
|
||||||
}
|
}
|
||||||
|
|
||||||
tempFolder.createFileAsync(fileName, generateUniqueCollisionOption).done(function(capturedFile) {
|
tempFolder.createFileAsync(fileName, generateUniqueCollisionOption)
|
||||||
capture.capturePhotoToStorageFileAsync(encodingProperties, capturedFile).done(function() {
|
.then(function(tempCapturedFile) {
|
||||||
|
capturedFile = tempCapturedFile;
|
||||||
|
return capture.capturePhotoToStorageFileAsync(encodingProperties, capturedFile);
|
||||||
|
})
|
||||||
|
.done(function() {
|
||||||
destroyCameraPreview();
|
destroyCameraPreview();
|
||||||
|
|
||||||
// success callback for capture operation
|
// success callback for capture operation
|
||||||
var success = function(capturedfile) {
|
var success = function(capturedfile) {
|
||||||
if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
|
if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(capturedfile);
|
resizeImage(successCallback, errorCallback, capturedFile, targetWidth, targetHeight, encodingType);
|
||||||
} else {
|
} else {
|
||||||
capturedfile.copyAsync(Windows.Storage.ApplicationData.current.localFolder, capturedfile.name, generateUniqueCollisionOption).done(function(copiedfile) {
|
capturedfile.copyAsync(Windows.Storage.ApplicationData.current.localFolder, capturedfile.name, generateUniqueCollisionOption).done(function(copiedfile) {
|
||||||
successCallback("ms-appdata:///local/" + copiedfile.name);
|
successCallback("ms-appdata:///local/" + copiedfile.name);
|
||||||
@ -314,15 +327,14 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImageBase64(capturedfile);
|
resizeImageBase64(successCallback, errorCallback, capturedfile, targetWidth, targetHeight);
|
||||||
} else {
|
} else {
|
||||||
Windows.Storage.FileIO.readBufferAsync(capturedfile).done(function(buffer) {
|
Windows.Storage.FileIO.readBufferAsync(capturedfile).done(function(buffer) {
|
||||||
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
||||||
capturedfile.deleteAsync().done(function() {
|
capturedfile.deleteAsync().done(function() {
|
||||||
successCallback(strBase64);
|
successCallback(strBase64);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
console.error(err);
|
errorCallback(err);
|
||||||
successCallback(strBase64);
|
|
||||||
});
|
});
|
||||||
}, errorCallback);
|
}, errorCallback);
|
||||||
}
|
}
|
||||||
@ -335,7 +347,7 @@ module.exports = {
|
|||||||
Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
|
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
|
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
|
||||||
*/
|
*/
|
||||||
function cameraActivationHandler(eventArgs) {
|
var cameraActivationHandler = function(eventArgs) {
|
||||||
if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
|
if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
|
||||||
var file = eventArgs.file;
|
var file = eventArgs.file;
|
||||||
if (file) {
|
if (file) {
|
||||||
@ -347,21 +359,19 @@ module.exports = {
|
|||||||
// the other app can update the remote version of the file.
|
// the other app can update the remote version of the file.
|
||||||
return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
|
return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
|
||||||
})
|
})
|
||||||
.done(
|
.done(function(updateStatus) {
|
||||||
function(updateStatus) {
|
|
||||||
if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
|
if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
|
||||||
success(capturedFile);
|
success(capturedFile);
|
||||||
} else {
|
} else {
|
||||||
errorCallback();
|
errorCallback();
|
||||||
}
|
}
|
||||||
}, errorCallback
|
}, errorCallback);
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
errorCallback();
|
errorCallback();
|
||||||
}
|
}
|
||||||
Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
|
Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", cameraActivationHandler);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
|
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
|
||||||
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
|
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
|
||||||
@ -376,12 +386,6 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
success(capturedFile);
|
success(capturedFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}, function(err) {
|
|
||||||
destroyCameraPreview();
|
|
||||||
errorCallback(err);
|
|
||||||
});
|
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
destroyCameraPreview();
|
destroyCameraPreview();
|
||||||
errorCallback(err);
|
errorCallback(err);
|
||||||
@ -394,10 +398,16 @@ module.exports = {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
errorCallback(ex);
|
errorCallback(ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
function takePictureFromCameraWindows(successCallback, errorCallback, args) {
|
||||||
|
var destinationType = args[1],
|
||||||
var cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
|
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;
|
cameraCaptureUI.photoSettings.allowCropping = allowCrop;
|
||||||
|
|
||||||
if (encodingType == Camera.EncodingType.PNG) {
|
if (encodingType == Camera.EncodingType.PNG) {
|
||||||
@ -421,33 +431,31 @@ module.exports = {
|
|||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function(picture) {
|
cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(function(picture) {
|
||||||
if (picture) {
|
if (picture) {
|
||||||
// save to photo album successCallback
|
// save to photo album successCallback
|
||||||
var success = function() {
|
var success = function() {
|
||||||
if (destinationType == Camera.DestinationType.FILE_URI) {
|
if (destinationType == Camera.DestinationType.FILE_URI) {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(picture);
|
resizeImage(successCallback, errorCallback, picture, targetWidth, targetHeight, encodingType);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function(storageFile) {
|
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function(storageFile) {
|
||||||
successCallback("ms-appdata:///local/" + storageFile.name);
|
successCallback("ms-appdata:///local/" + storageFile.name);
|
||||||
}, function() {
|
}, errorCallback);
|
||||||
errorCallback("Can't access localStorage folder.");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImageBase64(picture);
|
resizeImageBase64(successCallback, errorCallback, picture, targetWidth, targetHeight);
|
||||||
} else {
|
} else {
|
||||||
Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
|
Windows.Storage.FileIO.readBufferAsync(picture).done(function(buffer) {
|
||||||
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
|
||||||
successCallback(strBase64);
|
successCallback(strBase64);
|
||||||
});
|
}, errorCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// save to photo album errorCallback
|
// save to photo album errorCallback
|
||||||
var fail = function() {
|
var fail = function() {
|
||||||
//errorCallback("FileError, code:" + fileError.code);
|
//errorCallback("FileError, code:" + fileError.code);
|
||||||
@ -467,7 +475,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
savePicker.pickSaveFileAsync()
|
savePicker.pickSaveFileAsync()
|
||||||
.then(function(file) {
|
.done(function(file) {
|
||||||
if (file) {
|
if (file) {
|
||||||
// Prevent updates to the remote version of the file until we're done
|
// Prevent updates to the remote version of the file until we're done
|
||||||
Windows.Storage.CachedFileManager.deferUpdates(file);
|
Windows.Storage.CachedFileManager.deferUpdates(file);
|
||||||
@ -477,21 +485,17 @@ module.exports = {
|
|||||||
// the other app can update the remote version of the file.
|
// the other app can update the remote version of the file.
|
||||||
return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
|
return Windows.Storage.CachedFileManager.completeUpdatesAsync(file);
|
||||||
})
|
})
|
||||||
.done(
|
.done(function(updateStatus) {
|
||||||
function(updateStatus) {
|
|
||||||
if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
|
if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
}, function() {
|
}, fail);
|
||||||
fail();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
});
|
}, fail);
|
||||||
} else {
|
} else {
|
||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
@ -501,9 +505,6 @@ module.exports = {
|
|||||||
}, function() {
|
}, function() {
|
||||||
errorCallback("Fail to capture a photo.");
|
errorCallback("Fail to capture a photo.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
require("cordova/exec/proxy").add("Camera",module.exports);
|
require("cordova/exec/proxy").add("Camera",module.exports);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user