[iphone/Barcodes/ZWingWidget] added ORG and TITLE tag support in Me card ResultParser. This is a bit ahead of the java version

git-svn-id: https://zxing.googlecode.com/svn/trunk@1709 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
rpechayr 2011-01-27 16:45:25 +00:00
parent 6f62deca64
commit b9d867c4aa
21 changed files with 92 additions and 93 deletions

View file

@ -509,10 +509,10 @@
1FB4327D1290295C002D63E8 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
1FF80CDB12A3AB1B00FE297C /* fr */,
1FB4327E1290295C002D63E8 /* de */,
1FB4328E12902968002D63E8 /* en */,
1FB4329512902973002D63E8 /* sv */,
1FF80CDB12A3AB1B00FE297C /* fr */,
);
name = Localizable.strings;
sourceTree = "<group>";
@ -551,6 +551,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Barcodes_Prefix.pch;
GCC_VERSION = 4.2;
INFOPLIST_FILE = "Barcodes-Info.plist";
OTHER_LDFLAGS = (
"-all_load",
@ -567,6 +568,7 @@
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Barcodes_Prefix.pch;
GCC_VERSION = 4.2;
INFOPLIST_FILE = "Barcodes-Info.plist";
PRODUCT_NAME = Barcodes;
VALIDATE_PRODUCT = YES;
@ -584,8 +586,8 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"../ZXingWidget/Classes/**",
../../cpp/core/src,
"../ZXingWidget/Classes/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 4.1;
PREBINDING = NO;
@ -602,6 +604,11 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
../../cpp/core/src,
"../ZXingWidget/Classes/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 4.1;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphoneos;

View file

@ -90,9 +90,9 @@ static Database *sharedDatabase = nil;
sqlite3_bind_double(insertStatement, 3, timeStamp);
sqlite3_step(insertStatement);
sqlite3_reset(insertStatement);
NSDate* theDate = [NSDate dateWithTimeIntervalSince1970:timeStamp];
NSDate* theDate = [[NSDate alloc] initWithTimeIntervalSince1970:timeStamp];
Scan *scan = [[[Scan alloc] initWithIdent:nextScanIdent text:text stamp:theDate] autorelease];
[theDate release];
return scan;
}
@ -100,9 +100,11 @@ static Database *sharedDatabase = nil;
NSMutableArray *scans = [NSMutableArray array];
while (SQLITE_ROW == sqlite3_step(selectAllStatement)) {
int ident = sqlite3_column_int(selectAllStatement, 0);
NSString *text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectAllStatement, 1)];
NSDate *stamp = [NSDate dateWithTimeIntervalSince1970:sqlite3_column_double(selectAllStatement, 2)];
NSString *text = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectAllStatement, 1)];
NSDate *stamp = [[NSDate alloc] initWithTimeIntervalSince1970:sqlite3_column_double(selectAllStatement, 2)];
Scan *scan = [[Scan alloc] initWithIdent:ident text:text stamp:stamp];
[text release];
[stamp release];
[scans addObject:scan];
[scan release];
}

View file

@ -37,4 +37,10 @@
return self;
}
- (void)dealloc {
[stamp release];
[text release];
[super dealloc];
}
@end

View file

@ -19,24 +19,16 @@
@interface ZXMainViewController : UIViewController <ZXingDelegate,UIActionSheetDelegate,ModalViewControllerDelegate> {
NSArray *actions;
ParsedResult *result;
IBOutlet UITextView *resultView;
IBOutlet UIButton *lastActionButton;
}
@property (nonatomic,assign) NSArray *actions;
@property (nonatomic,assign) ParsedResult *result;
@property (nonatomic,retain) IBOutlet UITextView *resultView;
@property (nonatomic,retain) IBOutlet UIButton *lastActionButton;
- (IBAction)scan:(id)sender;
- (IBAction)info:(id)sender;
- (IBAction)showArchive:(id)sender;
- (IBAction)lastResultAction:(id)sender;
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result;
- (void)zxingControllerDidCancel:(ZXingWidgetController*)controller;
- (void)performResultAction;
- (void)setResultViewWithText:(NSString*)theResult;

View file

