[iphone] now decoders need to be injected into ZXingWidgetController to enhance perfo...
[zxing.git] / iphone / ScanTest / Classes / RootViewController.mm
1 //
2 //  RootViewController.m
3 //  ScanTest
4 //
5 //  Created by David Kavanagh on 5/10/10.
6 //  Copyright __MyCompanyName__ 2010. All rights reserved.
7 //
8
9 #import "RootViewController.h"
10 #import "QRCodeReader.h"
11
12 @interface RootViewController()
13 @property (nonatomic,retain) ZXingWidgetController *scanController;
14
15 @end
16
17
18 @implementation RootViewController
19 @synthesize resultsView;
20 @synthesize resultsToDisplay;
21 @synthesize scanController;
22 #pragma mark -
23 #pragma mark View lifecycle
24
25 - (void)viewDidLoad {
26     [super viewDidLoad];
27         [self setTitle:@"ZXing"];
28   
29   ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
30   QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
31   NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
32   [qrcodeReader release];
33   widController.readers = readers;
34   [readers release];
35   
36         self.scanController = widController;
37   [widController release];
38         NSBundle *mainBundle = [NSBundle mainBundle];
39         [scanController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]];
40    
41 }
42
43 - (IBAction)scanPressed:(id)sender {
44   //UIImagePickerController *picker = [[UIImagePickerController alloc] init];
45         [self presentModalViewController:scanController
46                           animated:YES];
47 //      [self.navigationController pushViewController:scanController animated:true];
48 }
49
50 /*
51 - (void)viewWillAppear:(BOOL)animated {
52     [super viewWillAppear:animated];
53 }
54 */
55 /*
56 - (void)viewDidAppear:(BOOL)animated {
57     [super viewDidAppear:animated];
58 }
59 */
60 /*
61 - (void)viewWillDisappear:(BOOL)animated {
62         [super viewWillDisappear:animated];
63 }
64 */
65 /*
66 - (void)viewDidDisappear:(BOOL)animated {
67         [super viewDidDisappear:animated];
68 }
69 */
70
71 /*
72  // Override to allow orientations other than the default portrait orientation.
73 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
74         // Return YES for supported orientations.
75         return (interfaceOrientation == UIInterfaceOrientationPortrait);
76 }
77  */
78
79 #pragma mark Memory management
80
81 - (void)scanResult:(NSString *)result {
82         //[self.resultsView setText:result];
83         [self dismissModalViewControllerAnimated:NO];
84   self.resultsToDisplay = result;
85 }
86
87 - (void)viewWillAppear:(BOOL)animated {
88   if (resultsToDisplay)
89   {
90     [resultsView setText:resultsToDisplay];
91     [resultsView setNeedsDisplay];
92   }
93 }
94
95 - (void)cancelled {
96         [self dismissModalViewControllerAnimated:YES];
97 }
98
99 #pragma mark -
100 #pragma mark Memory management
101
102 - (void)didReceiveMemoryWarning {
103     // Releases the view if it doesn't have a superview.
104     [super didReceiveMemoryWarning];
105     
106     // Relinquish ownership any cached data, images, etc that aren't in use.
107 }
108
109 - (void)viewDidUnload {
110     // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
111     // For example: self.myOutlet = nil;
112 }
113
114
115 - (void)dealloc {
116   [resultsView release];
117         [scanController release];
118   [resultsToDisplay release];
119     [super dealloc];
120 }
121
122
123 @end
124