//
//  PhotoViewViewController.m
//  PhotoView
//
//  Created by Bill Dudney on 12/12/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//

#import "PhotoViewViewController.h"

@implementation PhotoViewViewController

@synthesize imageView;
@synthesize imagePicker;

/*
//START:code.PhotoViewController.camera.bug
 if([[[UIDevice currentDevice] name] rangeOfString:@"Simulator"].location !=
         NSNotFound) {
 self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 }
//END:code.PhotoViewController.camera.bug
 */

//START:code.PhotoViewController.touchesEnded:withEvent:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  if([[touches anyObject] tapCount] > 1) {
    // bring up image grabber
    if([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeCamera]) { //<label id="code.imagepicker.sourceType"/>
      self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    } else {
      self.imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;
    }
    self.imagePicker.allowsImageEditing = YES; //<label id="code.imagepicker.allowsEditing"/>
    [self presentModalViewController:self.imagePicker animated:YES]; //<label id="code.imagepicker.present.modal"/>
  }
}
//END:code.PhotoViewController.touchesEnded:withEvent:

//START:code.PhotoViewController.didFinish
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
  imageView.image = [info objectForKey:UIImagePickerControllerEditedImage]; //<label id="code.imagepicker.setimage"/>
	[self dismissModalViewControllerAnimated:YES]; //<label id="code.imagepicker.dismiss"/>
}
//END:code.PhotoViewController.didFinish

//START:code.PhotoViewController.didCancel
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
	[self.imagePicker dismissModalViewControllerAnimated:YES];
}
//END:code.PhotoViewController.didCancel

- (void)dealloc {
  self.imageView = nil;
  self.imagePicker = nil;
  [super dealloc];
}

@end
