Merge branch 'develop'

This commit is contained in:
CSullivan102
2014-01-10 19:59:33 -05:00
6 changed files with 134 additions and 24 deletions
+45 -1
View File
@@ -1,9 +1,53 @@
cordova-imagePicker
===================
Cordova Plugin For Multiple Image Selection
Cordova Plugin For Multiple Image Selection - currently implemented only for
iOS, Android coming soon.
## Installing the plugin
The plugin conforms to the Cordova plugin specification, it can be installed
using the Cordova / Phonegap command line interface.
```
phonegap plugin add https://github.com/CSullivan102/cordova-imagePicker.git
cordova plugin add https://github.com/CSullivan102/cordova-imagePicker.git
```
## Using the plugin
The plugin creates the object `window.imagePicker` with the method `getPictures(success, fail, options)`
Example:
```javascript
window.imagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, function (error) {
console.log('Error: ' + error);
}, options
);
```
### Options
```javascript
options = {
maximumImagesCount: int,
// max images to be selected, defaults to 15. If this is set to 1, upon
// selection of a single image, the plugin will return it.
width: int,
// width to resize image to (if one of height/width is 0, will resize
// to fit the other while keeping aspect ratio)
height: int,
// height to resize image to
quality: int (0-100)
// quality of resized image, defaults to 100
};
```
This plugin uses the ELCImagePickerController for the iOS image picker.
+28 -2
View File
@@ -14,7 +14,9 @@
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module src="www/imagepicker.js" name="ImagePicker">
<clobbers target="plugins.imagePicker" />
</js-module>
<!-- ios -->
<platform name="ios">
@@ -26,9 +28,33 @@
<header-file src="src/ios/SOSPicker.h" />
<source-file src="src/ios/SOSPicker.m" />
<header-file src="src/ios/ELCImagePicker/ELCAlbumPickerController.h" />
<source-file src="src/ios/ELCImagePicker/ELCAlbumPickerController.m" />
<header-file src="src/ios/ELCImagePicker/ELCAsset.h" />
<source-file src="src/ios/ELCImagePicker/ELCAsset.m" />
<header-file src="src/ios/ELCImagePicker/ELCAssetCell.h" />
<source-file src="src/ios/ELCImagePicker/ELCAssetCell.m" />
<header-file src="src/ios/ELCImagePicker/ELCAssetPickerFilterDelegate.h" />
<header-file src="src/ios/ELCImagePicker/ELCAssetSelectionDelegate.h" />
<header-file src="src/ios/ELCImagePicker/ELCAssetTablePicker.h" />
<source-file src="src/ios/ELCImagePicker/ELCAssetTablePicker.m" />
<header-file src="src/ios/ELCImagePicker/ELCImagePickerController.h" />
<source-file src="src/ios/ELCImagePicker/ELCImagePickerController.m" />
<resource-file src="src/ios/ELCImagePicker/Resources/ELCAlbumPickerController.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/ELCAssetPicker.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/ELCAssetTablePicker.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/Overlay.png" />
<resource-file src="src/ios/ELCImagePicker/Resources/Overlay@2x.png" />
</platform>
<!-- android -->
<platform name="android">
</platform>
</plugin>
</plugin>
@@ -14,8 +14,8 @@
@property (nonatomic, weak) id<ELCAssetSelectionDelegate> parent;
@property (nonatomic, strong) NSMutableArray *assetGroups;
@property (nonatomic, weak) BOOL singleSelection;
@property (nonatomic, weak) BOOL immediateReturn;
@property (nonatomic, assign) BOOL singleSelection;
@property (nonatomic, assign) BOOL immediateReturn;
// optional, can be used to filter the assets displayed
@property (nonatomic, weak) id<ELCAssetPickerFilterDelegate> assetPickerFilterDelegate;
+5 -3
View File
@@ -10,13 +10,15 @@
#import "ELCAlbumPickerController.h"
#import "ELCImagePickerController.h"
@interface SOSPicker : CDVPlugin
@interface SOSPicker : CDVPlugin <ELCImagePickerControllerDelegate, UINavigationControllerDelegate, UIScrollViewDelegate>
@property (copy) NSString* callbackId;
- (void) getPictures:(CDVInvokedUrlCommand *)command;
- (void) elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
- (void) elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;
- (UIImage*)imageByScalingNotCroppingForSize:(UIImage*)anImage toSize:(CGSize)frameSize;
@property (nonatomic, assign) NSInteger width;
@property (nonatomic, assign) NSInteger height;
@property (nonatomic, assign) NSInteger quality;
@end
+25 -12
View File
@@ -19,12 +19,17 @@
@synthesize callbackId;
- (void) getPictures:(CDVInvokedUrlCommand *)command {
NSString* maxPhotos = [command.arguments objectAtIndex:0];
NSDictionary *options = [command.arguments objectAtIndex: 0];
NSInteger maximumImagesCount = [[options objectForKey:@"maximumImagesCount"] integerValue];
self.width = [[options objectForKey:@"width"] integerValue];
self.height = [[options objectForKey:@"height"] integerValue];
self.quality = [[options objectForKey:@"quality"] integerValue];
// Create the an album controller and image picker
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] init];
int max = [maxPhotos intValue];
if (max == 1) {
if (maximumImagesCount == 1) {
albumController.immediateReturn = true;
albumController.singleSelection = true;
} else {
@@ -33,10 +38,11 @@
}
ELCImagePickerController *imagePicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
imagePicker.maximumImagesCount = max;
[albumController setParent:imagePicker];
[imagePicker setDelegate:self];
imagePicker.maximumImagesCount = maximumImagesCount;
imagePicker.returnsOriginalImage = 1;
imagePicker.imagePickerDelegate = self;
albumController.parent = imagePicker;
self.callbackId = command.callbackId;
// Present modally
[self.viewController presentViewController:imagePicker
@@ -54,11 +60,10 @@
UIImage* image = nil;
image = [dict objectForKey:UIImagePickerControllerOriginalImage];
//Hard code this for now...
CGSize targetSize = CGSizeMake(750,960);
CGSize targetSize = CGSizeMake(self.width, self.height);
UIImage* scaledImage = nil;
scaledImage = [self imageByScalingNotCroppingForSize:image toSize:targetSize];
NSData* data = UIImageJPEGRepresentation(scaledImage, 50/100.0f);
NSData* data = UIImageJPEGRepresentation(scaledImage, self.quality/100.0f);
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
NSError* err = nil;
@@ -72,12 +77,16 @@
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
break;
} else {
[resultStrings addObject:[[NSURL fileURLWithPath:filePath] absoluteString]];
}
}
if (nil == result) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings];
}
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings];
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
}
@@ -106,7 +115,11 @@
CGFloat heightFactor = targetHeight / height;
// opposite comparison to imageByScalingAndCroppingForSize in order to contain the image within the given bounds
if (widthFactor > heightFactor) {
if (widthFactor == 0.0) {
scaleFactor = heightFactor;
} else if (heightFactor == 0.0) {
scaleFactor = widthFactor;
} else if (widthFactor > heightFactor) {
scaleFactor = heightFactor; // scale to fit height
} else {
scaleFactor = widthFactor; // scale to fit width
+29 -4
View File
@@ -1,3 +1,4 @@
/*global cordova,window,console*/
/**
* An Image Picker plugin for Cordova
*
@@ -8,10 +9,34 @@ var ImagePicker = function() {
};
ImagePicker.prototype.getPictures = function() {
/*
* success - success callback
* fail - error callback
* options
* .maximumImagesCount
* .maxWidth
* .maxHeight
*/
ImagePicker.prototype.getPictures = function(success, fail, options) {
if (!options) {
options = {};
}
var params = {
maximumImagesCount: options.maximumImagesCount ? options.maximumImagesCount : 15,
width: options.width ? options.width : 0,
height: options.height ? options.height : 0,
quality: options.quality ? options.quality : 100
};
}
return cordova.exec(success, fail, "ImagePicker", "getPictures", [params]);
};
cordova.addContstructor(function() {
cordova.addConstructor(function() {
window.imagePicker = new ImagePicker();
});
// backwards compatibility
window.plugins = window.plugins || {};
window.plugins.imagePicker = window.imagePicker;
console.log("Image Picker Registered under window.imagePicker");
});