Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
imported photo picker library
Browse files Browse the repository at this point in the history
  • Loading branch information
calebd committed Aug 25, 2011
1 parent 5d7d812 commit 33f121b
Show file tree
Hide file tree
Showing 34 changed files with 11,022 additions and 0 deletions.
4,462 changes: 4,462 additions & 0 deletions Artwork/GCImagePickerControllerCheckGreen.ai

Large diffs are not rendered by default.

Binary file added Artwork/GCImagePickerControllerCheckGreen.psd
Binary file not shown.
Binary file added Artwork/GCImagePickerControllerCheckGreen@2x.psd
Binary file not shown.
4,329 changes: 4,329 additions & 0 deletions Artwork/GCImagePickerControllerFilm Roll.ai

Large diffs are not rendered by default.

Binary file added Artwork/GCImagePickerControllerFilmRoll.psd
Binary file not shown.
Binary file added Artwork/GCImagePickerControllerFilmRoll@2x.psd
Binary file not shown.
Binary file added Artwork/GCImagePickerControllerVideoAsset.psd
Binary file not shown.
Binary file added Artwork/GCImagePickerControllerVideoAsset@2x.psd
Binary file not shown.
54 changes: 54 additions & 0 deletions Classes/ALAssetsLibrary+GCImagePickerControllerAdditions.h
@@ -0,0 +1,54 @@
/*
Copyright (C) 2011 GUI Cocoa, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <AssetsLibrary/AssetsLibrary.h>

@interface ALAssetsLibrary (GCImagePickerControllerAdditions)


/*
get assets groups sorted the same as seen in UIImagePickerController
types: filter group types. pass ALAssetGroupAll for all groups.
filter: filter the types of assets shown. groups with no assets
matching the filter will be omitted.
error: will be populated if no groups can be loaded.
returns: an array of groups.
*/
- (NSArray *)gc_assetGroupsWithTypes:(ALAssetsGroupType)types assetsFilter:(ALAssetsFilter *)filter error:(NSError **)error;

/*
get assets belonging to a certain group.
identifier: the persistent identifier of the group.
filter: filter the types of assets returned.
group: will be populated with the resulting group.
error: will be populated if loading assets fails.
returns: an array of groups.
*/
- (NSArray *)gc_assetsInGroupWithIdentifier:(NSString *)identifier filter:(ALAssetsFilter *)filter group:(ALAssetsGroup **)inGroup error:(NSError **)inError;

