Skip to content

Commit

Permalink
Merge branch 'release/1.1.3' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
grgar committed Apr 23, 2013
2 parents 7b869ac + b076451 commit c092faf
Show file tree
Hide file tree
Showing 69 changed files with 4,048 additions and 5,498 deletions.
5 changes: 3 additions & 2 deletions CordovaLib/Classes/CDV.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#import "CDVConnection.h"
#import "CDVContact.h"
#import "CDVContacts.h"
#import "CDVCordovaView.h"
#import "CDVDebug.h"
#import "CDVDebugConsole.h"
#import "CDVDevice.h"
Expand All @@ -46,11 +45,13 @@
#import "CDVSplashScreen.h"
#import "CDVWhitelist.h"
#import "CDVLocalStorage.h"
#import "CDVInAppBrowser.h"
#import "CDVScreenOrientationDelegate.h"

#import "NSArray+Comparisons.h"
#import "NSData+Base64.h"
#import "NSDictionary+Extensions.h"
#import "NSMutableArray+QueueAdditions.h"
#import "UIDevice+Extensions.h"

#import "JSONKit.h"
#import "CDVJSON.h"
5 changes: 4 additions & 1 deletion CordovaLib/Classes/CDVAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#define __CORDOVA_2_0_0 20000
#define __CORDOVA_2_1_0 20100
#define __CORDOVA_2_2_0 20200
#define __CORDOVA_2_3_0 20300
#define __CORDOVA_2_4_0 20400
#define __CORDOVA_2_5_0 20500
#define __CORDOVA_NA 99999 /* not available */

/*
Expand All @@ -44,7 +47,7 @@
#endif
*/
#ifndef CORDOVA_VERSION_MIN_REQUIRED
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_2_0
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_5_0
#endif

