[iphone][ScanTest] updated after update of ZingWidgetController
[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
13 @interface RootViewController()
14
15 @end
16
17
18 @implementation RootViewController
19 @synthesize resultsView;
20 @synthesize resultsToDisplay;
21 #pragma mark -
22 #pragma mark View lifecycle
23
24 - (void)viewDidLoad {
25   [super viewDidLoad];
26         [self setTitle:@"ZXing"];
27 }
28
29 - (IBAction)scanPressed:(id)sender {
30         
31   ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
32   QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
33   NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
34   [qrcodeReader release];
35   widController.readers = readers;
36   [readers release];
37   NSBundle *mainBundle = [NSBundle mainBundle];
38         [widController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]];
39   [self presentModalViewController:widController
40                           animated:YES];
41   [widController release];
42 }
43
44
45 - (void)viewWillAppear:(BOOL)animated {
46   [super viewWillAppear:animated];
47   if (resultsToDisplay)
48   {
49     [resultsView setText:resultsToDisplay];
50     [resultsView setNeedsDisplay];
51   }
52 }
53
54 /*
55  - (void)viewDidAppear:(BOOL)animated {
56  [super viewDidAppear:animated];
57  }
58  */
59 /*
60  - (void)viewWillDisappear:(BOOL)animated {
61  [super viewWillDisappear:animated];
62  }
63  */
64 /*
65  - (void)viewDidDisappear:(BOOL)animated {
66  [super viewDidDisappear:animated];
67  }
68  */
69
70 /*
71  // Override to allow orientations other than the default portrait orientation.
72  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
73  // Return YES for supported orientations.
74  return (interfaceOrientation == UIInterfaceOrientationPortrait);
75  }
76  */
77
78 #pragma mark -
79 #pragma mark ZXingDelegateMethods
80
81 - (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
82   [self dismissModalViewControllerAnimated:NO];
83   self.resultsToDisplay = result;
84 }
85
86 - (void)zxingControllerDidCancel:(ZXingWidgetController*)controller {
87   [self dismissModalViewControllerAnimated:YES];
88 }
89
90
91 #pragma mark -
92 #pragma mark Memory management
93
94 - (void)didReceiveMemoryWarning {
95   // Releases the view if it doesn't have a superview.
96   [super didReceiveMemoryWarning];
97   
98   // Relinquish ownership any cached data, images, etc that aren't in use.
99 }
100
101 - (void)viewDidUnload {
102   // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
103   // For example: self.myOutlet = nil;
104 }
105
106
107 - (void)dealloc {
108   [resultsView release];
109   [resultsToDisplay release];
110   [super dealloc];
111 }
112
113
114 @end
115