@end
134 changes: 134 additions & 0 deletions Classes/ALAssetsLibrary+GCImagePickerControllerAdditions.m
@@ -0,0 +1,134 @@
/*
Copyright (C) 2011 GUI Cocoa, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import "ALAssetsLibrary+GCImagePickerControllerAdditions.h"

@implementation ALAssetsLibrary (GCImagePickerControllerAdditions)
- (NSArray *)gc_assetGroupsWithTypes:(ALAssetsGroupType)types assetsFilter:(ALAssetsFilter *)filter error:(NSError **)inError {

// this will be returned
__block NSMutableArray *groups = nil;

// load groups
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self
enumerateGroupsWithTypes:types
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:filter];
if ([group numberOfAssets]) {
NSNumber *type = [group valueForProperty:ALAssetsGroupPropertyType];
NSMutableArray *groupsByType = [dictionary objectForKey:type];
if (groupsByType == nil) {
groupsByType = [NSMutableArray arrayWithCapacity:1];
[dictionary setObject:groupsByType forKey:type];
}
[groupsByType addObject:group];
}
}
else {

// make our groups array
groups = [[NSMutableArray alloc] init];

// sort groups into final container
NSArray *typeNumbers = [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedInteger:ALAssetsGroupSavedPhotos],
[NSNumber numberWithUnsignedInteger:ALAssetsGroupAlbum],
[NSNumber numberWithUnsignedInteger:ALAssetsGroupEvent],
[NSNumber numberWithUnsignedInteger:ALAssetsGroupFaces],
nil];
for (NSNumber *type in typeNumbers) {
NSArray *groupsByType = [dictionary objectForKey:type];
[groups addObjectsFromArray:groupsByType];
[dictionary removeObjectForKey:type];
}

// get any groups we do not have contants for
for (NSNumber *type in [dictionary keysSortedByValueUsingSelector:@selector(compare:)]) {
NSArray *groupsByType = [dictionary objectForKey:type];
[groups addObjectsFromArray:groupsByType];
[dictionary removeObjectForKey:type];
}

}
}
failureBlock:^(NSError *error) {
if (inError) { *inError = [error retain]; }
groups = [[NSArray alloc] init];
}];

// wait
while (groups == nil) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, NO);
}

// return
if (inError) { [*inError autorelease]; }
return [groups autorelease];

}
- (NSArray *)gc_assetsInGroupWithIdentifier:(NSString *)identifier filter:(ALAssetsFilter *)filter group:(ALAssetsGroup **)inGroup error:(NSError **)inError {

// this will be returned
__block NSMutableArray *assets = nil;

[self
enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
NSString *groupIdentifier = [group valueForProperty:ALAssetsGroupPropertyPersistentID];
if ([groupIdentifier isEqualToString:identifier]) {
[group setAssetsFilter:filter];
assets = [[NSMutableArray alloc] initWithCapacity:[group numberOfAssets]];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) { [assets addObject:result]; }
}];
if (inGroup) { *inGroup = [group retain]; }
*stop = YES;
}
}
else {
if (assets == nil) {
assets = [[NSArray alloc] init];
}
}
}
failureBlock:^(NSError *error) {
if (inError) { *inError = [error retain]; }
assets = [[NSArray alloc] init];
}];

// wait
while (assets == nil) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, NO);
}

// return
if (inGroup) { [*inGroup autorelease]; }
if (inError) { [*inError autorelease]; }
return [assets autorelease];

}
@end
38 changes: 38 additions & 0 deletions Classes/GCIPAssetPickerCell.h
@@ -0,0 +1,38 @@
/*
Copyright (C) 2011 GUI Cocoa, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <UIKit/UIKit.h>

// cell designed to display a grid of assets
@interface GCIPAssetPickerCell : UITableViewCell {

}

// number of columns for the cell to display
@property (nonatomic, assign) NSUInteger numberOfColumns;

// set assets to display and pass a set of selected asset urls
- (void)setAssets:(NSArray *)assets selected:(NSSet *)selected;

@end
102 changes: 102 additions & 0 deletions Classes/GCIPAssetPickerCell.m
@@ -0,0 +1,102 @@
/*
Copyright (C) 2011 GUI Cocoa, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <AssetsLibrary/AssetsLibrary.h>

#import "GCIPAssetPickerCell.h"
#import "GCIPAssetPickerView.h"

@implementation GCIPAssetPickerCell

@synthesize numberOfColumns = __numberOfColumns;

#pragma mark - object methods
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier {
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
return self;
}
- (void)setNumberOfColumns:(NSUInteger)count {

// check for same value
if (count == __numberOfColumns) {
return;
}

// save value
__numberOfColumns = count;

// set needs layout
[self setNeedsLayout];

}
- (void)setAssets:(NSArray *)assets selected:(NSSet *)selected {

// setup stuff
NSUInteger count = [assets count];

for (NSUInteger index = 0; index < self.numberOfColumns; index++) {

// get view
NSUInteger tag = index + 1;
GCIPAssetPickerView *assetView = (GCIPAssetPickerView *)[self.contentView viewWithTag:tag];

// create view if we need one
if (assetView == nil && index < count) {
assetView = [[GCIPAssetPickerView alloc] initWithFrame:CGRectZero];
assetView.tag = tag;
[self.contentView addSubview:assetView];
[assetView release];
}

// setup view
ALAsset *asset = nil;
if (index < count) {
asset = [assets objectAtIndex:index];
NSURL *assetURL = [[asset defaultRepresentation] url];
[assetView setSelected:[selected containsObject:assetURL]];
}
[assetView setAsset:asset];

}

}
- (void)layoutSubviews {
[super layoutSubviews];
CGSize viewSize = self.contentView.bounds.size;
CGSize tileSize = { 0.0, viewSize.height - 4.0 };
NSUInteger columns = self.numberOfColumns;
NSUInteger spaces = columns + 1;
CGFloat totalHorizontalSpace = (CGFloat)spaces * 4.0;
CGFloat occupiedWidth = viewSize.width - totalHorizontalSpace;
tileSize.width = occupiedWidth / (CGFloat)columns;
[self.contentView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
CGRect frame = CGRectMake(4.0 + (4.0 + tileSize.width) * (CGFloat)idx, 0.0, tileSize.width, tileSize.height);
[(UIView *)obj setFrame:frame];
}];
}

@end
38 changes: 38 additions & 0 deletions Classes/GCIPAssetPickerController.h
@@ -0,0 +1,38 @@
/*
Copyright (C) 2011 GUI Cocoa, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <MessageUI/MessageUI.h>

#import "GCIPTableViewController.h"

// select an asset from a given group
@interface GCIPAssetPickerController : GCIPTableViewController
<UIActionSheetDelegate, MFMailComposeViewControllerDelegate> {

}

// the group to browse
@property (nonatomic, copy) NSString *groupIdentifier;

@end

0 comments on commit 33f121b

Please sign in to comment.