cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nikhilkh <...@git.apache.org>
Subject [GitHub] cordova-plugin-camera pull request: CB-8054 Support taking picture...
Date Thu, 16 Apr 2015 16:56:16 GMT
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/86#discussion_r28528079
  
    --- Diff: src/windows/CameraProxy.js ---
    @@ -134,16 +134,84 @@ function resizeImageBase64(successCallback, errorCallback, file,
targetWidth, ta
         }, function(err) { errorCallback(err); });
     }
     
    -function takePictureFromFile(successCallback, errorCallback, mediaType, destinationType,
targetWidth, targetHeight, encodingType) {
    -    // TODO: Add WP8.1 support
    -    // WP8.1 doesn't allow to use of pickSingleFileAsync method
    -    // see http://msdn.microsoft.com/en-us/library/windows/apps/br207852.aspx for details
    -    // replacement of pickSingleFileAsync - pickSingleFileAndContinue method
    -    // will take application to suspended state and this require additional logic to
wake application up
    -    if (navigator.appVersion.indexOf('Windows Phone 8.1') >= 0 ) {
    -        errorCallback('Not supported');
    -        return;
    +function takePictureFromFile(successCallback, errorCallback, args) {
    +    // Detect Windows Phone
    +    if (navigator.appVersion.indexOf('Windows Phone 8.1') >= 0) {
    +        takePictureFromFileWP(successCallback, errorCallback, args);
    +    } else {
    +        takePictureFromFileWindows(successCallback, errorCallback, args);
         }
    +}
    +
    +function takePictureFromFileWP(successCallback, errorCallback, args) {
    +    var mediaType = args[6],
    +        destinationType = args[1],
    +        targetWidth = args[3],
    +        targetHeight = args[4],
    +        encodingType = args[5];
    +
    +    /*
    +        Need to add and remove an event listener to catch activation state
    +        Using FileOpenPicker will suspend the app and it's required to catch the PickSingleFileAndContinue
    +        https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
    +    */
    +    var filePickerActivationHandler = function(eventArgs) {
    +        if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickFileContinuation)
{
    +            var file = eventArgs.files[0];
    +            if (!file) {
    +                errorCallback("User didn't choose a file.");
    +                Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", filePickerActivationHandler);
    +                return;
    +            }
    +            if (destinationType == Camera.DestinationType.FILE_URI || destinationType
== Camera.DestinationType.NATIVE_URI) {
    +                if (targetHeight > 0 && targetWidth > 0) {
    +                    resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight,
encodingType);
    +                }
    +                else {
    +                    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
    +                    file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function
(storageFile) {
    +                        successCallback(URL.createObjectURL(storageFile));
    +                    }, function () {
    +                        errorCallback("Can't access localStorage folder.");
    +                    });
    +                }
    +            }
    +            else {
    +                if (targetHeight > 0 && targetWidth > 0) {
    +                    resizeImageBase64(successCallback, errorCallback, file, targetWidth,
targetHeight);
    +                } else {
    +                    Windows.Storage.FileIO.readBufferAsync(file).done(function (buffer)
{
    +                        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
    +                        successCallback(strBase64);
    +                    }, errorCallback);
    +                }
    +            }
    +            Windows.UI.WebUI.WebUIApplication.removeEventListener("activated", filePickerActivationHandler);
    +        }
    +    };
    +
    +    var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
    +    fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
    +    if (mediaType == Camera.MediaType.PICTURE) {
    +        fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
    +    }
    +    else if (mediaType == Camera.MediaType.VIDEO) {
    +        fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov",
".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
    --- End diff --
    
    Wonder if this list of video formats should be shared with the one from windows below?
It's amazing that so many video formats are supported here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message