-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathELCImagePickerController.m
166 lines (139 loc) · 5.54 KB
/
ELCImagePickerController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// ELCImagePickerController.m
// ELCImagePickerDemo
//
// Created by ELC on 9/9/10.
// Copyright 2010 ELC Technologies. All rights reserved.
//
#import "ELCImagePickerController.h"
#import "ELCAsset.h"
#import "ELCAssetCell.h"
#import "ELCAssetTablePicker.h"
#import "ELCAlbumPickerController.h"
#import <CoreLocation/CoreLocation.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import "EYLargePhotoHeader.h"
#import "ELCConsole.h"
@implementation ELCImagePickerController
//Using auto synthesizers
- (id)initImagePicker
{
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];
self = [super initWithRootViewController:albumPicker];
if (self) {
self.maximumImagesCount = 4;
self.returnsImage = YES;
[albumPicker setParent:self];
self.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
}
return self;
}
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
self.maximumImagesCount = 4;
self.returnsImage = YES;
}
return self;
}
- (ELCAlbumPickerController *)albumPicker
{
return self.viewControllers[0];
}
- (void)setMediaTypes:(NSArray *)mediaTypes
{
self.albumPicker.mediaTypes = mediaTypes;
}
- (NSArray *)mediaTypes
{
return self.albumPicker.mediaTypes;
}
- (void)cancelImagePicker
{
if ([_imagePickerDelegate respondsToSelector:@selector(elcImagePickerControllerDidCancel:)]) {
[_imagePickerDelegate performSelector:@selector(elcImagePickerControllerDidCancel:) withObject:self];
}
}
- (BOOL)shouldSelectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCount
{
BOOL shouldSelect = previousCount < self.maximumImagesCount;
if (!shouldSelect) {
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"Only %d photos please!", nil), self.maximumImagesCount];
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You can only send %d photos at a time.", nil), self.maximumImagesCount];
[[[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"Okay", nil), nil] show];
}
return shouldSelect;
}
- (void)selectedAssets:(NSArray *)assets
{
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
for(ELCAsset *elcasset in assets) {
ALAsset *asset = elcasset.asset;
id obj = [asset valueForProperty:ALAssetPropertyType];
if (!obj) {
continue;
}
NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
CLLocation* wgs84Location = [asset valueForProperty:ALAssetPropertyLocation];
if (wgs84Location) {
[workingDictionary setObject:wgs84Location forKey:ALAssetPropertyLocation];
}
[workingDictionary setObject:obj forKey:UIImagePickerControllerMediaType];
//This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
// ALAssetRepresentation *assetRep = [asset representationForUTI:@"teste"];
if(assetRep != nil) {
if (_returnsImage) {
CGImageRef imgRef = nil;
//defaultRepresentation returns image as it appears in photo picker, rotated and sized,
//so use UIImageOrientationUp when creating our image below.
UIImageOrientation orientation = UIImageOrientationUpMirrored;
if (_returnsOriginalImage) {
imgRef = [assetRep fullResolutionImage];
orientation = [assetRep orientation];
} else {
imgRef = [assetRep fullScreenImage];
}
UIImage *img = [UIImage imageWithCGImage:imgRef
scale:1.0f
orientation:orientation];
[workingDictionary setObject:img forKey:UIImagePickerControllerOriginalImage];
}
[workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];
[returnArray addObject:workingDictionary];
}
}
if (_imagePickerDelegate != nil && [_imagePickerDelegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
[_imagePickerDelegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:returnArray];
} else {
[self popToRootViewControllerAnimated:NO];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
/*
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
*/
return YES;
}
- (BOOL)onOrder
{
return [[ELCConsole mainConsole] onOrder];
}
- (void)setOnOrder:(BOOL)onOrder
{
[[ELCConsole mainConsole] setOnOrder:onOrder];
}
-(BOOL)shouldDeselectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCount{
return NO;
}
@end