mirror of
https://gitee.com/shuto/cordova-imagePicker.git
synced 2026-04-16 00:02:54 +08:00
Updated to take correct parameters, allow for 0 in width/height to size to a specific dimension, and updated controller/delegate to work correctly with updated ELCPicker
This commit is contained in:
30
plugin.xml
30
plugin.xml
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,12 +19,18 @@
|
||||
@synthesize callbackId;
|
||||
|
||||
- (void) getPictures:(CDVInvokedUrlCommand *)command {
|
||||
NSString* maxPhotos = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *options = [command.arguments objectAtIndex: 0];
|
||||
|
||||
bool returnsOriginalImage = [[options objectForKey:@"returnsOriginalImage"] boolValue];
|
||||
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 +39,11 @@
|
||||
}
|
||||
|
||||
ELCImagePickerController *imagePicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
|
||||
imagePicker.maximumImagesCount = max;
|
||||
|
||||
[albumController setParent:imagePicker];
|
||||
[imagePicker setDelegate:self];
|
||||
imagePicker.maximumImagesCount = maximumImagesCount;
|
||||
imagePicker.returnsOriginalImage = returnsOriginalImage;
|
||||
imagePicker.imagePickerDelegate = self;
|
||||
|
||||
albumController.parent = imagePicker;
|
||||
self.callbackId = command.callbackId;
|
||||
// Present modally
|
||||
[self.viewController presentViewController:imagePicker
|
||||
@@ -54,11 +61,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 +78,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 +116,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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*global cordova,window,console*/
|
||||
/**
|
||||
* An Image Picker plugin for Cordova
|
||||
*
|
||||
@@ -8,10 +9,36 @@ var ImagePicker = function() {
|
||||
|
||||
};
|
||||
|
||||
ImagePicker.prototype.getPictures = function() {
|
||||
/*
|
||||
* success - success callback
|
||||
* fail - error callback
|
||||
* options
|
||||
* .singleSelection
|
||||
* .maximumImagesCount
|
||||
* .maxWidth
|
||||
* .maxHeight
|
||||
*/
|
||||
ImagePicker.prototype.getPictures = function(success, fail, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
var params = {
|
||||
maximumImagesCount: options.maximumImagesCount ? options.maximumImagesCount : 15,
|
||||
returnsOriginalImage: options.returnsOriginalImage ? options.returnsOriginalImage : 1,
|
||||
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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user