2012-02-17 18:14:45 -08:00
|
|
|
// -*- Mode: ObjC; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
/*
|
|
|
|
* Copyright 2010-2012 ZXing authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2010-05-12 11:24:18 -07:00
|
|
|
|
|
|
|
#import "RootViewController.h"
|
2012-02-17 18:14:45 -08:00
|
|
|
|
|
|
|
#ifndef ZXQR
|
|
|
|
#define ZXQR 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ZXQR
|
2010-06-15 15:01:04 -07:00
|
|
|
#import "QRCodeReader.h"
|
2012-02-17 18:14:45 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ZXAZ
|
|
|
|
#define ZXAZ 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ZXAZ
|
|
|
|
#import "AztecReader.h"
|
|
|
|
#endif
|
2010-06-15 15:01:04 -07:00
|
|
|
|
2010-06-19 09:58:19 -07:00
|
|
|
|
2010-05-30 04:40:09 -07:00
|
|
|
@interface RootViewController()
|
|
|
|
|
|
|
|
@end
|
2010-05-12 11:24:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
@implementation RootViewController
|
|
|
|
@synthesize resultsView;
|
2010-05-22 02:17:41 -07:00
|
|
|
@synthesize resultsToDisplay;
|
2010-05-12 11:24:18 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark View lifecycle
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
2010-06-19 09:58:19 -07:00
|
|
|
[super viewDidLoad];
|
2010-08-17 14:18:56 -07:00
|
|
|
[self setTitle:@"ZXing"];
|
|
|
|
[resultsView setText:resultsToDisplay];
|
2010-06-19 09:58:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)scanPressed:(id)sender {
|
|
|
|
|
2010-05-30 04:40:09 -07:00
|
|
|
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
|
2012-02-17 18:14:45 -08:00
|
|
|
|
|
|
|
NSMutableSet *readers = [[NSMutableSet alloc ] init];
|
|
|
|
|
|
|
|
#if ZXQR
|
2010-06-15 15:01:04 -07:00
|
|
|
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
|
2012-02-17 18:14:45 -08:00
|
|
|
[readers addObject:qrcodeReader];
|
2010-06-15 15:01:04 -07:00
|
|
|
[qrcodeReader release];
|
2012-02-17 18:14:45 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ZXAZ
|
|
|
|
AztecReader *aztecReader = [[AztecReader alloc] init];
|
|
|
|
[readers addObject:aztecReader];
|
|
|
|
[aztecReader release];
|
|
|
|
#endif
|
|
|
|
|
2010-06-15 15:01:04 -07:00
|
|
|
widController.readers = readers;
|
|
|
|
[readers release];
|
2012-02-17 18:14:45 -08:00
|
|
|
|
2010-06-19 09:58:19 -07:00
|
|
|
NSBundle *mainBundle = [NSBundle mainBundle];
|
2010-08-17 14:18:56 -07:00
|
|
|
widController.soundToPlay =
|
2012-02-17 18:14:45 -08:00
|
|
|
[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO];
|
2010-08-17 14:18:56 -07:00
|
|
|
[self presentModalViewController:widController animated:YES];
|
2010-05-30 04:40:09 -07:00
|
|
|
[widController release];
|
2010-05-12 11:24:18 -07:00
|
|
|
}
|
|
|
|
|
2010-06-19 09:58:19 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark ZXingDelegateMethods
|
2010-05-12 11:24:18 -07:00
|
|
|
|
2010-06-19 09:58:19 -07:00
|
|
|
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
|
2010-05-22 02:17:41 -07:00
|
|
|
self.resultsToDisplay = result;
|
2010-08-17 14:18:56 -07:00
|
|
|
if (self.isViewLoaded) {
|
|
|
|
[resultsView setText:resultsToDisplay];
|
|
|
|
[resultsView setNeedsDisplay];
|
|
|
|
}
|
|
|
|
[self dismissModalViewControllerAnimated:NO];
|
2010-05-22 02:17:41 -07:00
|
|
|
}
|
|
|
|
|
2010-06-19 09:58:19 -07:00
|
|
|
- (void)zxingControllerDidCancel:(ZXingWidgetController*)controller {
|
|
|
|
[self dismissModalViewControllerAnimated:YES];
|
2010-05-12 11:24:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload {
|
2010-08-17 14:18:56 -07:00
|
|
|
self.resultsView = nil;
|
2010-05-12 11:24:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2010-05-22 02:17:41 -07:00
|
|
|
[resultsView release];
|
|
|
|
[resultsToDisplay release];
|
2010-06-19 09:58:19 -07:00
|
|
|
[super dealloc];
|
2010-05-12 11:24:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|