@ -18,8 +18,6 @@
@implementation ZXMainViewController
@synthesize actions;
@synthesize result;
@synthesize resultView;
@synthesize lastActionButton;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
@ -37,10 +35,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Barcodes";
NSString *rawLatestResult = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastScan"];
if (!rawLatestResult) rawLatestResult = NSLocalizedString(@"Latest result will appear here once you have scanned a barcode at least once",@"Latest result will appear here once you have scanned a barcode at least once");
[self setResultViewWithText:rawLatestResult];
}
@ -80,28 +74,6 @@
[messageController release];
}
- (IBAction)info:(id)sender {
MessageViewController *aboutController =
[[MessageViewController alloc] initWithMessageFilename:@"About"];
aboutController.delegate = self;
//TODO: change this
[self.navigationController pushViewController:aboutController animated:YES];
[aboutController release];
}
- (IBAction)showArchive:(id)sender {
ArchiveController *archiveController = [[ArchiveController alloc] init];
archiveController.delegate = self;
//TODO: change this
[self.navigationController pushViewController:archiveController animated:YES];
[archiveController release];
}
- (IBAction)lastResultAction:(id)sender {
[self performResultAction];
}
- (void)performAction:(ResultAction *)action {
[action performActionWithController:self shouldConfirm:NO];
}
@ -124,52 +96,24 @@
- (void)dealloc {
[resultView release];
[lastActionButton release];
actions = nil;
result = nil;
[super dealloc];
}
- (void)setResultViewWithText:(NSString*)theResult {
ParsedResult *parsedResult = [[UniversalResultParser parsedResultForString:theResult] retain];
NSString *displayString = [parsedResult stringForDisplay];
self.resultView.text = displayString;
self.result = [parsedResult retain];
self.actions = [[parsedResult actions] retain];
NSString *buttonTitle;
if ([self.actions count] == 1) {
ResultAction *theAction = [self.actions objectAtIndex:0];
buttonTitle = [theAction title];
lastActionButton.userInteractionEnabled = YES;
} else if ([self.actions count] == 0) {
lastActionButton.userInteractionEnabled = NO;
buttonTitle = NSLocalizedString(@"No Actions",@"No Actions");
} else {
lastActionButton.userInteractionEnabled = YES;
buttonTitle = NSLocalizedString(@"Actions ...",@"Actions ...");
}
[lastActionButton setTitle:buttonTitle forState: UIControlStateNormal];
}
#pragma mark -
#pragma mark ZXingDelegateMethods
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)resultString {
[self dismissModalViewControllerAnimated:YES];
//ParsedResult *theResult = [UniversalResultParser parsedResultForString:resultString];
//self.result = [theResult retain];
//self.actions = [self.result.actions retain];
[self setResultViewWithText:resultString];
#ifdef DEBUG
NSLog(@"result has %d actions", actions ? 0 : actions.count);
#endif
Scan * scan = [[Database sharedDatabase] addScanWithText:resultString];
[[NSUserDefaults standardUserDefaults] setObject:resultString forKey:@"lastScan"];
//TODO: toggle view into result view that needs to be done.
ParsedResult *parsedResult = [[UniversalResultParser parsedResultForString:resultString] retain];
self.result = [parsedResult retain];
self.actions = [self.result.actions retain];
ScanViewController *scanViewController = [[ScanViewController alloc] initWithResult:parsedResult forScan:scan];
[self.navigationController pushViewController:scanViewController animated:NO];
[scanViewController release];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View file

@ -160,7 +160,7 @@ public:
- (BOOL)decode {
NSAutoreleasePool* mainpool = [[NSAutoreleasePool alloc] init];
TwoDDecoderResult *decoderResult = nil;
BOOL returnCode = NO;
{
//NSSet *formatReaders = [FormatReader formatReaders];
NSSet *formatReaders = self.readers;
@ -205,10 +205,13 @@ public:
[points addObject:[NSValue valueWithCGPoint:p]];
}
NSString *resultString = [NSString stringWithCString:cString
encoding:NSUTF8StringEncoding];
decoderResult = [[TwoDDecoderResult resultWithText:resultString points:points] retain];
//NSString *resultString = [NSString stringWithCString:cString
// encoding:NSUTF8StringEncoding];
NSString *resultString = [[NSString alloc] initWithCString:cString encoding:NSUTF8StringEncoding];
//decoderResult = [[TwoDDecoderResult resultWithText:resultString points:points] retain];
if (decoderResult) [decoderResult release];
decoderResult = [[TwoDDecoderResult alloc] initWithText:resultString points:points];
[resultString release];
[points release];
} catch (ReaderException &rex) {
NSLog(@"failed to decode, caught ReaderException '%s'",
@ -245,8 +248,10 @@ public:
if (decoderResult) {
[self performSelectorOnMainThread:@selector(didDecodeImage:)
withObject:decoderResult
withObject:[decoderResult copy]
waitUntilDone:NO];
[decoderResult release];
returnCode = YES;
} else {
[self performSelectorOnMainThread:@selector(failedToDecodeImage:)
withObject:NSLocalizedString(@"Decoder BarcodeDetectionFailure", @"No barcode detected.")
@ -260,7 +265,7 @@ public:
#endif
[mainpool release];
return decoderResult == nil ? NO : YES;
return returnCode;
}
- (BOOL) decodeImage:(UIImage *)i {

View file

@ -22,9 +22,10 @@
UIImageView *imageView;
NSMutableArray *_points;
UIButton *cancelButton;
UILabel *instructionsLabel;
id<CancelDelegate> delegate;
BOOL oneDMode;
CGRect cropRect;
CGRect cropRect;
}
@property (nonatomic, retain) NSMutableArray* points;

View file

@ -20,6 +20,7 @@ static const CGFloat kPadding = 10;
@interface OverlayView()
@property (nonatomic,assign) UIButton *cancelButton;
@property (nonatomic,retain) UILabel *instructionsLabel;
@end
@ -29,6 +30,7 @@ static const CGFloat kPadding = 10;
@synthesize points = _points;
@synthesize cancelButton;
@synthesize cropRect;
@synthesize instructionsLabel;
////////////////////////////////////////////////////////////////////////////////////////////////////
- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled {
@ -61,6 +63,7 @@ static const CGFloat kPadding = 10;
[self addSubview:cancelButton];
[self addSubview:imageView];
}
}
return self;
}
@ -76,6 +79,7 @@ static const CGFloat kPadding = 10;
- (void) dealloc {
[imageView release];
[_points release];
[instructionsLabel release];
[super dealloc];
}

View file

@ -21,7 +21,7 @@
#import <UIKit/UIKit.h>
@interface TwoDDecoderResult : NSObject {
@interface TwoDDecoderResult : NSObject<NSCopying> {
NSString *text;
NSArray *points;
}
@ -31,5 +31,7 @@
+ (id)resultWithText:(NSString *)text points:(NSArray *)points;
- (id)initWithText:(NSString *)text points:(NSArray *)points;
- (id)copyWithZone:(NSZone *)zone;
- (id)copy;
@end

View file

@ -39,6 +39,15 @@
return self;
}
- (id)copyWithZone:(NSZone *)zone {
TwoDDecoderResult *theCopy = [[TwoDDecoderResult allocWithZone:zone] initWithText:[text copyWithZone:zone] points:[points copyWithZone:zone]];
return theCopy;
}
- (id)copy {
return [self copyWithZone:nil];
}
- (void)dealloc {
[text release];
[points release];

View file

@ -20,6 +20,7 @@
#import "ResultParser.h"
#import "ParsedResult.h"
#import "ResultAction.h"
#import "TwoDDecoderResult.h"
#include <sys/types.h>
#include <sys/sysctl.h>
@ -239,11 +240,13 @@
#endif
}
- (void)presentResultPoints:(NSMutableArray *)resultPoints
- (void)presentResultPoints:(NSArray *)resultPoints
forImage:(UIImage *)image
usingSubset:(UIImage *)subset {
// simply add the points to the image view
[overlayView setPoints:resultPoints];
NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:resultPoints];
[overlayView setPoints:mutableArray];
[mutableArray release];
}
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {

View file

@ -31,6 +31,7 @@
NSString *urlString;
NSString *address;
NSString *organization;
NSString *jobTitle;
UIViewController *viewController;
}
@ -42,6 +43,7 @@
@property (nonatomic, copy) NSString *urlString;
@property (nonatomic, copy) NSString *address;
@property (nonatomic, copy) NSString *organization;
@property (nonatomic, copy) NSString *jobTitle;
+ (id)actionWithName:(NSString *)n
phoneNumbers:(NSArray *)nums
@ -49,6 +51,7 @@
url:(NSString *)us
address:(NSString *)ad
note:(NSString *)nt
organization:(NSString *)org;
organization:(NSString *)org
jobTitle:(NSString *)title;
@end

View file

@ -32,6 +32,7 @@
@synthesize urlString;
@synthesize address;
@synthesize organization;
@synthesize jobTitle;
+ (id)actionWithName:(NSString *)n
phoneNumbers:(NSArray *)nums
@ -39,7 +40,8 @@
url:(NSString *)us
address:(NSString *)ad
note:(NSString *)nt
organization:(NSString *)org {
organization:(NSString *)org
jobTitle:(NSString *)title {
AddContactAction *aca = [[[self alloc] init] autorelease];
aca.name = n;
aca.phoneNumbers = nums;
@ -48,6 +50,7 @@
aca.address = ad;
aca.note = nt;
aca.organization = org;
aca.jobTitle = title;
return aca;
}
@ -96,6 +99,10 @@
ABRecordSetValue(person, kABPersonOrganizationProperty, (CFStringRef)self.organization, error);
}
if (self.jobTitle) {
ABRecordSetValue(person, kABPersonJobTitleProperty, (CFStringRef)self.jobTitle, error);
}
if (self.phoneNumbers && self.phoneNumbers.count > 0) {
// multi-values: nultiple phone numbers
ABMutableMultiValueRef phoneNumberMultiValue =

View file

@ -30,6 +30,7 @@
NSString *urlString;
NSString *address;
NSString *organization;
NSString *jobTitle;
}
@property (nonatomic, copy) NSString *name;
@ -39,5 +40,6 @@
@property (nonatomic, copy) NSString *urlString;
@property (nonatomic, copy) NSString *address;
@property (nonatomic, copy) NSString *organization;
@property (nonatomic, copy) NSString *jobTitle;
@end

View file

@ -31,6 +31,7 @@
@synthesize urlString;
@synthesize address;
@synthesize organization;
@synthesize jobTitle;
- (NSString *)stringForDisplay {
NSMutableString *result = [NSMutableString stringWithString:self.name];
@ -63,7 +64,8 @@
url:self.urlString
address:self.address
note:self.note
organization:self.organization]];
organization:self.organization
jobTitle:self.jobTitle]];
}
- (void) dealloc {
@ -74,6 +76,7 @@
[address release];
[note release];
[organization release];
[jobTitle release];
[super dealloc];
}