/*
Expand Down
4 changes: 3 additions & 1 deletion CordovaLib/Classes/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

enum CDVDestinationType {
DestinationTypeDataUrl = 0,
DestinationTypeFileUri
DestinationTypeFileUri,
DestinationTypeNativeUri
};
typedef NSUInteger CDVDestinationType;

Expand Down Expand Up @@ -79,6 +80,7 @@ typedef NSUInteger CDVMediaType;
- (void)takePicture:(CDVInvokedUrlCommand*)command;
- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;
- (void)cleanup:(CDVInvokedUrlCommand*)command;
- (void)repositionPopover:(CDVInvokedUrlCommand*)command;

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo;
Expand Down
159 changes: 92 additions & 67 deletions CordovaLib/Classes/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
targetSize = CGSizeMake([targetWidth floatValue], [targetHeight floatValue]);
}

// If a popover is already open, close it; we only want one at a time.
if (([[self pickerController] popoverController] != nil) && [[[self pickerController] popoverController] isPopoverVisible]) {
[[[self pickerController] popoverController] dismissPopoverAnimated:YES];
[[[self pickerController] popoverController] setDelegate:nil];
[[self pickerController] setPopoverController:nil];
}

CDVCameraPicker* cameraPicker = [[CDVCameraPicker alloc] init];
self.pickerController = cameraPicker;

Expand Down Expand Up @@ -128,28 +135,8 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
if (cameraPicker.popoverController == nil) {
cameraPicker.popoverController = [[NSClassFromString (@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
}
int x = 0;
int y = 32;
int width = 320;
int height = 480;
UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirectionAny;
NSDictionary* options = [command.arguments objectAtIndex:10 withDefault:nil];
if (options) {
x = [options integerValueForKey:@"x" defaultValue:0];
y = [options integerValueForKey:@"y" defaultValue:32];
width = [options integerValueForKey:@"width" defaultValue:320];
height = [options integerValueForKey:@"height" defaultValue:480];
arrowDirection = [options integerValueForKey:@"arrowDir" defaultValue:UIPopoverArrowDirectionAny];
if (![org_apache_cordova_validArrowDirections containsObject:[NSNumber numberWithInt:arrowDirection]]) {
arrowDirection = UIPopoverArrowDirectionAny;
}
}

cameraPicker.popoverController.delegate = self;
[cameraPicker.popoverController presentPopoverFromRect:CGRectMake(x, y, width, height)
inView:[self.webView superview]
permittedArrowDirections:arrowDirection
animated:YES];
[self displayPopover:options];
} else {
if ([self.viewController respondsToSelector:@selector(presentViewController:::)]) {
[self.viewController presentViewController:cameraPicker animated:YES completion:nil];
Expand All @@ -160,6 +147,39 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
self.hasPendingOperation = YES;
}

- (void)repositionPopover:(CDVInvokedUrlCommand*)command
{
NSDictionary* options = [command.arguments objectAtIndex:0 withDefault:nil];

[self displayPopover:options];
}

- (void)displayPopover:(NSDictionary*)options
{
int x = 0;
int y = 32;
int width = 320;
int height = 480;
UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirectionAny;

if (options) {
x = [options integerValueForKey:@"x" defaultValue:0];
y = [options integerValueForKey:@"y" defaultValue:32];
width = [options integerValueForKey:@"width" defaultValue:320];
height = [options integerValueForKey:@"height" defaultValue:480];
arrowDirection = [options integerValueForKey:@"arrowDir" defaultValue:UIPopoverArrowDirectionAny];
if (![org_apache_cordova_validArrowDirections containsObject:[NSNumber numberWithInt:arrowDirection]]) {
arrowDirection = UIPopoverArrowDirectionAny;
}
}

[[[self pickerController] popoverController] setDelegate:self];
[[[self pickerController] popoverController] presentPopoverFromRect:CGRectMake(x, y, width, height)
inView:[self.webView superview]
permittedArrowDirections:arrowDirection
animated:YES];
}

- (void)cleanup:(CDVInvokedUrlCommand*)command
{
// empty the tmp directory
Expand Down Expand Up @@ -232,63 +252,68 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
// IMAGE TYPE
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
// get the image
UIImage* image = nil;
if (cameraPicker.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) {
image = [info objectForKey:UIImagePickerControllerEditedImage];
if (cameraPicker.returnType == DestinationTypeNativeUri) {
NSString* nativeUri = [(NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nativeUri];
} else {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
// get the image
UIImage* image = nil;
if (cameraPicker.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) {
image = [info objectForKey:UIImagePickerControllerEditedImage];
} else {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}

if (cameraPicker.saveToPhotoAlbum) {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
if (cameraPicker.saveToPhotoAlbum) {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}

if (cameraPicker.correctOrientation) {
image = [self imageCorrectedForCaptureOrientation:image];
}
if (cameraPicker.correctOrientation) {
image = [self imageCorrectedForCaptureOrientation:image];
}

UIImage* scaledImage = nil;
UIImage* scaledImage = nil;

if ((cameraPicker.targetSize.width > 0) && (cameraPicker.targetSize.height > 0)) {
// if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
if (cameraPicker.cropToSize) {
scaledImage = [self imageByScalingAndCroppingForSize:image toSize:cameraPicker.targetSize];
} else {
scaledImage = [self imageByScalingNotCroppingForSize:image toSize:cameraPicker.targetSize];
if ((cameraPicker.targetSize.width > 0) && (cameraPicker.targetSize.height > 0)) {
// if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
if (cameraPicker.cropToSize) {
scaledImage = [self imageByScalingAndCroppingForSize:image toSize:cameraPicker.targetSize];
} else {
scaledImage = [self imageByScalingNotCroppingForSize:image toSize:cameraPicker.targetSize];
}
}
}

NSData* data = nil;
NSData* data = nil;

if (cameraPicker.encodingType == EncodingTypePNG) {
data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
} else {
data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
}
if (cameraPicker.encodingType == EncodingTypePNG) {
data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
} else {
data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
}

if (cameraPicker.returnType == DestinationTypeFileUri) {
// write to temp directory and return URI
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
// generate unique file name
NSString* filePath;

int i = 1;
do {
filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, cameraPicker.encodingType == EncodingTypePNG ? @"png":@"jpg"];
} while ([fileMgr fileExistsAtPath:filePath]);

// save file
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
if (cameraPicker.returnType == DestinationTypeFileUri) {
// write to temp directory and return URI
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
// generate unique file name
NSString* filePath;

int i = 1;
do {
filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, cameraPicker.encodingType == EncodingTypePNG ? @"png":@"jpg"];
} while ([fileMgr fileExistsAtPath:filePath]);

// save file
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
}
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
}
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
}
}
// NOT IMAGE TYPE (MOVIE)
Expand Down
53 changes: 31 additions & 22 deletions CordovaLib/Classes/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ Licensed to the Apache Software Foundation (ASF) under one
*/

#import "CDVCapture.h"
#import "JSONKit.h"
#import "CDVJSON.h"
#import "CDVAvailability.h"
#import "CDVViewController.h"

