Permalink
Browse files

first commit

  • Loading branch information...
1 parent a05bdd9 commit 2db3ab1bc7a797d838a935ec07ac2cea6a6a3b41 @amano amano committed Jun 12, 2011
View
@@ -0,0 +1,6 @@
+tmp
+bin
+build
+*.zip
+tielcimagepicker.xcodeproj/project.xcworkspace
+tielcimagepicker.xcodeproj/xcuserdata
View
@@ -0,0 +1,2 @@
+JpKrayTiELCImagePicker.h
+JpKrayTiELCImagePicker.m
@@ -0,0 +1,35 @@
+//
+// AlbumPickerController.h
+//
+// Created by Matt Tuzzolo on 2/15/11.
+// Copyright 2011 ELC Technologies. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+typedef enum ELCAlbumPickerFilter {
+ kELCAlbumAllAssets = 0,
+ kELCAlbumAllPhotos,
+ kELCAlbumAllVideos
+} ELCAlbumPickerFilter;
+
+@interface ELCAlbumPickerController : UITableViewController {
+
+ NSMutableArray *assetGroups;
+ NSOperationQueue *queue;
+ id parent;
+ ELCAlbumPickerFilter assetFilter;
+ CGFloat cellHeight;
+ NSString *titleForSelection;
+}
+
+@property (nonatomic, assign) id parent;
+@property (nonatomic, retain) NSMutableArray *assetGroups;
+@property (nonatomic, assign) ELCAlbumPickerFilter assetFilter;
+@property (nonatomic, assign) CGFloat cellHeight;
+@property (nonatomic, retain) NSString *titleForSelection;
+
+-(void)selectedAssets:(NSArray*)_assets;
+
+@end
+
@@ -0,0 +1,214 @@
+//
+// AlbumPickerController.m
+//
+// Created by Matt Tuzzolo on 2/15/11.
+// Copyright 2011 ELC Technologies. All rights reserved.
+//
+
+#import <AssetsLibrary/AssetsLibrary.h>
+#import "ELCAlbumPickerController.h"
+#import "ELCImagePickerController.h"
+#import "ELCAssetTablePicker.h"
+#import "ELCAsset.h"
+
+@interface ELCAlbumPickerController ()
+- (ALAssetsFilter *) filter;
+@end
+
+
+@implementation ELCAlbumPickerController
+
+@synthesize parent, assetGroups;
+@synthesize assetFilter;
+@synthesize cellHeight;
+@synthesize titleForSelection;
+
+#pragma mark -
+#pragma mark View lifecycle
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ // Return YES for supported orientations
+ return YES;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ [self.navigationItem setTitle:NSLocalizedString(@"Loading...", @"Title bar text for loading albums")];
+
+ UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self.parent action:@selector(cancelImagePicker)];
+ [self.navigationItem setRightBarButtonItem:cancelButton];
+ [cancelButton release];
+
+ NSMutableArray *tempArray = [[NSMutableArray alloc] init];
+ self.assetGroups = tempArray;
+ [tempArray release];
+
+ // Load Albums into assetGroups
+ dispatch_async(dispatch_get_main_queue(), ^
+ {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ // Group enumerator Block
+ ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop)
+ {
+ if (group == nil)
+ {
+ return;
+ }
+
+ [group setAssetsFilter:[self filter]];
+ if ([group numberOfAssets])
+ {
+ [self.assetGroups addObject:group];
+ }
+
+ // Reload albums
+ [self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES];
+ };
+
+ // Group Enumerator Failure Block
+ ALAssetsLibraryAccessFailureBlock assetGroupEnumberatorFailure = ^(NSError *error) {
+
+ UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Album Error", @"Title for error when enumerating albums") message:[error description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
+ [alert release];
+
+ //NSLog(@"A problem occured %@", [error description]);
+ };
+
+ // Enumerate Albums
+ ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
+ [library enumerateGroupsWithTypes:ALAssetsGroupAll
+ usingBlock:assetGroupEnumerator
+ failureBlock:assetGroupEnumberatorFailure];
+
+
+ [library release];
+ [pool release];
+ });
+}
+
+-(void)reloadTableView {
+
+ [self.tableView reloadData];
+ [self.navigationItem setTitle:NSLocalizedString(@"Select an Album", @"Text for title bar when selecting an album")];
+}
+
+-(void)selectedAssets:(NSArray*)_assets {
+
+ [(ELCImagePickerController*)parent selectedAssets:_assets];
+}
+
+#pragma mark -
+#pragma mark Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ // Return the number of sections.
+ return 1;
+}
+
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ // Return the number of rows in the section.
+ return [assetGroups count];
+}
+
+
+// Customize the appearance of table view cells.
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ static NSString *CellIdentifier = @"Cell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ // Get count
+ ALAssetsGroup *g = (ALAssetsGroup*)[assetGroups objectAtIndex:indexPath.row];
+ [g setAssetsFilter:[self filter]];
+ NSInteger gCount = [g numberOfAssets];
+
+ cell.textLabel.text = [NSString stringWithFormat:@"%@ (%d)",[g valueForProperty:ALAssetsGroupPropertyName], gCount];
+ [cell.imageView setImage:[UIImage imageWithCGImage:[(ALAssetsGroup*)[assetGroups objectAtIndex:indexPath.row] posterImage]]];
+ [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
+
+ return cell;
+}
+
+#pragma mark -
+#pragma mark Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ ELCAssetTablePicker *picker = [[ELCAssetTablePicker alloc] init];
+ picker.parent = self;
+ picker.titleForSelection = self.titleForSelection;
+ if (self.cellHeight == 0)
+ {
+ self.cellHeight = kDefaultHeight;
+ }
+ picker.cellHeight = self.cellHeight;
+
+ // Move me
+ picker.assetGroup = [assetGroups objectAtIndex:indexPath.row];
+ [picker.assetGroup setAssetsFilter:[self filter]];
+
+ [self.navigationController pushViewController:picker animated:YES];
+ [picker release];
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ return 57;
+}
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Relinquish ownership any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
+ // For example: self.myOutlet = nil;
+}
+
+
+- (void)dealloc
+{
+ self.titleForSelection = nil;
+ [assetGroups release];
+ [super dealloc];
+}
+
+- (ALAssetsFilter *) filter
+{
+ switch (self.assetFilter)
+ {
+ case kELCAlbumAllAssets:
+ default:
+ {
+ return [ALAssetsFilter allAssets];
+ }
+
+ case kELCAlbumAllPhotos:
+ {
+ return [ALAssetsFilter allPhotos];
+ }
+
+ case kELCAlbumAllVideos:
+ {
+ return [ALAssetsFilter allVideos];
+ }
+ }
+}
+
+@end
+
View
@@ -0,0 +1,29 @@
+//
+// Asset.h
+//
+// Created by Matt Tuzzolo on 2/15/11.
+// Copyright 2011 ELC Technologies. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <AssetsLibrary/AssetsLibrary.h>
+
+#define kDefaultHeight 75
+
+@interface ELCAsset : UIView {
+ ALAsset *asset;
+ UIImageView *overlayView;
+ BOOL selected;
+ id parent;
+ CGFloat height;
+}
+
+@property (nonatomic, retain) ALAsset *asset;
+@property (nonatomic, assign) id parent;
+@property (nonatomic, assign) CGFloat height;
+
+-(id)initWithAsset:(ALAsset*)_asset;
+-(id)initWithAsset:(ALAsset*)_asset withHeight:(CGFloat) inHeight;
+-(BOOL)selected;
+
+@end
View
@@ -0,0 +1,97 @@
+//
+// Asset.m
+//
+// Created by Matt Tuzzolo on 2/15/11.
+// Copyright 2011 ELC Technologies. All rights reserved.
+//
+
+#import "ELCAsset.h"
+#import "ELCAssetTablePicker.h"
+#import "TiUtils.h"
+
+@implementation ELCAsset
+
+@synthesize asset;
+@synthesize parent;
+@synthesize height;
+
+- (id)initWithFrame:(CGRect)frame {
+ if ((self = [super initWithFrame:frame])) {
+ // Initialization code
+ }
+ return self;
+}
+
+-(id)initWithAsset:(ALAsset*)_asset withHeight:(CGFloat) inHeight {
+
+ if ((self = [super initWithFrame:CGRectMake(0, 0, 0, 0)])) {
+
+ self.asset = _asset;
+
+ if (inHeight == 0)
+ {
+ self.height = kDefaultHeight;
+ }
+ else
+ {
+ self.height = inHeight;
+ }
+
+ CGRect viewFrames = CGRectMake(0, 0, self.height, self.height);
+
+ UIImageView *assetImageView = [[UIImageView alloc] initWithFrame:viewFrames];
+ [assetImageView setContentMode:UIViewContentModeScaleToFill];
+ [assetImageView setImage:[UIImage imageWithCGImage:[self.asset thumbnail]]];
+ [self addSubview:assetImageView];
+ [assetImageView release];
+
+ NSString *resourceurl = [[NSBundle mainBundle] resourcePath];
+ NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/modules/%@/%@",resourceurl,@"jp.kray.ti.ELCImagePicker",@"Overlay.png"]];
+ UIImage *overlayImage = [UIImage imageWithContentsOfFile:[url path]];
+ overlayView = [[UIImageView alloc] initWithFrame:viewFrames];
+ [overlayView setImage:overlayImage];
+ [overlayView setHidden:YES];
+ [self addSubview:overlayView];
+ }
+
+ return self;
+}
+
+-(id)initWithAsset:(ALAsset*)_asset {
+ return [self initWithAsset:_asset withHeight:0];
+}
+
+
+-(void)toggleSelection {
+
+ overlayView.hidden = !overlayView.hidden;
+
+// if([(ELCAssetTablePicker*)self.parent totalSelectedAssets] >= 10) {
+//
+// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Maximum Reached" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
+// [alert show];
+// [alert release];
+//
+// [(ELCAssetTablePicker*)self.parent doneAction:nil];
+// }
+}
+
+-(BOOL)selected {
+
+ return !overlayView.hidden;
+}
+
+-(void)setSelected:(BOOL)_selected {
+
+ [overlayView setHidden:!_selected];
+}
+
+- (void)dealloc
+{
+ self.asset = nil;
+ [overlayView release];
+ [super dealloc];
+}
+
+@end
+
Oops, something went wrong.

0 comments on commit 2db3ab1

Please sign in to comment.