View file

@ -58,6 +58,7 @@
int max = [self length];
NSRange searchRange;
NSRange foundRange;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
while (i < max) {
searchRange = NSMakeRange(i, max - i);
foundRange = [self rangeOfString:prefix options:0 range:searchRange];
@ -78,18 +79,20 @@
} else {
NSString *substring = [self substringWithRange:NSMakeRange(start, termRange.location - start)];
NSString *unescaped = [substring backslashUnescaped];
NSString *toBeInArray = [[NSString alloc] initWithString:unescaped];
if (result == nil) {
result = [NSMutableArray arrayWithObject:unescaped];
} else {
[result addObject:unescaped];
result = [[NSMutableArray alloc] initWithCapacity:1];
}
[result addObject:toBeInArray];
[toBeInArray release];
i = termRange.location + termRange.length;
done = true;
}
}
}
[pool release];
return result;
return [result autorelease];
}
- (NSString *)fieldWithPrefix:(NSString *)prefix {

View file

@ -46,7 +46,11 @@
result.note = [s fieldWithPrefix:@"NOTE:"];
result.urlString = [s fieldWithPrefix:@"URL:"];
result.address = [s fieldWithPrefix:@"ADR:"];
//The following tags are not stricty parot of MECARD spec, but as their are standard in
//vcard, we honor them
result.organization = [s fieldWithPrefix:@"ORG:"];
result.jobTitle = [s fieldWithPrefix:@"TITLE:"];
return [result autorelease];
}

View file

@ -1169,6 +1169,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ZXingWidget_Prefix.pch;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = 4.2;
HEADER_SEARCH_PATHS = ../../cpp/core/src;
INSTALL_PATH = /usr/local/lib;
LD_GENERATE_MAP_FILE = YES;
@ -1193,6 +1194,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ZXingWidget_Prefix.pch;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = 4.2;
HEADER_SEARCH_PATHS = ../../cpp/core/src;
INSTALL_PATH = /usr/local/lib;
PRODUCT_NAME = ZXingWidget;
@ -1205,7 +1207,7 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_VERSION = 4.2;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../../cpp/core/src;

View file

@ -1517,7 +1517,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ZXing_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
HEADER_SEARCH_PATHS = ../../cpp/core/src;
HEADER_SEARCH_PATHS = ../../../cpp/core/src;
INFOPLIST_FILE = Info.plist;
PRODUCT_NAME = Barcodes;
};
@ -2005,7 +2005,7 @@
HEADER_SEARCH_PATHS = ../../../cpp/core/src;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = iphoneos4.2;
SDKROOT = iphoneos;
};
name = Debug;
};