#define kW3CMediaFormatHeight @"height"
#define kW3CMediaFormatWidth @"width"
Expand Down Expand Up @@ -251,7 +250,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
// iOS 4.0
if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]) {
pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
// pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
// pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
// pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
Expand Down Expand Up @@ -329,7 +328,7 @@ - (void)getMediaModes:(CDVInvokedUrlCommand*)command
movieArray ? (NSObject*) movieArray:[NSNull null], @"video",
audioArray ? (NSObject*) audioArray:[NSNull null], @"audio",
nil];
NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", [modes cdvjk_JSONString]];
NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", [modes JSONString]];
[self.commandDelegate evalJs:jsString];
}

Expand Down Expand Up @@ -383,12 +382,20 @@ - (void)getFormatData:(CDVInvokedUrlCommand*)command
AVURLAsset* movieAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil];
CMTime duration = [movieAsset duration];
[formatData setObject:[NSNumber numberWithFloat:CMTimeGetSeconds(duration)] forKey:kW3CMediaFormatDuration];
CGSize size = [movieAsset naturalSize];
[formatData setObject:[NSNumber numberWithFloat:size.height] forKey:kW3CMediaFormatHeight];
[formatData setObject:[NSNumber numberWithFloat:size.width] forKey:kW3CMediaFormatWidth];
// not sure how to get codecs or bitrate???
// AVMetadataItem
// AudioFile

NSArray* allVideoTracks = [movieAsset tracksWithMediaType:AVMediaTypeVideo];
if ([allVideoTracks count] > 0) {
AVAssetTrack* track = [[movieAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGSize size = [track naturalSize];

[formatData setObject:[NSNumber numberWithFloat:size.height] forKey:kW3CMediaFormatHeight];
[formatData setObject:[NSNumber numberWithFloat:size.width] forKey:kW3CMediaFormatWidth];
// not sure how to get codecs or bitrate???
// AVMetadataItem
// AudioFile
} else {
NSLog(@"No video tracks found for %@", fullPath);
}
} else if ([mimeType rangeOfString:@"audio/"].location != NSNotFound) {
if (NSClassFromString(@"AVAudioPlayer") != nil) {
NSURL* fileURL = [NSURL fileURLWithPath:fullPath];
Expand Down Expand Up @@ -521,11 +528,12 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
@implementation CDVAudioNavigationController

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
- (NSUInteger)supportedInterfaceOrientations
{
// delegate to CVDAudioRecorderViewController
return [self.topViewController supportedInterfaceOrientations];
}
- (NSUInteger)supportedInterfaceOrientations
{
// delegate to CVDAudioRecorderViewController
return [self.topViewController supportedInterfaceOrientations];
}

#endif

@end
Expand Down Expand Up @@ -685,14 +693,15 @@ - (void)viewDidLoad
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger orientation = UIInterfaceOrientationMaskPortrait; // must support portrait
NSUInteger supported = [captureCommand.viewController supportedInterfaceOrientations];
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger orientation = UIInterfaceOrientationMaskPortrait; // must support portrait
NSUInteger supported = [captureCommand.viewController supportedInterfaceOrientations];

orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown);
return orientation;
}

orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown);
return orientation;
}
#endif

- (void)viewDidUnload
Expand Down
9 changes: 8 additions & 1 deletion CordovaLib/Classes/CDVCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@

@class CDVPlugin;
@class CDVPluginResult;
@class CDVWhitelist;

@protocol CDVCommandDelegate <NSObject>

@property (nonatomic, readonly) NSDictionary* settings;

- (NSString*)pathForResource:(NSString*)resourcepath;
- (id)getCommandInstance:(NSString*)pluginName;
- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className CDV_DEPRECATED(2.2, "Use CDVViewController to register plugins, or use Cordova.plist.");
- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className CDV_DEPRECATED(2.2, "Use CDVViewController to register plugins, or use config.xml.");

// Plugins should not be using this interface to call other plugins since it
// will result in bogus callbacks being made.
Expand All @@ -44,5 +47,9 @@
- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop;
// Runs the given block on a background thread using a shared thread-pool.
- (void)runInBackground:(void (^)())block;
// Returns the User-Agent of the associated UIWebView.
- (NSString*)userAgent;
// Returns whether the given URL passes the white-list.
- (BOOL)URLIsWhitelisted:(NSURL*)url;

@end
5 changes: 3 additions & 2 deletions CordovaLib/Classes/CDVCommandDelegateImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

@interface CDVCommandDelegateImpl : NSObject <CDVCommandDelegate>{
@private
__unsafe_unretained CDVViewController* _viewController;
__unsafe_unretained CDVCommandQueue* _commandQueue;
__weak CDVViewController* _viewController;
@protected
__weak CDVCommandQueue* _commandQueue;
}
- (id)initWithViewController:(CDVViewController*)viewController;
@end
Loading

0 comments on commit c092faf

Please sign in to comment.