Navigation Menu

Skip to content

Commit

Permalink
Sync with latest app version
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesu committed Oct 15, 2009
1 parent 8f769c1 commit c6653ef
Show file tree
Hide file tree
Showing 11 changed files with 758 additions and 32 deletions.
Binary file added CameraButton.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
485 changes: 485 additions & 0 deletions CameraOverlay.xib

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Classes/CameraOverlayController.h
@@ -0,0 +1,41 @@
//
// CameraOverlayController.h
// phototest
//
// Created by James Urquhart on 17/09/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "OverlayDesc.h"

@class TestView;

@interface CameraOverlayController : UIViewController {
IBOutlet TestView *theView;
IBOutlet UIToolbar *toolbar;

IBOutlet UIActivityIndicatorView *savingView;
IBOutlet UILabel *savingDesc;

UIImagePickerController *currentPicker;
OverlayDesc *overlay;

int saveCount;
}

@property(nonatomic, retain) TestView *theView;
@property(nonatomic, retain) UIToolbar *toolbar;

@property(nonatomic, retain) UIActivityIndicatorView *savingView;
@property(nonatomic, retain) UILabel *savingDesc;

@property(nonatomic, assign) UIImagePickerController *currentPicker;

@property(nonatomic, assign) bool saving;
@property(nonatomic, retain) OverlayDesc *overlay;

- (void)setCameraToolbar:(BOOL)animated;

@end
168 changes: 168 additions & 0 deletions Classes/CameraOverlayController.m
@@ -0,0 +1,168 @@
//
// CameraOverlayController.m
// phototest
//
// Created by James Urquhart on 17/09/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "CameraOverlayController.h"
#import "phototestAppDelegate.h"
#import "TestView.h"

@implementation CameraOverlayController

@synthesize theView;
@synthesize toolbar;

@synthesize savingView;
@synthesize savingDesc;

@synthesize currentPicker;
@dynamic saving;
@dynamic overlay;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

UIView *myView = self.view;

myView.opaque = NO;
myView.backgroundColor = [UIColor clearColor];

theView = [[TestView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 480.0-54)];
[myView addSubview:theView];
[myView bringSubviewToFront:savingView];
[myView bringSubviewToFront:savingDesc];
self.overlay = overlay;

saveCount = 0;
savingView.hidden = YES;
savingDesc.hidden = YES;

savingDesc.text = NSLocalizedString(@"sav_stat", @"SAVING");

[self setCameraToolbar:NO];
}

- (void)cancelSelect:(id)sender
{
phototestAppDelegate *del = [[UIApplication sharedApplication] delegate];
[del imagePickerControllerDidCancel:del.picker];
}

- (void)cameraSelect:(id)sender
{
[currentPicker takePicture];
}



- (void)setCameraToolbar:(BOOL)animated
{
UIImage *camImg = [UIImage imageNamed:@"CameraButton.png"];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(cancelSelect:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *cameraButton = [[UIBarButtonItem alloc] initWithImage:camImg style:UIBarButtonItemStyleBordered target:self action:@selector(cameraSelect:)];

fixedSpace.width = 42.0;
cameraButton.width = 96.0;

UIEdgeInsets insets = cameraButton.imageInsets;
insets.left = 0.0;
cameraButton.imageInsets = insets;

CGRect frame = toolbar.frame;
frame.origin.y -= 10.0;
toolbar.frame = frame;

NSArray *theItems = [NSArray arrayWithObjects:
cancelButton,
fixedSpace,
cameraButton,
flexSpace,
nil];

[toolbar setItems:theItems animated:animated];

// release allocated items
for (UIView *view in theItems) {
[view release];
}
}

- (void)setSaving:(bool)value
{
bool hidden;

if (value) {
saveCount++;
} else {
saveCount--;
if (saveCount < 0)
saveCount = 0;
}

hidden = saveCount == 0;

savingView.hidden = hidden;
savingDesc.hidden = hidden;

if (!hidden)
[savingView startAnimating];
else
[savingView stopAnimating];

}

- (bool)saving
{
return savingView.hidden;
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.theView = nil;
self.toolbar = nil;

self.savingDesc = nil;
self.savingView = nil;
}

- (void)setOverlay:(OverlayDesc *)theOverlay
{
if (overlay)
[overlay release];

overlay = [theOverlay retain];

theView.theImage = overlay.image;
theView.defaultOpacity = overlay.opacity;
theView.alpha = overlay.opacity;
}

- (OverlayDesc*)overlay
{
return overlay;
}


- (void)dealloc {
[overlay release];
[super dealloc];
}


@end
17 changes: 16 additions & 1 deletion Classes/TestView.m
Expand Up @@ -13,7 +13,7 @@

@implementation TestView

@synthesize theImage;
@dynamic theImage;
@synthesize defaultOpacity;

- (id)initWithFrame:(CGRect)theFrame
Expand All @@ -23,6 +23,7 @@ - (id)initWithFrame:(CGRect)theFrame
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
defaultOpacity = 1.0;
theImage = nil;
}

