ZXing license link within the scanning view from erikprice. Closes Issue 1075.

git-svn-id: https://zxing.googlecode.com/svn/trunk@2198 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2012-02-17 18:05:17 +00:00
parent 45abf6d9ec
commit bf133c75d7
5 changed files with 83 additions and 11 deletions

View file

@ -1,4 +1,4 @@
/* Add Contact? */
/* Add Contact? */
"AddContactAction alert message" = "Add Contact?";
/* Cancel */
@ -151,3 +151,24 @@
/*Button title when multiple actions are available*/
"Actions ..." = "Actions ...";
/* Place a red line over the bar code to be scanned. */
"OverlayView 1d instructions" = "Place a red line over the bar code to be scanned.";
/* Cancel */
"OverlayView cancel button title" = "Cancel";
/* Place a barcode inside the viewfinder rectangle to scan it. */
"OverlayView displayed message" = "Place a barcode inside the viewfinder rectangle to scan it.";
/* Cancel */
"OverlayView license alert cancel title" = "Cancel";
/* Scanning functionality provided by ZXing library, licensed under Apache License version 2.0. */
"OverlayView license alert message" = "Scanning functionality provided by ZXing library, licensed under Apache License version 2.0.";
/* License */
"OverlayView license alert title" = "License";
/* View License */
"OverlayView license alert view title" = "View License";

View file

@ -35,6 +35,7 @@
@property (nonatomic, assign) CGRect cropRect;
@property (nonatomic, copy) NSString *displayedMessage;
- (id)initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled showLicense:(BOOL)shouldShowLicense;
- (id)initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled;
- (void)setPoint:(CGPoint)point;

View file

