From dc81afb251650514e62d8b07623910c6db2bcba3 Mon Sep 17 00:00:00 2001 From: Krzysztof Pintscher Date: Sun, 26 Jul 2015 22:23:57 +0200 Subject: [PATCH] Fix --- README.md | 2 + package.json | 2 +- plugin.xml | 2 +- src/android/CameraLauncher.java | 10 +- src/ios/CDVCamera.m | 29 ++--- src/windows/CameraProxy.js | 109 ++++++------------ tests/ios/{.gitignore => .npmignore} | 0 .../CDVCameraLibTests/CameraTest.m | 6 +- tests/plugin.xml | 2 +- 9 files changed, 55 insertions(+), 107 deletions(-) rename tests/ios/{.gitignore => .npmignore} (100%) diff --git a/README.md b/README.md index 9d1e35171..f64ca0f9a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ # cordova-plugin-camera +[![Build Status](https://travis-ci.org/apache/cordova-plugin-camera.svg)](https://travis-ci.org/apache/cordova-plugin-camera) + This plugin defines a global `navigator.camera` object, which provides an API for taking pictures and for choosing images from the system's image library. diff --git a/package.json b/package.json index b5c18c725..d4c90e941 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-camera", - "version": "1.2.1-dev", + "version": "1.2.0", "description": "Cordova Camera Plugin", "cordova": { "id": "cordova-plugin-camera", diff --git a/plugin.xml b/plugin.xml index 0cb9d9f97..26c1545f9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -22,7 +22,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rim="http://www.blackberry.com/ns/widgets" id="cordova-plugin-camera" - version="1.2.1-dev"> + version="1.2.0"> Camera Cordova Camera Plugin Apache 2.0 diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 986a9ae7d..c9584a3f8 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -379,7 +379,7 @@ private void processResultFromCamera(int destType, Intent intent) throws IOExcep } //We don't support PNG, so let's not pretend we do - exif.createInFile(sourcePath); + exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); @@ -442,13 +442,7 @@ else if (destType == FILE_URI || destType == NATIVE_URI) { this.callbackContext.success(uri.toString()); } else { - if(croppedUri != null) { - bitmap = getScaledBitmap(FileHelper.stripFileProtocol(croppedUri.toString())); - } - else - { - bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); - } + bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index 328a72e04..f3ba254ea 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one #import "CDVCamera.h" #import "CDVJpegHeaderWriter.h" #import "UIImage+CropScaleOrientation.h" +#import #import #import #import @@ -30,10 +31,6 @@ Licensed to the Apache Software Foundation (ASF) under one #import #import -#ifndef __CORDOVA_4_0_0 - #import -#endif - #define CDV_PHOTO_PREFIX @"cdv_photo_" static NSSet* org_apache_cordova_validArrowDirections; @@ -41,20 +38,9 @@ Licensed to the Apache Software Foundation (ASF) under one static NSString* toBase64(NSData* data) { SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString"); SEL s2 = NSSelectorFromString(@"base64EncodedString"); - SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:"); - - if ([data respondsToSelector:s1]) { - NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1]; - return func(data, s1); - } else if ([data respondsToSelector:s2]) { - NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s2]; - return func(data, s2); - } else if ([data respondsToSelector:s3]) { - NSString* (*func)(id, SEL, NSUInteger) = (void *)[data methodForSelector:s3]; - return func(data, s3, 0); - } else { - return nil; - } + SEL realSel = [data respondsToSelector:s1] ? s1 : s2; + NSString* (*func)(id, SEL) = (void *)[data methodForSelector:realSel]; + return func(data, realSel); } @implementation CDVPictureOptions @@ -417,10 +403,9 @@ - (UIImage*)retrieveImage:(NSDictionary*)info options:(CDVPictureOptions*)option } else { scaledImage = [image imageByScalingNotCroppingForSize:options.targetSize]; } - } else if (options.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) { - scaledImage = [image imageCropWithoutScale:info]; - } - + } else if (options.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) { + scaledImage = [image imageCropWithoutScale:info]; + } return (scaledImage == nil ? image : scaledImage); } diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js index b70895dc3..d03a18002 100644 --- a/src/windows/CameraProxy.js +++ b/src/windows/CameraProxy.js @@ -267,12 +267,7 @@ function takePictureFromFileWindows(successCallback, errorCallback, args) { else { var storageFolder = getAppData().localFolder; file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) { - if(destinationType == Camera.DestinationType.NATIVE_URI) { - successCallback("ms-appdata:///local/" + storageFile.name); - } - else { - successCallback(URL.createObjectURL(storageFile)); - } + successCallback(URL.createObjectURL(storageFile)); }, function () { errorCallback("Can't access localStorage folder."); }); @@ -312,7 +307,6 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { saveToPhotoAlbum = args[9], cameraDirection = args[11], capturePreview = null, - captureTakePhotoButton = null, captureCancelButton = null, capture = null, captureSettings = null, @@ -320,24 +314,17 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { sensor = null; var createCameraUI = function () { - // create style for take and cancel buttons - var buttonStyle = "width:45%;padding: 10px 16px;font-size: 18px;line-height: 1.3333333;color: #333;background-color: #fff;border-color: #ccc; border: 1px solid transparent;border-radius: 6px; display: block; margin: 20px; z-index: 1000;border-color: #adadad;"; - // Create fullscreen preview - // z-order style element for capturePreview and captureCancelButton elts - // is necessary to avoid overriding by another page elements, -1 sometimes is not enough capturePreview = document.createElement("video"); - capturePreview.style.cssText = "position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 999;"; - // Create capture button - captureTakePhotoButton = document.createElement("button"); - captureTakePhotoButton.innerText = "Take"; - captureTakePhotoButton.style.cssText = buttonStyle + "position: fixed; left: 0; bottom: 0; margin: 20px; z-index: 1000"; + // z-order style element for capturePreview and captureCancelButton elts + // is necessary to avoid overriding by another page elements, -1 sometimes is not enough + capturePreview.style.cssText = "position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 999"; // Create cancel button captureCancelButton = document.createElement("button"); captureCancelButton.innerText = "Cancel"; - captureCancelButton.style.cssText = buttonStyle + "position: fixed; right: 0; bottom: 0; margin: 20px; z-index: 1000"; + captureCancelButton.style.cssText = "position: fixed; right: 0; bottom: 0; display: block; margin: 20px; z-index: 1000"; capture = new CaptureNS.MediaCapture(); @@ -368,22 +355,6 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { return capture.initializeAsync(captureSettings); }).then(function () { - - // create focus control if available - var VideoDeviceController = capture.videoDeviceController; - var FocusControl = VideoDeviceController.focusControl; - - if (FocusControl.supported == true) { - capturePreview.addEventListener('click', function () { - - var preset = Windows.Media.Devices.FocusPreset.autoNormal; - - FocusControl.setPresetAsync(preset).done(function () { - - }); - }); - } - // msdn.microsoft.com/en-us/library/windows/apps/hh452807.aspx capturePreview.msZoom = true; capturePreview.src = URL.createObjectURL(capture); @@ -394,12 +365,10 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { if (sensor !== null) { sensor.addEventListener("orientationchanged", onOrientationChange); } - - // add click events to take and cancel buttons - captureTakePhotoButton.addEventListener('click', captureAction); + capturePreview.addEventListener('click', captureAction); captureCancelButton.addEventListener('click', function () { destroyCameraPreview(); - errorCallback('no image selected'); + errorCallback('Cancelled'); }, false); // Change default orientation @@ -419,9 +388,8 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { return; } - // add elements to body + // Insert preview frame and controls into page document.body.appendChild(capturePreview); - document.body.appendChild(captureTakePhotoButton); document.body.appendChild(captureCancelButton); if (aspectRatios.indexOf(DEFAULT_ASPECT_RATIO) > -1) { @@ -442,8 +410,7 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { } capturePreview.pause(); capturePreview.src = null; - // remove elements from wrapper - [capturePreview, captureTakePhotoButton, captureCancelButton].forEach(function (elem) { + [capturePreview, captureCancelButton].forEach(function(elem) { if (elem /* && elem in document.body.childNodes */) { document.body.removeChild(elem); } @@ -474,33 +441,33 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { var photoStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); var finalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); capture.capturePhotoToStreamAsync(encodingProperties, photoStream) - .then(function() { - return Windows.Graphics.Imaging.BitmapDecoder.createAsync(photoStream); - }) - .then(function(dec) { - finalStream.size = 0; // BitmapEncoder requires the output stream to be empty - return Windows.Graphics.Imaging.BitmapEncoder.createForTranscodingAsync(finalStream, dec); - }) - .then(function(enc) { - // We need to rotate the photo wrt sensor orientation - enc.bitmapTransform.rotation = orientationToRotation(sensor.getCurrentOrientation()); - return enc.flushAsync(); - }) - .then(function() { - return tempCapturedFile.openAsync(Windows.Storage.FileAccessMode.readWrite); - }) - .then(function(fileStream) { - return Windows.Storage.Streams.RandomAccessStream.copyAsync(finalStream, fileStream); - }) - .done(function() { - photoStream.close(); - finalStream.close(); - complete(tempCapturedFile); - }, function() { - photoStream.close(); - finalStream.close(); - throw new Error("An error has occured while capturing the photo."); - }); + .then(function() { + return Windows.Graphics.Imaging.BitmapDecoder.createAsync(photoStream); + }) + .then(function(dec) { + finalStream.size = 0; // BitmapEncoder requires the output stream to be empty + return Windows.Graphics.Imaging.BitmapEncoder.createForTranscodingAsync(finalStream, dec); + }) + .then(function(enc) { + // We need to rotate the photo wrt sensor orientation + enc.bitmapTransform.rotation = orientationToRotation(sensor.getCurrentOrientation()); + return enc.flushAsync(); + }) + .then(function() { + return tempCapturedFile.openAsync(Windows.Storage.FileAccessMode.readWrite); + }) + .then(function(fileStream) { + return Windows.Storage.Streams.RandomAccessStream.copyAsync(finalStream, fileStream); + }) + .done(function() { + photoStream.close(); + finalStream.close(); + complete(tempCapturedFile); + }, function() { + photoStream.close(); + finalStream.close(); + throw new Error("An error has occured while capturing the photo."); + }); }); }) .done(function(capturedFile) { @@ -513,8 +480,8 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { saveToPhotoAlbum: saveToPhotoAlbum }, successCallback, errorCallback); }, function(err) { - destroyCameraPreview(); - errorCallback(err); + destroyCameraPreview(); + errorCallback(err); }); }; diff --git a/tests/ios/.gitignore b/tests/ios/.npmignore similarity index 100% rename from tests/ios/.gitignore rename to tests/ios/.npmignore diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m index d1da2faa1..42111983e 100644 --- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m +++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m @@ -476,7 +476,7 @@ - (void) testProcessImage pictureOptions.encodingType = EncodingTypePNG; resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataPNG base64EncodedStringWithOptions:0]); + XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataPNG base64EncodedString]); // Original, JPEG, full quality @@ -487,7 +487,7 @@ - (void) testProcessImage pictureOptions.encodingType = EncodingTypeJPEG; resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataJPEG base64EncodedStringWithOptions:0]); + XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataJPEG base64EncodedString]); // Original, JPEG, with quality value @@ -500,7 +500,7 @@ - (void) testProcessImage NSData* originalImageDataJPEGWithQuality = UIImageJPEGRepresentation(originalImage, [pictureOptions.quality floatValue]/ 100.f); resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataJPEGWithQuality base64EncodedStringWithOptions:0]); + XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataJPEGWithQuality base64EncodedString]); // TODO: usesGeolocation is not tested } diff --git a/tests/plugin.xml b/tests/plugin.xml index 7cf4a5396..2665d6f7e 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -22,7 +22,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rim="http://www.blackberry.com/ns/widgets" id="cordova-plugin-camera-tests" - version="1.2.1-dev"> + version="1.2.0"> Cordova Camera Plugin Tests Apache 2.0