return self;
Expand All @@ -38,6 +39,20 @@ - (void)animateVisibility:(BOOL)visible
[UIView commitAnimations];
}

- (void)setTheImage:(UIImage*)aImage
{
if (theImage)
[theImage release];
theImage = [aImage retain];

[self setNeedsDisplay];
}

- (UIImage*)theImage
{
return theImage;
}

- (void)drawRect:(CGRect)theFrame
{
[theImage drawInRect:theFrame];
Expand Down
4 changes: 2 additions & 2 deletions Classes/phototestAppDelegate.h
Expand Up @@ -10,6 +10,7 @@

#import <UIKit/UIKit.h>
#import "OverlayPickerController.h"
#import "CameraOverlayController.h"

@class TestView;
@class OverlayDesc;
Expand All @@ -23,8 +24,7 @@
OverlayDesc *overlay;
NSString *docDir;

TestView *theView;
NSTimer *cameraTimer;
CameraOverlayController *overlayController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
Expand Down
55 changes: 27 additions & 28 deletions Classes/phototestAppDelegate.m
Expand Up @@ -84,6 +84,8 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
[control setTitle:locale forState:UIControlStateNormal];
[control setTitle:locale forState:UIControlStateHighlighted];

overlayController = nil;

// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
Expand All @@ -92,14 +94,8 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication*)application
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (cameraTimer) {
[cameraTimer invalidate];
cameraTimer = nil;
}
if (picker)
[picker dismissModalViewControllerAnimated:NO];
if (theView)
[theView removeFromSuperview];
[defaults synchronize];
}

Expand Down Expand Up @@ -142,25 +138,33 @@ - (IBAction)doTakePicture:(id)sender

picker = [[UIImagePickerController alloc] init];

CGAffineTransform trans = CGAffineTransformIdentity;
//trans = CGAffineTransformTranslate(trans, 50, -44);
//trans = CGAffineTransformScale(trans, 1.0, (480.0-44)/480.0);

if (!overlayController) {
overlayController = [[CameraOverlayController alloc] initWithNibName:@"CameraOverlay" bundle:nil];
}

picker.allowsImageEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.cameraViewTransform = trans;
picker.cameraOverlayView = overlayController.view;
[viewController presentModalViewController:picker animated:YES];

CGRect theFrame = window.frame;
theFrame.origin.y += TOOLBAR_OFFSET;
theFrame.size.height -= TOOLBAR_HEIGHT;
theView = [[TestView alloc] initWithFrame:theFrame];
theView.theImage = overlay.image;
theView.defaultOpacity = overlay.opacity;
theView.alpha = overlay.opacity;
[window addSubview:theView];

overlayController.overlay = overlay;
overlayController.currentPicker = picker;
camCheck = false;
camRecheck = false;

cameraTimer = [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(checkCamera:) userInfo:nil repeats:YES];
picker.showsCameraControls = NO;
}

/*
- (void)checkCamera:(NSTimer*)timer
{
bool hasCamera = true;
Expand All @@ -186,12 +190,14 @@ - (void)checkCamera:(NSTimer*)timer
else
[theView animateVisibility:NO];
}
*/

- (void) savedPhotoImage:(UIImage *)image
didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
NSString *message = nil;
overlayController.saving = NO;
if (error) {
message = [error localizedDescription];
} else {
Expand All @@ -207,29 +213,24 @@ - (void) savedPhotoImage:(UIImage *)image
[alert release];
}

- (void)imagePickerController:(UIImagePickerController *)thePicker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
- (void)imagePickerController:(UIImagePickerController *)thePicker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[viewController dismissModalViewControllerAnimated:NO];
[viewController presentModalViewController:thePicker animated:NO];

UIImageWriteToSavedPhotosAlbum(image,
UIImageWriteToSavedPhotosAlbum([info objectForKey:UIImagePickerControllerOriginalImage],
self,
@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),
NULL);

overlayController.saving = YES;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)thePicker
{
overlayController.saving = NO;

[viewController dismissModalViewControllerAnimated:thePicker ? YES : NO];
[picker release];
picker = nil;
[theView removeFromSuperview];
[theView release];
theView = nil;
[cameraTimer invalidate];
cameraTimer = nil;
}


Expand Down Expand Up @@ -277,9 +278,7 @@ - (void)dealloc {
[currentOverlay release];
[overlay release];
[viewController dismissModalViewControllerAnimated:NO];
if (picker) {
[theView release];
}
[overlayController release];
[picker release];
[viewController release];
[window release];
Expand Down

0 comments on commit c6653ef

Please sign in to comment.