@ -1,3 +1,5 @@
// -*- Mode: ObjC; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/**
* Copyright 2009 Jeff Verkoeyen
*
@ -17,9 +19,11 @@
#import "OverlayView.h"
static const CGFloat kPadding = 10;
static const CGFloat kLicenseButtonPadding = 10;
@interface OverlayView()
@property (nonatomic,assign) UIButton *cancelButton;
@property (nonatomic,assign) UIButton *licenseButton;
@property (nonatomic,retain) UILabel *instructionsLabel;
@end
@ -29,12 +33,17 @@ static const CGFloat kPadding = 10;
@synthesize delegate, oneDMode;
@synthesize points = _points;
@synthesize cancelButton;
@synthesize licenseButton;
@synthesize cropRect;
@synthesize instructionsLabel;
@synthesize displayedMessage;
////////////////////////////////////////////////////////////////////////////////////////////////////
- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled {
- (id)initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled {
return [self initWithFrame:theFrame cancelEnabled:isCancelEnabled oneDMode:isOneDModeEnabled showLicense:YES];
}
- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled showLicense:(BOOL)showLicenseButton {
self = [super initWithFrame:theFrame];
if( self ) {
@ -51,7 +60,7 @@ static const CGFloat kPadding = 10;
if (isCancelEnabled) {
UIButton *butt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.cancelButton = butt;
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton setTitle:NSLocalizedStringWithDefaultValue(@"OverlayView cancel button title", nil, [NSBundle mainBundle], @"Cancel", @"Cancel") forState:UIControlStateNormal];
if (oneDMode) {
[cancelButton setTransform:CGAffineTransformMakeRotation(M_PI/2)];
@ -68,6 +77,18 @@ static const CGFloat kPadding = 10;
[self addSubview:cancelButton];
[self addSubview:imageView];
}
if (showLicenseButton) {
self.licenseButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
CGRect lbFrame = [licenseButton frame];
lbFrame.origin.x = self.frame.size.width - licenseButton.frame.size.width - kLicenseButtonPadding;
lbFrame.origin.y = self.frame.size.height - licenseButton.frame.size.height - kLicenseButtonPadding;
[licenseButton setFrame:lbFrame];
[licenseButton addTarget:self action:@selector(showLicenseAlert:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:licenseButton];
}
}
return self;
}
@ -79,6 +100,23 @@ static const CGFloat kPadding = 10;
}
}
- (void)showLicenseAlert:(id)sender {
NSString *title = NSLocalizedStringWithDefaultValue(@"OverlayView license alert title", nil, [NSBundle mainBundle], @"License", @"License");
NSString *message = NSLocalizedStringWithDefaultValue(@"OverlayView license alert message", nil, [NSBundle mainBundle], @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.", @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.");
NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"OverlayView license alert cancel title", nil, [NSBundle mainBundle], @"OK", @"OK");
NSString *viewTitle = NSLocalizedStringWithDefaultValue(@"OverlayView license alert view title", nil, [NSBundle mainBundle], @"View License", @"View License");
UIAlertView *av = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:viewTitle, nil];
[av show];
[av release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView firstOtherButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apache.org/licenses/LICENSE-2.0.html"]];
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
- (void) dealloc {
[imageView release];
@ -135,7 +173,7 @@ static const CGFloat kPadding = 10;
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
if (displayedMessage == nil) {
self.displayedMessage = @"Place a barcode inside the viewfinder rectangle to scan it.";
self.displayedMessage = NSLocalizedStringWithDefaultValue(@"OverlayView displayed message", nil, [NSBundle mainBundle], @"Place a barcode inside the viewfinder rectangle to scan it.", @"Place a barcode inside the viewfinder rectangle to scan it.");
}
CGContextRef c = UIGraphicsGetCurrentContext();
@ -152,11 +190,14 @@ static const CGFloat kPadding = 10;
// CGContextSetStrokeColor(c, white);
CGContextSaveGState(c);
if (oneDMode) {
char *text = "Place a red line over the bar code to be scanned.";
CGContextSelectFont(c, "Helvetica", 15, kCGEncodingMacRoman);
CGContextScaleCTM(c, -1.0, 1.0);
NSString *text = NSLocalizedStringWithDefaultValue(@"OverlayView 1d instructions", nil, [NSBundle mainBundle], @"Place a red line over the bar code to be scanned.", @"Place a red line over the bar code to be scanned.");
UIFont *helvetica15 = [UIFont fontWithName:@"Helvetica" size:15];
CGSize textSize = [text sizeWithFont:helvetica15];
CGContextRotateCTM(c, M_PI/2);
CGContextShowTextAtPoint(c, 74.0, 285.0, text, 49);
// Invert height and width, because we are rotated.
CGPoint textPoint = CGPointMake(self.bounds.size.height / 2 - textSize.width / 2, self.bounds.size.width * -1.0f + 20.0f);
[text drawAtPoint:textPoint withFont:helvetica15];
}
else {
UIFont *font = [UIFont systemFontOfSize:18];

View file

@ -62,6 +62,7 @@
@property (nonatomic, retain) OverlayView *overlayView;
- (id)initWithDelegate:(id<ZXingDelegate>)delegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode;
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode showLicense:(BOOL)shouldShowLicense;
- (BOOL)fixedFocus;
- (void)setTorch:(BOOL)status;

View file

@ -33,6 +33,7 @@
@interface ZXingWidgetController ()
@property BOOL showCancel;
@property BOOL showLicense;
@property BOOL oneDMode;
@property BOOL isStatusBarHidden;
@ -49,22 +50,29 @@
#endif
@synthesize result, delegate, soundToPlay;
@synthesize overlayView;
@synthesize oneDMode, showCancel, isStatusBarHidden;
@synthesize oneDMode, showCancel, showLicense, isStatusBarHidden;
@synthesize readers;
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode {
return [self initWithDelegate:scanDelegate showCancel:shouldShowCancel OneDMode:shouldUseoOneDMode showLicense:YES];
}
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode showLicense:(BOOL)shouldShowLicense {
self = [super init];
if (self) {
[self setDelegate:scanDelegate];
self.oneDMode = shouldUseoOneDMode;
self.showCancel = shouldShowCancel;
self.showLicense = shouldShowLicense;
self.wantsFullScreenLayout = YES;
beepSound = -1;
decoding = NO;
OverlayView *theOverLayView = [[OverlayView alloc] initWithFrame:[UIScreen mainScreen].bounds
cancelEnabled:showCancel
oneDMode:oneDMode];
oneDMode:oneDMode
showLicense:shouldShowLicense];
[theOverLayView setDelegate:self];
self.overlayView = theOverLayView;
[theOverLayView release];