a scan widget you can include in your iPhone app. Test app coming shortly.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1353 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dkavanagh 2010-05-12 18:13:27 +00:00
parent 0e0bed8b50
commit 422eae3e81
77 changed files with 9347 additions and 0 deletions

View file

@ -0,0 +1,51 @@
//
// AddContactAction.h
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultAction.h"
#import "AddressBookUI/AddressBookUI.h"
@interface AddContactAction : ResultAction <ABUnknownPersonViewControllerDelegate> {
NSString *name;
NSArray *phoneNumbers;
NSString *note;
NSString *email;
NSString *urlString;
NSString *address;
UIViewController *viewController;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, retain) NSArray *phoneNumbers;
@property (nonatomic, copy) NSString *note;
@property (nonatomic, copy) NSString *email;
@property (nonatomic, copy) NSString *urlString;
@property (nonatomic, copy) NSString *address;
+ (id)actionWithName:(NSString *)n
phoneNumbers:(NSArray *)nums
email:(NSString *)em
url:(NSString *)us
address:(NSString *)ad
note:(NSString *)nt;
@end

View file

@ -0,0 +1,224 @@
//
// AddContactAction.m
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import "AddContactAction.h"
#import "AddressBook/AddressBook.h"
@implementation AddContactAction
@synthesize name;
@synthesize phoneNumbers;
@synthesize note;
@synthesize email;
@synthesize urlString;
@synthesize address;
+ (id)actionWithName:(NSString *)n
phoneNumbers:(NSArray *)nums
email:(NSString *)em
url:(NSString *)us
address:(NSString *)ad
note:(NSString *)nt {
AddContactAction *aca = [[[self alloc] init] autorelease];
aca.name = n;
aca.phoneNumbers = nums;
aca.email = em;
aca.urlString = us;
aca.address = ad;
aca.note = nt;
return aca;
}
- (NSString *)title {
return NSLocalizedString(@"AddContactAction title", @"Add Contact");
}
- (void) addContactWithController:(UIViewController *)controller {
CFErrorRef *error = NULL;
NSCharacterSet *whitespaceSet = [NSCharacterSet whitespaceCharacterSet];
ABRecordRef person = ABPersonCreate();
NSRange commaRange = [name rangeOfString:@","];
if (commaRange.location != NSNotFound) {
NSString *lastName = [[name substringToIndex:commaRange.location]
stringByTrimmingCharactersInSet:whitespaceSet];
ABRecordSetValue(person, kABPersonLastNameProperty, lastName, error);
NSArray *firstNames = [[[name substringFromIndex:commaRange.location + commaRange.length]
stringByTrimmingCharactersInSet:whitespaceSet]
componentsSeparatedByCharactersInSet:whitespaceSet];
ABRecordSetValue(person, kABPersonFirstNameProperty, [firstNames objectAtIndex:0], error);
for (int i = 1; i < [firstNames count]; i++) {
ABRecordSetValue(person, kABPersonMiddleNameProperty, [firstNames objectAtIndex:1], error);
}
} else {
NSArray *nameParts = [name componentsSeparatedByCharactersInSet:whitespaceSet];
int nParts = nameParts.count;
if (nParts == 1) {
ABRecordSetValue(person, kABPersonFirstNameProperty, name, error);
} else if (nParts >= 2) {
int lastPart = nParts - 1;
ABRecordSetValue(person, kABPersonFirstNameProperty, [nameParts objectAtIndex:0], error);
for (int i = 1; i < lastPart; i++) {
ABRecordSetValue(person, kABPersonMiddleNameProperty, [nameParts objectAtIndex:i], error);
}
ABRecordSetValue(person, kABPersonLastNameProperty, [nameParts objectAtIndex:lastPart], error);
}
}
if (self.note) {
ABRecordSetValue(person, kABPersonNoteProperty, self.note, error);
}
if (self.phoneNumbers && self.phoneNumbers.count > 0) {
// multi-values: nultiple phone numbers
ABMutableMultiValueRef phoneNumberMultiValue =
ABMultiValueCreateMutable(kABStringPropertyType);
for (NSString *number in self.phoneNumbers) {
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, number,
kABPersonPhoneMainLabel, NULL);
}
ABRecordSetValue(person, kABPersonPhoneProperty,
phoneNumberMultiValue, error);
CFRelease(phoneNumberMultiValue);
}
if (self.email) {
// a single email address
ABMutableMultiValueRef emailMultiValue =
ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(emailMultiValue, self.email,
kABHomeLabel, NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, error);
CFRelease(emailMultiValue);
}
if (self.urlString) {
// a single url as the home page
ABMutableMultiValueRef urlMultiValue =
ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(urlMultiValue, self.urlString,
kABPersonHomePageLabel, NULL);
ABRecordSetValue(person, kABPersonURLProperty, urlMultiValue, error);
CFRelease(urlMultiValue);
}
if (self.address) {
// we can't parse all the possible address formats, alas, so we punt by putting
// the entire thing into a multi-line 'street' address.
// This won't look great on the phone, but at least the info will be there,
// and can be syned to a desktop computer, adjusted as necessary, and so on.
// split the address into parts at each comma or return
NSArray *parts =
[self.address componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@",;\r\n"]];
NSMutableArray *strippedParts = [NSMutableArray arrayWithCapacity:[parts count]];
// for each part:
for (NSString *part in parts) {
// strip the part of whitespace
NSString *strippedPart =
[part stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if ([strippedPart length] > 0) {
// if there is anything in this address part, add it to the list of stripped parts
[strippedParts addObject:strippedPart];
}
}
// finally, create a 'street' address by concatenating all the stripped parts, separated by linefeeds
NSString *street = [strippedParts componentsJoinedByString:@"\n"];
CFMutableDictionaryRef addressDict =
CFDictionaryCreateMutable(NULL,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(addressDict, kABPersonAddressStreetKey, street);
ABMutableMultiValueRef addressMultiValue =
ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(addressMultiValue,
addressDict,
kABHomeLabel,
NULL);
ABRecordSetValue(person, kABPersonAddressProperty, addressMultiValue, error);
CFRelease(addressMultiValue);
CFRelease(addressDict);
}
ABUnknownPersonViewController *unknownPersonViewController =
[[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = person;
unknownPersonViewController.allowsActions = true;
unknownPersonViewController.allowsAddingToAddressBook = true;
unknownPersonViewController.unknownPersonViewDelegate = self;
CFRelease(person);
viewController = [controller retain];
[[viewController navigationController] pushViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
// perform the action
[self addContactWithController:viewController];
}
}
#ifdef CONFIRM_ADDING_CONTACT
#undef CONFIRM_ADDING_CONTACT
#endif
- (void)performActionWithController:(UIViewController *)controller
shouldConfirm:(bool)confirm {
#ifdef CONFIRM_ADDING_CONTACT
if (confirm) {
viewController = controller;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:NSLocalizedString(@"AddContactAction alert message", @"Add Contact?")
delegate:self
cancelButtonTitle:NSLocalizedString(@"AddContactAction cancel button title", @"Cancel")
otherButtonTitles:NSLocalizedString(@"AddContactAction confirm button title", @"Add Contact"), nil];
[alertView show];
[alertView release];
} else {
#endif
[self addContactWithController:controller];
#ifdef CONFIRM_ADDING_CONTACT
}
#endif
}
- (void)dismissUnknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonViewController {
[[viewController navigationController] popToViewController:viewController animated:YES];
[viewController release];
viewController = nil;
}
// ABUnknownPersonViewControllerDelegate
- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonViewController
didResolveToPerson:(ABRecordRef)person {
if (person) {
[self performSelector:@selector(dismissUnknownPersonViewController:) withObject:unknownPersonViewController afterDelay:0.0];
}
}
@end

View file

@ -0,0 +1,29 @@
//
// BookmarkDoCoMoResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "DoCoMoResultParser.h"
@interface BookmarkDoCoMoResultParser : DoCoMoResultParser {
}
@end

View file

@ -0,0 +1,49 @@
//
// BookmarkDoCoMoResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "BookmarkDoCoMoResultParser.h"
#import "URIParsedResult.h"
@implementation BookmarkDoCoMoResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange foundRange = [s rangeOfString:@"MEBKM:"];
if (foundRange.location == NSNotFound) {
return nil;
}
NSString *urlString = [s fieldWithPrefix:@"URL:"];
if (urlString == nil) {
return nil;
}
NSString *title = [s fieldWithPrefix:@"TITLE:"];
return [[[URIParsedResult alloc] initWithURLString:urlString
title:title] autorelease];
}
@end

View file

@ -0,0 +1,41 @@
//
// AddressBookDoCoMoParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface BusinessCardParsedResult : ParsedResult {
NSString *name;
NSArray *phoneNumbers;
NSString *note;
NSString *email;
NSString *urlString;
NSString *address;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, retain) NSArray *phoneNumbers;
@property (nonatomic, copy) NSString *note;
@property (nonatomic, copy) NSString *email;
@property (nonatomic, copy) NSString *urlString;
@property (nonatomic, copy) NSString *address;
@end

View file

@ -0,0 +1,84 @@
//
// AddressBookDoCoMoParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import "BusinessCardParsedResult.h"
#import "AddContactAction.h"
@implementation BusinessCardParsedResult
@synthesize name;
@synthesize phoneNumbers;
@synthesize note;
@synthesize email;
@synthesize urlString;
@synthesize address;
- (NSString *)stringForDisplay {
NSMutableString *result = [NSMutableString stringWithString:self.name];
if (self.phoneNumbers) {
for (NSString *number in self.phoneNumbers) {
[result appendFormat:@"\n%@", number];
}
}
if (self.email) {
[result appendFormat:@"\n%@", self.email];
}
if (self.urlString) {
[result appendFormat:@"\n%@", self.urlString];
}
if (self.note) {
[result appendFormat:@"\n%@", self.note];
}
if (self.address) {
[result appendFormat:@"\n%@", self.address];
}
return [NSString stringWithString:result];
}
- (void)populateActions {
[actions addObject:[AddContactAction actionWithName:self.name
phoneNumbers:self.phoneNumbers
email:self.email
url:self.urlString
address:self.address
note:self.note]];
}
- (void) dealloc {
[name release];
[phoneNumbers release];
[email release];
[urlString release];
[address release];
[note release];
[super dealloc];
}
+ (NSString *)typeName {
return NSLocalizedString(@"Contact Result Type Name", @"Contact");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"business-card.png"];
}
@end

View file

@ -0,0 +1,36 @@
//
// CallAction.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "OpenUrlAction.h"
@interface CallAction : OpenUrlAction {
NSString *number;
}
@property (nonatomic, copy) NSString *number;
+ (NSURL *)urlForNumber:(NSString *)number;
- (id)initWithNumber:(NSString *)number;
+ (id)actionWithNumber:(NSString *)number;
@end

View file

@ -0,0 +1,67 @@
//
// CallAction.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "CallAction.h"
@implementation CallAction
@synthesize number;
+ (NSURL *)urlForNumber:(NSString *)number {
NSString *urlString = [NSString stringWithFormat:@"tel:%@", number];
return [NSURL URLWithString:urlString];
}
- (id)initWithNumber:(NSString *)n {
if ((self = [super initWithURL:[[self class] urlForNumber:n]]) != nil) {
self.number = n;
}
return self;
}
+ (id)actionWithNumber:(NSString *)number {
return [[[self alloc] initWithNumber:number] autorelease];
}
- (NSString *)title {
return [NSString localizedStringWithFormat:NSLocalizedString(@"CallAction action title", @"Call %@"), self.number];
}
- (NSString *)alertTitle {
return NSLocalizedString(@"CallAction alert title", @"Call");
}
- (NSString *)alertMessage {
return [NSString localizedStringWithFormat:NSLocalizedString(@"CallAction alert message", @"Call %@?"), self.number];
}
- (NSString *)alertButtonTitle {
return NSLocalizedString(@"CallAction alert button title", @"Call");
}
- (void) dealloc {
[number release];
[super dealloc];
}
@end

View file

@ -0,0 +1,49 @@
//
// Decoder.h
// ZXing
//
// Created by Christian Brunschen on 31/03/2008.
//
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "DecoderDelegate.h"
@interface Decoder : NSObject {
UIImage *image;
CGRect cropRect;
UIImage *subsetImage;
unsigned char *subsetData;
size_t subsetWidth;
size_t subsetHeight;
size_t subsetBytesPerRow;
id<DecoderDelegate> delegate;
}
@property(nonatomic, retain) UIImage *image;
@property(nonatomic, assign) CGRect cropRect;
@property(nonatomic, retain) UIImage *subsetImage;
@property(nonatomic, assign) unsigned char *subsetData;
@property(assign) size_t subsetWidth;
@property(assign) size_t subsetHeight;
@property(assign) size_t subsetBytesPerRow;
@property(nonatomic, assign) id<DecoderDelegate> delegate;
- (void) decodeImage:(UIImage *)image;
- (void) decodeImage:(UIImage *)image cropRect:(CGRect)cropRect;
@end

View file

@ -0,0 +1,267 @@
//
// Decoder.m
// ZXing
//
// Created by Christian Brunschen on 31/03/2008.
//
/*
* Copyright 2008 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.
*/
#import "Decoder.h"
#import "TwoDDecoderResult.h"
#import "FormatReader.h"
#include <zxing/BinaryBitmap.h>
#include <zxing/ReaderException.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include "GrayBytesMonochromeBitmapSource.h"
using namespace zxing;
@implementation Decoder
@synthesize image;
@synthesize cropRect;
@synthesize subsetImage;
@synthesize subsetData;
@synthesize subsetWidth;
@synthesize subsetHeight;
@synthesize subsetBytesPerRow;
@synthesize delegate;
- (void)willDecodeImage {
if ([self.delegate respondsToSelector:@selector(decoder:willDecodeImage:usingSubset:)]) {
[self.delegate decoder:self willDecodeImage:self.image usingSubset:self.subsetImage];
}
}
- (void)progressDecodingImage:(NSString *)progress {
if ([self.delegate respondsToSelector:@selector(decoder:decodingImage:usingSubset:progress:)]) {
[self.delegate decoder:self decodingImage:self.image usingSubset:self.subsetImage progress:progress];
}
}
- (void)didDecodeImage:(TwoDDecoderResult *)result {
if ([self.delegate respondsToSelector:@selector(decoder:didDecodeImage:usingSubset:withResult:)]) {
[self.delegate decoder:self didDecodeImage:self.image usingSubset:self.subsetImage withResult:result];
}
}
- (void)failedToDecodeImage:(NSString *)reason {
if ([self.delegate respondsToSelector:@selector(decoder:failedToDecodeImage:usingSubset:reason:)]) {
[self.delegate decoder:self failedToDecodeImage:self.image usingSubset:self.subsetImage reason:reason];
}
}
#define SUBSET_SIZE 320.0
- (void) prepareSubset {
CGSize size = [image size];
#ifdef DEBUG
NSLog(@"decoding: image is (%.1f x %.1f), cropRect is (%.1f,%.1f)x(%.1f,%.1f)", size.width, size.height,
cropRect.origin.x, cropRect.origin.y, cropRect.size.width, cropRect.size.height);
#endif
float scale = fminf(1.0f, fmaxf(SUBSET_SIZE / cropRect.size.width, SUBSET_SIZE / cropRect.size.height));
CGPoint offset = CGPointMake(-cropRect.origin.x, -cropRect.origin.y);
#ifdef DEBUG
NSLog(@" offset = (%.1f, %.1f), scale = %.3f", offset.x, offset.y, scale);
#endif
subsetWidth = cropRect.size.width * scale;
subsetHeight = cropRect.size.height * scale;
subsetBytesPerRow = ((subsetWidth + 0xf) >> 4) << 4;
#ifdef DEBUG
NSLog(@"decoding: image to decode is (%d x %d) (%d bytes/row)", subsetWidth, subsetHeight, subsetBytesPerRow);
#endif
subsetData = (unsigned char *)malloc(subsetBytesPerRow * subsetHeight);
#ifdef DEBUG
NSLog(@"allocated %d bytes of memory", subsetBytesPerRow * subsetHeight);
#endif
CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef ctx =
CGBitmapContextCreate(subsetData, subsetWidth, subsetHeight,
8, subsetBytesPerRow, grayColorSpace,
kCGImageAlphaNone);
CGColorSpaceRelease(grayColorSpace);
CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
CGContextSetAllowsAntialiasing(ctx, false);
// adjust the coordinate system
CGContextTranslateCTM(ctx, 0.0, subsetHeight);
CGContextScaleCTM(ctx, 1.0, -1.0);
#ifdef DEBUG
NSLog(@"created %dx%d bitmap context", subsetWidth, subsetHeight);
#endif
UIGraphicsPushContext(ctx);
CGRect rect = CGRectMake(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
#ifdef DEBUG
NSLog(@"rect for image = (%.1f,%.1f)x(%.1f,%.1f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
#endif
[image drawInRect:rect];
UIGraphicsPopContext();
#ifdef DEBUG
NSLog(@"drew image into %d(%d)x%d bitmap context", subsetWidth, subsetBytesPerRow, subsetHeight);
#endif
CGContextFlush(ctx);
#ifdef DEBUG
NSLog(@"flushed context");
#endif
CGImageRef subsetImageRef = CGBitmapContextCreateImage(ctx);
#ifdef DEBUG
NSLog(@"created CGImage from context");
#endif
self.subsetImage = [UIImage imageWithCGImage:subsetImageRef];
// for debug purposes.
UIImageWriteToSavedPhotosAlbum(self.subsetImage, nil, nil, nil);
CGImageRelease(subsetImageRef);
CGContextRelease(ctx);
#ifdef DEBUG
NSLog(@"released context");
#endif
}
- (void)decode:(id)arg {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
{
NSSet *formatReaders = [FormatReader formatReaders];
Ref<LuminanceSource> source (new GrayBytesMonochromeBitmapSource(subsetData, subsetWidth, subsetHeight, subsetBytesPerRow));
Ref<Binarizer> binarizer (new GlobalHistogramBinarizer(source));
Ref<BinaryBitmap> grayImage (new BinaryBitmap(binarizer));
#ifdef DEBUG
NSLog(@"created GrayBytesMonochromeBitmapSource", subsetWidth, subsetHeight);
NSLog(@"grayImage count = %d", grayImage->count());
#endif
TwoDDecoderResult *decoderResult = nil;
#ifdef TRY_ROTATIONS
for (int i = 0; !decoderResult && i < 4; i++) {`
#endif
for (FormatReader *reader in formatReaders) {
try {
#ifdef DEBUG
NSLog(@"decoding gray image");
#endif
Ref<Result> result([reader decode:grayImage]);
#ifdef DEBUG
NSLog(@"gray image decoded");
#endif
Ref<String> resultText(result->getText());
const char *cString = resultText->getText().c_str();
const std::vector<Ref<ResultPoint> > &resultPoints = result->getResultPoints();
NSMutableArray *points =
[NSMutableArray arrayWithCapacity:resultPoints.size()];
for (size_t i = 0; i < resultPoints.size(); i++) {
const Ref<ResultPoint> &rp = resultPoints[i];
CGPoint p = CGPointMake(rp->getX(), rp->getY());
[points addObject:[NSValue valueWithCGPoint:p]];
}
NSString *resultString = [NSString stringWithCString:cString
encoding:NSUTF8StringEncoding];
decoderResult = [TwoDDecoderResult resultWithText:resultString
points:points];
} catch (ReaderException &rex) {
NSLog(@"failed to decode, caught ReaderException '%s'",
rex.what());
} catch (IllegalArgumentException &iex) {
NSLog(@"failed to decode, caught IllegalArgumentException '%s'",
iex.what());
} catch (...) {
NSLog(@"Caught unknown exception!");
}
}
#ifdef TRY_ROTATIONS
if (!decoderResult) {
#ifdef DEBUG
NSLog(@"rotating gray image");
#endif
grayImage = grayImage->rotateCounterClockwise();
#ifdef DEBUG
NSLog(@"gray image rotated");
#endif
}
}
#endif
if (decoderResult) {
[self performSelectorOnMainThread:@selector(didDecodeImage:)
withObject:decoderResult
waitUntilDone:NO];
} else {
[self performSelectorOnMainThread:@selector(failedToDecodeImage:)
withObject:NSLocalizedString(@"Decoder BarcodeDetectionFailure", @"No barcode detected.")
waitUntilDone:NO];
}
free(subsetData);
self.subsetData = NULL;
}
[pool drain];
#ifdef DEBUG
NSLog(@"finished decoding.");
#endif
// if this is not the main thread, then we end it
if (![NSThread isMainThread]) {
[NSThread exit];
}
}
- (void) decodeImage:(UIImage *)i {
[self decodeImage:i cropRect:CGRectMake(0.0f, 0.0f, image.size.width, image.size.height)];
}
- (void) decodeImage:(UIImage *)i cropRect:(CGRect)cr {
self.image = i;
self.cropRect = cr;
[self prepareSubset];
[self willDecodeImage];
[self performSelectorOnMainThread:@selector(progressDecodingImage:)
withObject:NSLocalizedString(@"Decoder MessageWhileDecoding", @"Decoding ...")
waitUntilDone:NO];
[NSThread detachNewThreadSelector:@selector(decode:)
toTarget:self
withObject:nil];
}
- (void) dealloc {
[image release];
[subsetImage release];
if (subsetData) free(subsetData);
[super dealloc];
}
@end

View file

@ -0,0 +1,34 @@
//
// DecoderDelegate.h
// ZXing
//
// Created by Christian Brunschen on 01/04/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
@class Decoder;
@class TwoDDecoderResult;
@protocol DecoderDelegate<NSObject>
@optional
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset;
- (void)decoder:(Decoder *)decoder decodingImage:(UIImage *)image usingSubset:(UIImage *)subset progress:(NSString *)message;
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)result;
- (void)decoder:(Decoder *)decoder failedToDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset reason:(NSString *)reason;
@end

View file

@ -0,0 +1,38 @@
//
// DoCoMoResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface NSString (DoCoMoFieldParsing)
- (NSString *)backslashUnescaped;
- (NSArray *)fieldsWithPrefix:(NSString *)prefix;
- (NSArray *)fieldsWithPrefix:(NSString *)prefix terminator:(NSString *)term;
- (NSString *)fieldWithPrefix:(NSString *)prefix;
- (NSString *)fieldWithPrefix:(NSString *)prefix terminator:(NSString *)term;
@end
@interface DoCoMoResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,114 @@
//
// DoCoMoResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "DoCoMoResultParser.h"
@implementation NSString (DoCoMoFieldParsing)
- (NSString *)backslashUnescaped {
NSRange backslashRange = [self rangeOfString:@"\\"];
if (backslashRange.location == NSNotFound) {
return self;
}
int max = [self length];
int startLocation = 0;
NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
while (backslashRange.location != NSNotFound) {
[result appendString:[self substringWithRange:NSMakeRange(startLocation,
backslashRange.location - startLocation)]];
[result appendFormat:@"%c", [self characterAtIndex:backslashRange.location + 1]];
startLocation = backslashRange.location + 2;
NSRange searchRange = NSMakeRange(startLocation, max - startLocation);
backslashRange = [self rangeOfString:@"\\" options:0 range:searchRange];
}
if (startLocation < max) {
[result appendString:[self substringWithRange:NSMakeRange(startLocation, max - startLocation)]];
}
return [NSString stringWithString:result];
}
- (NSArray *)fieldsWithPrefix:(NSString *)prefix {
return [self fieldsWithPrefix:prefix terminator:@";"];
}
- (NSArray *)fieldsWithPrefix:(NSString *)prefix terminator:(NSString *)term {
NSMutableArray *result = nil;
int i = 0;
int max = [self length];
NSRange searchRange;
NSRange foundRange;
while (i < max) {
searchRange = NSMakeRange(i, max - i);
foundRange = [self rangeOfString:prefix options:0 range:searchRange];
if(foundRange.location == NSNotFound) {
break;
}
int start = i = foundRange.location + foundRange.length;
bool done = false;
while (!done) {
searchRange = NSMakeRange(i, max - i);
NSRange termRange = [self rangeOfString:term options:0 range:searchRange];
if (termRange.location == NSNotFound) {
i = max;
done = true;
} else if ([self characterAtIndex:termRange.location-1] == (unichar)'\\') {
i++;
} else {
NSString *substring = [self substringWithRange:NSMakeRange(start, termRange.location - start)];
NSString *unescaped = [substring backslashUnescaped];
if (result == nil) {
result = [NSMutableArray arrayWithObject:unescaped];
} else {
[result addObject:unescaped];
}
i = termRange.location + termRange.length;
done = true;
}
}
}
return result;
}
- (NSString *)fieldWithPrefix:(NSString *)prefix {
return [self fieldWithPrefix:prefix terminator:@";"];
}
- (NSString *)fieldWithPrefix:(NSString *)prefix terminator:(NSString *)term {
NSArray *fields = [self fieldsWithPrefix:prefix terminator:term];
if (fields.count == 0) {
return nil;
} else {
return [fields lastObject];
}
}
@end
@implementation DoCoMoResultParser
@end

View file

@ -0,0 +1,34 @@
//
// EmailAction.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#include "OpenUrlAction.h"
@interface EmailAction : OpenUrlAction {
NSString *recipient;
}
@property (nonatomic, copy) NSString *recipient;
- (id)initWithRecipient:(NSString *)recipient subject:(NSString *)subject body:(NSString *)body;
+ (id)actionWithRecipient:(NSString *)recipient subject:(NSString *)subject body:(NSString *)body;
@end

View file

@ -0,0 +1,68 @@
//
// EmailAction.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "EmailAction.h"
@implementation EmailAction
@synthesize recipient;
static NSURL *MailtoURL(NSString *to, NSString *sub, NSString *body) {
NSMutableString *result = [NSMutableString stringWithFormat:@"mailto:%@",
[to stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (sub) {
[result appendFormat:@"&subject=%@", [sub stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
if (body) {
[result appendFormat:@"&body=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
return [NSURL URLWithString:result];
}
- (id)initWithRecipient:(NSString *)rec subject:(NSString *)subject body:(NSString *)body {
if ((self = [super initWithURL:MailtoURL(rec, subject, body)]) != nil) {
self.recipient = rec;
}
return self;
}
+ (id)actionWithRecipient:(NSString *)recipient subject:(NSString *)subject body:(NSString *)body {
return [[[self alloc] initWithRecipient:recipient subject:subject body:body] autorelease];
}
- (NSString *)title {
return [NSString localizedStringWithFormat:NSLocalizedString(@"EmailAction action title", @"Email %@"), self.recipient];
}
- (NSString *)alertTitle {
return NSLocalizedString(@"EmailAction alert title", @"Compose Email");
}
- (NSString *)alertMessage {
return [NSString localizedStringWithFormat:NSLocalizedString(@"EmailAction alert message", @"Compose Email to %@?"), self.recipient];
}
- (NSString *)alertButtonTitle {
return NSLocalizedString(@"EmailAction alert button title", @"Compose");
}
@end

View file

@ -0,0 +1,29 @@
//
// EmailDoCoMoResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "DoCoMoResultParser.h"
@interface EmailDoCoMoResultParser : DoCoMoResultParser {
}
@end

View file

@ -0,0 +1,50 @@
//
// EmailDoCoMoResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "EmailDoCoMoResultParser.h"
#import "EmailParsedResult.h"
@implementation EmailDoCoMoResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange foundRange = [s rangeOfString:@"MATMSG:"];
if (foundRange.location == NSNotFound) {
return nil;
}
NSString *to = [s fieldWithPrefix:@"TO:"];
if (to == nil) {
return nil;
}
EmailParsedResult *result = [[EmailParsedResult alloc] init];
result.to = to;
result.subject = [s fieldWithPrefix:@"SUB:"];
result.body = [s fieldWithPrefix:@"BODY:"];
return [result autorelease];
}
@end

View file

@ -0,0 +1,37 @@
//
// EmailDoCoMoParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface EmailParsedResult : ParsedResult {
NSString *to;
NSString *subject;
NSString *body;
}
@property (nonatomic, copy) NSString *to;
@property (nonatomic, copy) NSString *subject;
@property (nonatomic, copy) NSString *body;
+ (bool) looksLikeAnEmailAddress:(NSString *)s;
@end

View file

@ -0,0 +1,74 @@
//
// EmailDoCoMoParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "EmailParsedResult.h"
#import "EmailAction.h"
@implementation EmailParsedResult
@synthesize to;
@synthesize subject;
@synthesize body;
+ (bool) looksLikeAnEmailAddress:(NSString *)s {
if ([s rangeOfString:@"@"].location == NSNotFound) {
return false;
}
if ([s rangeOfString:@"."].location == NSNotFound) {
return false;
}
if ([s rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location != NSNotFound) {
return false;
}
return true;
}
- (NSString *)stringForDisplay {
NSMutableArray *parts = [[NSMutableArray alloc] initWithCapacity:10];
[parts addObject:[NSString stringWithFormat:NSLocalizedString(@"EmailParsedResult Display: Recipient", @"To: %@"), self.to]];
if (self.subject) {
[parts addObject:[NSString stringWithFormat:NSLocalizedString(@"EmailParsedResult Display: Subject", @"Subject: %@"), self.subject]];
}
if (self.body) {
[parts addObject:@""];
[parts addObject:[NSString stringWithFormat:NSLocalizedString(@"EmailParsedResult Display: Body", @"%@"), self.body]];
}
return [parts componentsJoinedByString:@"\n"];
}
+ (NSString *)typeName {
return NSLocalizedString(@"EmailParsedResult type name", @"Email");
}
- (NSArray *)actions {
return [NSArray arrayWithObject:[EmailAction actionWithRecipient:self.to
subject:self.subject
body:self.body]];
}
- (UIImage *)icon {
return [UIImage imageNamed:@"email.png"];
}
@end

View file

@ -0,0 +1,37 @@
//
// FormatReader.h
//
// Created by Dave MacLachlan on 2010-05-03.
/*
* Copyright 2010 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.
*/
#import <Foundation/Foundation.h>
#import <zxing/common/Counted.h>
#import <zxing/Result.h>
#import <zxing/BinaryBitmap.h>
#import <zxing/Reader.h>
@interface FormatReader : NSObject {
zxing::Reader *reader_;
}
+ (void)registerFormatReader:(FormatReader *)formatReader;
+ (NSSet *)formatReaders;
- (id)initWithReader:(zxing::Reader *)reader;
- (zxing::Ref<zxing::Result>)decode:(zxing::Ref<zxing::BinaryBitmap>)grayImage;
@end

View file

@ -0,0 +1,64 @@
//
// FormatReader.mm
//
// Created by Dave MacLachlan on 2010-05-03.
/*
* Copyright 2010 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.
*/
#import "FormatReader.h"
@implementation FormatReader
static NSMutableSet *sFormatReaders = nil;
+ (void)registerFormatReader:(FormatReader*)formatReader {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@synchronized(self) {
if (!sFormatReaders) {
sFormatReaders = [[NSMutableSet alloc] init];
}
[sFormatReaders addObject:formatReader];
}
[pool drain];
}
+ (NSSet *)formatReaders {
NSSet *formatReaders = nil;
@synchronized(self) {
formatReaders = [[sFormatReaders copy] autorelease];
NSLog(@"readers : %d",[formatReaders count]);
}
return formatReaders;
}
- (id)initWithReader:(zxing::Reader *)reader {
if ((self = [super init])) {
reader_ = reader;
}
return self;
}
- (void)dealloc {
delete reader_;
[super dealloc];
}
- (zxing::Ref<zxing::Result>)decode:(zxing::Ref<zxing::BinaryBitmap>)grayImage {
return reader_->decode(grayImage);
}
@end

View file

@ -0,0 +1,34 @@
//
// GeoParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 05/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface GeoParsedResult : ParsedResult {
NSString *location;
}
@property (nonatomic, copy) NSString *location;
- (id)initWithLocation:(NSString *)location;
@end

View file

@ -0,0 +1,59 @@
//
// GeoParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 05/06/2008.
/*
* Copyright 2008 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.
*/
#import "GeoParsedResult.h"
#import "ShowMapAction.h"
@implementation GeoParsedResult
@synthesize location;
- (id)initWithLocation:(NSString *)l {
if ((self = [super init]) != nil) {
self.location = l;
}
return self;
}
+ (NSString *)typeName {
return NSLocalizedString(@"GeoParsedResult type name", @"Geolocation");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"map-pin.png"];
}
- (NSString *)stringForDisplay {
return [NSString stringWithFormat:NSLocalizedString(@"GeoParsedResult display", @"Geo: %@"), self.location];
}
- (void)populateActions {
[actions addObject:[ShowMapAction actionWithLocation:self.location]];
}
- (void) dealloc {
[location release];
[super dealloc];
}
@end

View file

@ -0,0 +1,29 @@
//
// GeoResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface GeoResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,43 @@
//
// GeoResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "GeoResultParser.h"
#import "GeoParsedResult.h"
#define PREFIX @"geo:"
@implementation GeoResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) {
int restStart = prefixRange.location + prefixRange.length;
return [[[GeoParsedResult alloc] initWithLocation:[s substringFromIndex:restStart]]
autorelease];
}
return nil;
}
@end

View file

@ -0,0 +1,50 @@
//
// GrayBytesMonochromeBitmapSource.cpp
// ZXing
//
// Created by Thomas Recloux, Norsys on 04/12/2009.
/*
* Copyright 2008 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.
*/
#include "GrayBytesMonochromeBitmapSource.h"
#include <zxing/ReaderException.h>
GrayBytesMonochromeBitmapSource::GrayBytesMonochromeBitmapSource(const unsigned char *bytes,
int width,
int height,
int bytesPerRow) :
width_(width),
height_(height),
bytes_(bytes),
bytesPerRow_(bytesPerRow) { }
int GrayBytesMonochromeBitmapSource::getWidth() const{
return width_;
}
int GrayBytesMonochromeBitmapSource::getHeight() const {
return height_;
}
unsigned char GrayBytesMonochromeBitmapSource::getPixel(int x, int y) const {
/* if (x >= width_ || y >= height_) {
throw new ReaderException("bitmap coordinate out of bounds");
}*/
int index = y * bytesPerRow_ + x;
return bytes_[index];
}

View file

@ -0,0 +1,51 @@
//
// GrayBytesMonochromeBitmapSource.h
// ZXing
//
// Created by Thomas Recloux, Norsys on 04/12/2009.
/*
* Copyright 2008 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.
*/
#ifndef __GRAY_BYTES_MONOCHROM_BITMAP_SOURCE_H__
#define __GRAY_BYTES_MONOCHROM_BITMAP_SOURCE_H__
#include <zxing/LuminanceSource.h>
class GrayBytesMonochromeBitmapSource : public zxing::LuminanceSource {
private:
int width_;
int height_;
const unsigned char *bytes_;
int bytesPerRow_;
public:
GrayBytesMonochromeBitmapSource(const unsigned char *bytes,
int width,
int height,
int bytesPerRow);
virtual ~GrayBytesMonochromeBitmapSource() { }
virtual unsigned char getPixel(int x, int y) const;
virtual int getWidth() const;
virtual int getHeight() const;
private:
GrayBytesMonochromeBitmapSource(const GrayBytesMonochromeBitmapSource&);
GrayBytesMonochromeBitmapSource& operator=(const GrayBytesMonochromeBitmapSource&);
};
#endif // __GRAY_BYTES_MONOCHROM_BITMAP_SOURCE_H__

View file

@ -0,0 +1,29 @@
//
// MeCardParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "DoCoMoResultParser.h"
@interface MeCardParser : DoCoMoResultParser {
}
@end

View file

@ -0,0 +1,54 @@
//
// MeCardParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "MeCardParser.h"
#import "BusinessCardParsedResult.h"
@implementation MeCardParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange foundRange = [s rangeOfString:@"MECARD:"];
if (foundRange.location == NSNotFound) {
return nil;
}
NSString *name = [s fieldWithPrefix:@"N:"];
if (name == nil) {
return nil;
}
BusinessCardParsedResult *result = [[BusinessCardParsedResult alloc] init];
result.name = name;
result.phoneNumbers = [s fieldsWithPrefix:@"TEL:"];
result.email = [s fieldWithPrefix:@"EMAIL:"];
result.note = [s fieldWithPrefix:@"NOTE:"];
result.urlString = [s fieldWithPrefix:@"URL:"];
result.address = [s fieldWithPrefix:@"ADR:"];
return [result autorelease];
}
@end

View file

@ -0,0 +1,42 @@
//
// MultiFormatReader.mm
//
// Created by Dave MacLachlan on 2010-05-03.
/*
* Copyright 2010 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.
*/
#import "FormatReader.h"
#import <zxing/MultiFormatReader.h>
@interface MultiFormatReader : FormatReader
@end
@implementation MultiFormatReader
+ (void)load {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"MultiFormatReader: load called");
[FormatReader registerFormatReader:[[[self alloc] init] autorelease]];
[pool drain];
}
- (id)init {
zxing::MultiFormatReader *reader = new zxing::MultiFormatReader();
NSLog(@"MultiFormatReader: init called");
return [super initWithReader:reader];
}
@end

View file

@ -0,0 +1,32 @@
//
// NSString+HTML.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
@interface NSString (HTMLExtensions)
+ (NSDictionary *)htmlEscapes;
+ (NSDictionary *)htmlUnescapes;
- (NSString *)htmlEscapedString;
- (NSString *)htmlUnescapedString;
@end

View file

@ -0,0 +1,70 @@
//
// NSString+HTML.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "NSString+HTML.h"
@implementation NSString (HTMLExtensions)
static NSDictionary *htmlEscapes = nil;
static NSDictionary *htmlUnescapes = nil;
+ (NSDictionary *)htmlEscapes {
if (!htmlEscapes) {
htmlEscapes = [[NSDictionary alloc] initWithObjectsAndKeys:
@"&amp;", @"&",
@"&lt;", @"<",
@"&gt;", @">",
nil
];
}
return htmlEscapes;
}
+ (NSDictionary *)htmlUnescapes {
if (!htmlUnescapes) {
htmlUnescapes = [[NSDictionary alloc] initWithObjectsAndKeys:
@"&", @"&amp;",
@"<", @"&lt;",
@">", @"&gt;",
nil
];
}
return htmlEscapes;
}
static NSString *replaceAll(NSString *s, NSDictionary *replacements) {
for (NSString *key in replacements) {
NSString *replacement = [replacements objectForKey:key];
s = [s stringByReplacingOccurrencesOfString:key withString:replacement];
}
return s;
}
- (NSString *)htmlEscapedString {
return replaceAll(self, [[self class] htmlEscapes]);
}
- (NSString *)htmlUnescapedString {
return replaceAll(self, [[self class] htmlUnescapes]);
}
@end

View file

@ -0,0 +1,42 @@
//
// OpenUrlAction.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultAction.h"
@interface OpenUrlAction : ResultAction <UIAlertViewDelegate> {
NSURL *URL;
}
@property(nonatomic, retain) NSURL *URL;
- (id)initWithURL:(NSURL *)URL;
+ (id)actionWithURL:(NSURL *)URL;
- (void)openURL;
- (NSString *)alertTitle;
- (NSString *)alertMessage;
- (NSString *)alertButtonTitle;
// UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@end

View file

@ -0,0 +1,82 @@
//
// OpenUrlAction.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "OpenUrlAction.h"
@implementation OpenUrlAction
@synthesize URL;
- (id)initWithURL:(NSURL *)url {
if ((self = [super init]) != nil) {
self.URL = url;
}
return self;
}
+ (id)actionWithURL:(NSURL *)URL {
return [[[self alloc] initWithURL:URL] autorelease];
}
- (NSString *)title {
return [NSString localizedStringWithFormat:NSLocalizedString(@"OpenURLAction action title", @"Open URL"), self.URL];
}
- (NSString *)alertTitle {
return NSLocalizedString(@"OpenURLAction alert title", @"Open URL");
}
- (NSString *)alertMessage {
return [NSString localizedStringWithFormat:NSLocalizedString(@"OpenURLAction alert message", @"Open URL <%@>?"), self.URL];
}
- (NSString *)alertButtonTitle {
return NSLocalizedString(@"OpenURLAction alert button title", @"Open");
}
- (void)performActionWithController:(UIViewController *)controller
shouldConfirm:(bool)shouldConfirm {
if (shouldConfirm) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:[self alertMessage]
delegate:self
cancelButtonTitle:NSLocalizedString(@"OpenURLAction cancel button title", @"Cancel")
otherButtonTitles:[self alertButtonTitle], nil];
[alertView show];
[alertView release];
} else {
[self openURL];
}
}
- (void)openURL {
[[UIApplication sharedApplication] openURL:self.URL];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
// perform the action
[self openURL];
}
}
@end

View file

@ -0,0 +1,40 @@
/**
* Copyright 2009 Jeff Verkoeyen
*
* 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.
*/
#import <UIKit/UIKit.h>
@protocol CancelDelegate;
@interface OverlayView : UIView {
UIImageView *imageView;
NSArray *_points;
UIButton *cancelButton;
id<CancelDelegate> delegate;
}
//@property (nonatomic, retain) UIImage* image;
@property (nonatomic, retain) NSArray* points;
@property (nonatomic, assign) id<CancelDelegate> delegate;
- (id)initWithCancelEnabled:(BOOL)cancelEnabled frame:(CGRect)frame;
- (CGRect)cropRect;
@end
@protocol CancelDelegate
- (void)cancelled;
@end

166
iphone/ZXingWidget/OverlayView.m Executable file
View file

@ -0,0 +1,166 @@
/**
* Copyright 2009 Jeff Verkoeyen
*
* 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.
*/
#import "OverlayView.h"
static const CGFloat kPadding = 10;
@implementation OverlayView
@synthesize delegate;
@synthesize points = _points;
//@synthesize image;
////////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithCancelEnabled:(BOOL)cancelEnabled frame:(CGRect)frame {
if( self = [super initWithFrame:frame] ) {
self.backgroundColor = [UIColor clearColor];
}
if (cancelEnabled) {
cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton setFrame:CGRectMake(95, 420, 130, 45)];
[cancelButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:cancelButton];
}
return self;
}
- (void)cancel:(id)sender {
// call delegate to cancel this scanner
if (delegate != nil) {
[delegate cancelled];
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
- (void) dealloc {
[imageView release];
imageView = nil;
[_points release];
_points = nil;
[super dealloc];
}
- (void)drawRect:(CGRect)rect inContext:(CGContextRef)context {
CGContextBeginPath(context);
CGContextMoveToPoint(context, rect.origin.x, rect.origin.y);
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y);
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + rect.size.height);
CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height);
CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y);
CGContextStrokePath(context);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef c = UIGraphicsGetCurrentContext();
CGRect cropRect = [self cropRect];
if (nil != _points) {
// [imageView.image drawAtPoint:cropRect.origin];
}
CGFloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
CGContextSetStrokeColor(c, white);
CGContextSetFillColor(c, white);
[self drawRect:cropRect inContext:c];
// CGContextSetStrokeColor(c, white);
char *text = "Place a barcode inside the";
char *text2 = "viewfinder rectangle to scan it.";
// CGContextSetStrokeColor(c, white);
CGContextSaveGState(c);
CGContextSelectFont(c, "Helvetica", 18, kCGEncodingMacRoman);
CGContextScaleCTM(c, -1.0, 1.0);
CGContextRotateCTM(c, 3.1415);
CGContextShowTextAtPoint(c, 48.0, -45.0, text, 26);
CGContextShowTextAtPoint(c, 33.0, -70.0, text2, 32);
CGContextRestoreGState(c);
if( nil != _points ) {
CGFloat blue[4] = {0.0f, 1.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(c, blue);
CGContextSetFillColor(c, blue);
CGRect smallSquare = CGRectMake(0, 0, 10, 10);
for( NSValue* value in _points ) {
CGPoint point = [value CGPointValue];
NSLog(@"drawing point at %f, %f", point.x, point.y);
smallSquare.origin = CGPointMake(
cropRect.origin.x + point.x - smallSquare.size.width / 2,
cropRect.origin.y + point.y - smallSquare.size.height / 2);
[self drawRect:smallSquare inContext:c];
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
- (void) setImage:(UIImage*)image {
if( nil == _imageView ) {
_imageView = [[UIImageView alloc] initWithImage:image];
_imageView.alpha = 0.5;
} else {
_imageView.image = image;
}
CGRect frame = _imageView.frame;
frame.origin.x = self.cropRect.origin.x;
frame.origin.y = self.cropRect.origin.y;
_imageView.frame = frame;
[_points release];
_points = nil;
self.backgroundColor = [UIColor clearColor];
[self setNeedsDisplay];
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage*) image {
return imageView.image;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
- (CGRect) cropRect {
CGFloat rectSize = self.frame.size.width - kPadding * 2;
return CGRectMake(kPadding, (self.frame.size.height - rectSize) / 2, rectSize, rectSize);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
- (void) setPoints:(NSArray*)pnts {
[pnts retain];
[_points release];
_points = pnts;
if (pnts != nil) {
self.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.25];
}
[self setNeedsDisplay];
}
@end

View file

@ -0,0 +1,35 @@
//
// ParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 22/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
@interface ParsedResult : NSObject {
NSMutableArray *actions;
}
+ (NSString *)typeName;
- (NSString *)stringForDisplay;
- (UIImage *)icon;
- (NSArray *)actions;
- (void)populateActions;
@end

View file

@ -0,0 +1,104 @@
//
// ParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 22/05/2008.
/*
* Copyright 2008 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.
*/
#import "ParsedResult.h"
#import "TextParsedResult.h"
#import "TelParsedResult.h"
#import "EmailParsedResult.h"
#import "BusinessCardParsedResult.h"
#import "URIParsedResult.h"
#import "GeoParsedResult.h"
#import "UIKit/UIStringDrawing.h"
#import <math.h>
@implementation ParsedResult
static NSMutableDictionary *iconsByClass = nil;
+ (NSString *)typeName {
return NSStringFromClass(self);
}
- (NSString *)stringForDisplay {
return @"{none}";
}
#define ICON_SIZE 40
#define ICON_INSIDE 36
+ (UIImage *)icon {
if (iconsByClass == nil) {
iconsByClass = [[NSMutableDictionary alloc] initWithCapacity:16];
}
UIImage *icon = [iconsByClass objectForKey:[self class]];
if (icon == nil) {
UIGraphicsBeginImageContext(CGSizeMake(ICON_SIZE, ICON_SIZE));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor lightGrayColor] set];
UIRectFill(CGRectMake(0, 0, ICON_SIZE, ICON_SIZE));
[[UIColor blackColor] set];
NSString *s = [[self class] typeName];
UIFont *font = [UIFont systemFontOfSize:16];
CGSize stringSize = [s sizeWithFont:font];
float xScale = fminf(1.0, ICON_INSIDE / stringSize.width);
float yScale = fminf(1.0, ICON_INSIDE / stringSize.height);
CGContextTranslateCTM(ctx, (ICON_SIZE / 2), (ICON_SIZE / 2));
CGContextRotateCTM(ctx, -M_PI / 6.0);
CGContextScaleCTM(ctx, xScale, yScale);
CGContextTranslateCTM(ctx,
-(stringSize.width)/2.0,
-(stringSize.height)/2.0);
[s drawAtPoint:CGPointMake(0, 0) withFont:font];
icon = [UIGraphicsGetImageFromCurrentImageContext() retain];
[iconsByClass setObject:icon forKey:[self class]];
UIGraphicsEndImageContext();
}
return icon;
}
- (UIImage *)icon {
return [[self class] icon];
}
- (NSArray *)actions {
if (!actions) {
actions = [[NSMutableArray alloc] init];
[self populateActions];
}
return actions;
}
- (void) populateActions {
}
- (void) dealloc {
[actions release];
[super dealloc];
}
@end

View file

@ -0,0 +1,30 @@
//
// PlainEmailResultParser.h
// ZXing
//
// Created by Christian Brunschen on 28/07/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface PlainEmailResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,40 @@
//
// PlainEmailResultParser.m
// ZXing
//
// Created by Christian Brunschen on 28/07/2008.
/*
* Copyright 2008 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.
*/
#import "PlainEmailResultParser.h"
#import "EmailParsedResult.h"
@implementation PlainEmailResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
if ([EmailParsedResult looksLikeAnEmailAddress:s]) {
EmailParsedResult *result = [[[EmailParsedResult alloc] init] autorelease];
[result setTo:s];
return result;
}
return nil;
}
@end

View file

@ -0,0 +1,32 @@
//
// ResultAction.h
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
@interface ResultAction : NSObject {
}
- (NSString *)title;
- (void)performActionWithController:(UIViewController *)controller
shouldConfirm:(bool)confirm;
@end

View file

@ -0,0 +1,36 @@
//
// ResultAction.m
// ZXing
//
// Created by Christian Brunschen on 28/05/2008.
/*
* Copyright 2008 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.
*/
#import "ResultAction.h"
@implementation ResultAction
- (NSString *)title {
return @"Abstract Action";
}
- (void)performActionWithController:(UIViewController *)controller
shouldConfirm:(bool)confirm {
NSLog(@"Abstract Action performed");
}
@end

View file

@ -0,0 +1,31 @@
//
// ResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface ResultParser : NSObject {
}
+ (void)registerResultParserClass:(Class)resultParser;
+ (ParsedResult *)parsedResultForString:(NSString *)s;
@end

View file

@ -0,0 +1,66 @@
//
// ResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "ResultParser.h"
@implementation ResultParser
static NSMutableSet *sResultParsers = nil;
+ (void)registerResultParserClass:(Class)resultParser {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@synchronized(self) {
if (!sResultParsers) {
sResultParsers = [[NSMutableSet alloc] init];
}
[sResultParsers addObject:resultParser];
}
[pool drain];
}
+ (NSSet *)resultParsers {
NSSet *resultParsers = nil;
@synchronized(self) {
resultParsers = [[sResultParsers copy] autorelease];
}
return resultParsers;
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
#ifdef DEBUG
NSLog(@"parsing result:\n<<<\n%@\n>>>\n", s);
#endif
for (Class c in [self resultParsers]) {
#ifdef DEBUG
NSLog(@"trying %@", NSStringFromClass(c));
#endif
ParsedResult *result = [c parsedResultForString:s];
if (result != nil) {
#ifdef DEBUG
NSLog(@"parsed as %@ %@", NSStringFromClass([result class]), result);
#endif
return result;
}
}
return nil;
}
@end

View file

@ -0,0 +1,34 @@
//
// SMSAction.h
// ZXing
//
// Created by Christian Brunschen on 16/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "CallAction.h"
@interface SMSAction : CallAction {
NSString *body;
}
@property (nonatomic, copy) NSString *body;
+ actionWithNumber:(NSString *)number body:(NSString *)body;
+ actionWithNumber:(NSString *)number;
@end

View file

@ -0,0 +1,85 @@
//
// SMSAction.m
// ZXing
//
// Created by Christian Brunschen on 16/06/2008.
/*
* Copyright 2008 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.
*/
#import "SMSAction.h"
// currently, including a message body makes the iPhone not actually
// go to compose an SMS at all, just start the SMS app. Bummer.
#ifdef SMS_URL_INCLUDE_BODY
#undef SMS_URL_INCLUDE_BODY
#endif
@implementation SMSAction
@synthesize body;
+ (NSURL *)urlForNumber:(NSString *)number withBody:(NSString *)body {
NSString *urlString =
#ifdef SMS_URL_INCLUDE_BODY
(body && [body length]) ?
[NSString stringWithFormat:@"sms:%@?body=%@", number, [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] :
#endif
[NSString stringWithFormat:@"sms:%@", number];
return [NSURL URLWithString:urlString];
}
- initWithNumber:(NSString *)n body:(NSString *)b {
if ((self = [super initWithURL:[[self class] urlForNumber:n withBody:b]]) != nil) {
self.number = n;
self.body = b;
}
return self;
}
- initWithNumber:(NSString *)n {
return [self initWithNumber:n body:nil];
}
+ actionWithNumber:(NSString *)number body:(NSString *)body {
return [[[self alloc] initWithNumber:number body:body] autorelease];
}
+ actionWithNumber:(NSString *)number {
return [self actionWithNumber:number body:nil];
}
- (NSString *)title {
return [NSString localizedStringWithFormat:NSLocalizedString(@"SMSAction action title", @"Compose SMS to %@"), self.number];
}
- (NSString *)alertTitle {
return NSLocalizedString(@"SMSAction alert title", @"Compose");
}
- (NSString *)alertMessage {
return [NSString localizedStringWithFormat:NSLocalizedString(@"SMSAction alert message", @"Compose SMS to %@?"), self.number];
}
- (NSString *)alertButtonTitle {
return NSLocalizedString(@"SMSAction alert button title", @"Compose");
}
- (void) dealloc {
[body release];
[super dealloc];
}
@end

View file

@ -0,0 +1,36 @@
//
// SMSParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface SMSParsedResult : ParsedResult {
NSString *number;
NSString *body;
}
@property (nonatomic, copy) NSString *number;
@property (nonatomic, copy) NSString *body;
- (id)initWithNumber:(NSString *)n body:(NSString *)b;
@end

View file

@ -0,0 +1,65 @@
//
// SMSParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "SMSParsedResult.h"
#import "SMSAction.h"
@implementation SMSParsedResult
@synthesize number;
@synthesize body;
- (id)initWithNumber:(NSString *)n body:(NSString *)b {
if ((self = [super init]) != nil) {
self.number = n;
self.body = b;
}
return self;
}
- (NSString *)stringForDisplay {
if (self.body) {
return [NSString stringWithFormat:@"%@\n%@", self.number, self.body];
}
return self.number;
}
+ (NSString *)typeName {
return NSLocalizedString(@"SMSParsedResult type name", @"SMS");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"sms.png"];
}
- (void)populateActions {
[actions addObject:[SMSAction actionWithNumber:self.number body:self.body]];
}
- (void) dealloc {
[number release];
[body release];
[super dealloc];
}
@end

View file

@ -0,0 +1,29 @@
//
// SMSResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface SMSResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,78 @@
//
// SMSResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "SMSResultParser.h"
#import "SMSParsedResult.h"
#define PREFIX @"sms:"
@implementation SMSResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) {
int max = [s length];
int restStart = prefixRange.location + prefixRange.length;
// initial presuption: everything after the prefix is the number, and there is no body
NSRange numberRange = NSMakeRange(restStart, max - restStart);
NSRange bodyRange = NSMakeRange(NSNotFound, 0);
// is there a query string?
NSRange queryRange = [s rangeOfString:@"?" options:0 range:numberRange];
if (queryRange.location != NSNotFound) {
// truncate the number range at the beginning of the query string
numberRange.length = queryRange.location - numberRange.location;
int paramsStart = queryRange.location + queryRange.length;
NSRange paramsRange = NSMakeRange(paramsStart, max - paramsStart);
NSRange bodyPrefixRange = [s rangeOfString:@"body=" options:0 range:paramsRange];
if (bodyPrefixRange.location != NSNotFound) {
int bodyStart = bodyPrefixRange.location + bodyPrefixRange.length;
bodyRange = NSMakeRange(bodyStart, max - bodyStart);
NSRange ampRange = [s rangeOfString:@"&" options:0 range:bodyRange];
if (ampRange.location != NSNotFound) {
// we found a '&', so we truncate the body range there
bodyRange.length = ampRange.location - bodyRange.location;
}
}
}
// if there's a semicolon in the number, truncate the number there
NSRange semicolonRange = [s rangeOfString:@";" options:0 range:numberRange];
if (semicolonRange.location != NSNotFound) {
numberRange.length = semicolonRange.location - numberRange.location;
}
NSString *number = [s substringWithRange:numberRange];
NSString *body = bodyRange.location != NSNotFound ? [s substringWithRange:bodyRange] : nil;
return [[[SMSParsedResult alloc] initWithNumber:number body:body]
autorelease];
}
return nil;
}
@end

View file

@ -0,0 +1,29 @@
//
// SMSTOResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface SMSTOResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,57 @@
//
// SMSTOResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "SMSTOResultParser.h"
#import "SMSParsedResult.h"
#define PREFIX @"SMSTO:"
@implementation SMSTOResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) {
int max = [s length];
int restStart = prefixRange.location + prefixRange.length;
NSRange searchRange = NSMakeRange(restStart, max - restStart);
NSRange colonRange = [s rangeOfString:@":" options:0 range:searchRange];
if (colonRange.location != NSNotFound) {
NSRange numberRange = NSMakeRange(restStart,
colonRange.location - restStart);
int bodyStart = colonRange.location + colonRange.length;
NSRange bodyRange = NSMakeRange(bodyStart, max - bodyStart);
return [[[SMSParsedResult alloc] initWithNumber:[s substringWithRange:numberRange]
body:[s substringWithRange:bodyRange]]
autorelease];
} else {
return [[[SMSParsedResult alloc] initWithNumber:[s substringFromIndex:restStart]
body:nil]
autorelease];
}
}
return nil;
}
@end

View file

@ -0,0 +1,34 @@
/*
* Copyright 2008 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.
*/
//
// ShowMapAction.h
// ZXing
//
// Created by Christian Brunschen on 05/06/2008.
#import <UIKit/UIKit.h>
#import "OpenUrlAction.h"
@interface ShowMapAction : OpenUrlAction {
NSString *location;
}
@property (nonatomic, copy) NSString *location;
- (id)initWithLocation:(NSString *)location;
+ (id)actionWithLocation:(NSString *)location;
@end

View file

@ -0,0 +1,68 @@
//
// ShowMapAction.m
// ZXing
//
// Created by Christian Brunschen on 05/06/2008.
/*
* Copyright 2008 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.
*/
#import "ShowMapAction.h"
@implementation ShowMapAction
@synthesize location;
static NSURL * URLForLocation(NSString *location) {
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",
[location stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
return [NSURL URLWithString:urlString];
}
- (id)initWithLocation:(NSString *)l {
if ((self = [super initWithURL:URLForLocation(l)]) != nil) {
self.location = l;
}
return self;
}
+ (id)actionWithLocation:(NSString *)location {
return [[[self alloc] initWithLocation:location] autorelease];
}
- (NSString *)title {
return NSLocalizedString(@"ShowMapAction action title", @"Show on Map");
}
- (NSString *)alertTitle {
return NSLocalizedString(@"ShowMapAction alert title", @"Show on Map");
}
- (NSString *)alertMessage {
return [NSString stringWithFormat:NSLocalizedString(@"ShowMapAction alert message", @"Show location %@ on Map ?"), self.location];
}
- (NSString *)alertButtonTitle {
return NSLocalizedString(@"ShowMapAction alert button title", @"Show");
}
- (void)dealloc {
[location release];
[super dealloc];
}
@end

View file

@ -0,0 +1,33 @@
//
// TelParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 23/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface TelParsedResult : ParsedResult {
NSString *number;
}
@property (nonatomic, copy) NSString *number;
- (id)initWithNumber:(NSString *)n;
@end

View file

@ -0,0 +1,58 @@
//
// TelParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 23/05/2008.
/*
* Copyright 2008 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.
*/
#import "TelParsedResult.h"
#import "CallAction.h"
@implementation TelParsedResult
@synthesize number;
- (id)initWithNumber:(NSString *)n {
if ((self = [super init]) != nil) {
self.number = n;
}
return self;
}
- (NSString *)stringForDisplay {
return self.number;
}
+ (NSString *)typeName {
return NSLocalizedString(@"TelParsedResult type name", @"Tel");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"phone.png"];
}
- (void)populateActions {
[actions addObject:[CallAction actionWithNumber:self.number]];
}
- (void) dealloc {
[number release];
[super dealloc];
}
@end

View file

@ -0,0 +1,29 @@
//
// TelResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface TelResultParser : NSObject {
}
@end

View file

@ -0,0 +1,44 @@
//
// TelResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "TelResultParser.h"
#import "TelParsedResult.h"
#define PREFIX @"tel:"
@implementation TelResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange telRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (telRange.location == 0) {
int restStart = telRange.location + telRange.length;
return [[[TelParsedResult alloc] initWithNumber:[s substringFromIndex:restStart]]
autorelease];
}
return nil;
}
@end

View file

@ -0,0 +1,34 @@
//
// TextParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 23/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface TextParsedResult : ParsedResult {
NSString *text;
}
@property (nonatomic, copy) NSString *text;
- (id)initWithString:(NSString *)s;
@end

View file

@ -0,0 +1,58 @@
//
// TextParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 23/05/2008.
/*
* Copyright 2008 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.
*/
#import "TextParsedResult.h"
#import "EmailAction.h"
@implementation TextParsedResult
@synthesize text;
- (id)initWithString:(NSString *)s {
if ((self = [super init]) != nil) {
self.text = s;
}
return self;
}
+ (NSString *)typeName {
return NSLocalizedString(@"TextParsedResult type name", @"Text");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"text.png"];
}
- (NSString *)stringForDisplay {
return self.text;
}
- (void) populateActions {
//[actions addObject:[EmailAction actionWithRecipient:@"recipient@domain" subject:@"QR Code Contents" body:text]];
}
- (void)dealloc {
[text release];
[super dealloc];
}
@end

View file

@ -0,0 +1,30 @@
//
// TextResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface TextResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,36 @@
//
// TextResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "TextResultParser.h"
#import "TextParsedResult.h"
@implementation TextResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
return [[[TextParsedResult alloc] initWithString:s] autorelease];
}
@end

View file

@ -0,0 +1,35 @@
//
// TwoDDecoderResult.h
// ZXing
//
// Created by Christian Brunschen on 04/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
@interface TwoDDecoderResult : NSObject {
NSString *text;
NSArray *points;
}
@property (nonatomic, copy) NSString *text;
@property (nonatomic, retain) NSArray *points;
+ (id)resultWithText:(NSString *)text points:(NSArray *)points;
- (id)initWithText:(NSString *)text points:(NSArray *)points;
@end

View file

@ -0,0 +1,52 @@
//
// TwoDDecoderResult.m
// ZXing
//
// Created by Christian Brunschen on 04/06/2008.
/*
* Copyright 2008 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.
*/
#import "TwoDDecoderResult.h"
@implementation TwoDDecoderResult
@synthesize text;
@synthesize points;
+ (id)resultWithText:(NSString *)text points:(NSArray *)points {
return [[[self alloc] initWithText:text points:points] autorelease];
}
- (id)initWithText:(NSString *)t points:(NSArray *)p {
if ((self = [super init]) != nil) {
self.text = t;
self.points = p;
}
return self;
}
- (void)dealloc {
[text release];
[points release];
[super dealloc];
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p> %@", [self class], self, self.text];
}
@end

View file

@ -0,0 +1,45 @@
//
// URIParsedResult.h
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ParsedResult.h"
@interface NSString (ZXingURLExtensions)
- (bool) looksLikeAURI;
- (NSString *)massagedURLString;
@end
@interface URIParsedResult : ParsedResult {
NSString *urlString;
NSString *title;
NSURL *URL;
}
- (id)initWithURLString:(NSString *)s title:(NSString *)t URL:(NSURL *)ur;
- (id)initWithURLString:(NSString *)s title:(NSString *)t;
- (id)initWithURLString:(NSString *)s URL:(NSURL *)ur;
- (id)initWithURLString:(NSString *)s;
@property (nonatomic, retain) NSString *urlString;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSURL *URL;
@end

View file

@ -0,0 +1,87 @@
//
// URIParsedResult.m
// ZXing
//
// Created by Christian Brunschen on 29/05/2008.
/*
* Copyright 2008 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.
*/
#import "URIParsedResult.h"
#import "OpenUrlAction.h"
#import "EmailAction.h"
#import "SMSAction.h"
@implementation URIParsedResult
@synthesize urlString;
@synthesize title;
@synthesize URL;
- (ResultAction *)createAction {
return [OpenUrlAction actionWithURL:self.URL];
}
- (id)initWithURLString:(NSString *)s title:(NSString *)t URL:(NSURL *)url {
if ((self = [super init]) != nil) {
self.urlString = s;
self.title = t;
self.URL = url;
}
return self;
}
- (id)initWithURLString:(NSString *)s URL:(NSURL *)url {
return [self initWithURLString:s title:nil URL:url];
}
- (id)initWithURLString:(NSString *)s title:(NSString *)t {
return [self initWithURLString:s title:t URL:[NSURL URLWithString:s]];
}
- (id)initWithURLString:(NSString *)s {
return [self initWithURLString:s title:nil URL:[NSURL URLWithString:s]];
}
- (NSString *)stringForDisplay {
return self.title ?
[NSString stringWithFormat:@"%@ <%@>", self.title, self.urlString] :
self.urlString;
}
+ (NSString *)typeName {
return NSLocalizedString(@"URIParsedResult type name", @"URI");
}
- (UIImage *)icon {
return [UIImage imageNamed:@"link2.png"];
}
- (void)populateActions {
#ifdef DEBUG
NSLog(@"creating action to open URL '%@'", self.urlString);
#endif
[actions addObject:[self createAction]];
}
- (void)dealloc {
[URL release];
[urlString release];
[super dealloc];
}
@end

View file

@ -0,0 +1,30 @@
//
// URIResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface URLResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,80 @@
//
// URIResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "URLResultParser.h"
#import "URIParsedResult.h"
@implementation NSString (ZXingURLExtensions)
- (bool)looksLikeAURI {
if ([self rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location != NSNotFound) {
return false;
}
if ([self rangeOfString:@":"].location == NSNotFound) {
return false;
}
return true;
}
- (NSString *)massagedURLString {
NSRange colonRange = [self rangeOfString:@":"];
if (colonRange.location == NSNotFound) {
return [NSString stringWithFormat:@"http://%@", self];
} else {
return [NSString stringWithFormat:@"%@%@",
[[self substringToIndex:colonRange.location] lowercaseString],
[self substringFromIndex:colonRange.location]
];
}
}
@end
#define PREFIX @"URL:"
@implementation URLResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) {
int restStart = prefixRange.location + prefixRange.length;
return [[[URIParsedResult alloc] initWithURLString:[[s substringFromIndex:restStart] massagedURLString]]
autorelease];
}
if ([s looksLikeAURI]) {
NSString *massaged = [s massagedURLString];
NSURL *url = [NSURL URLWithString:massaged];
if (url != nil) {
return [[[URIParsedResult alloc] initWithURLString:massaged URL:url] autorelease];
}
}
return nil;
}
@end

View file

@ -0,0 +1,29 @@
//
// URLTOResultParser.h
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import <UIKit/UIKit.h>
#import "ResultParser.h"
@interface URLTOResultParser : ResultParser {
}
@end

View file

@ -0,0 +1,54 @@
//
// URLTOResultParser.m
// ZXing
//
// Created by Christian Brunschen on 25/06/2008.
/*
* Copyright 2008 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.
*/
#import "URLTOResultParser.h"
#import "URIParsedResult.h"
#define PREFIX @"URLTO:"
@implementation URLTOResultParser
+ (void)load {
[ResultParser registerResultParserClass:self];
}
+ (ParsedResult *)parsedResultForString:(NSString *)s {
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) {
int max = [s length];
int titleStart = prefixRange.location + prefixRange.length;
NSRange searchRange = NSMakeRange(titleStart, max - titleStart);
NSRange colonRange = [s rangeOfString:@":" options:0 range:searchRange];
if (colonRange.location != NSNotFound) {
NSRange titleRange = NSMakeRange(titleStart,
colonRange.location - titleStart);
int linkStart = colonRange.location + colonRange.length;
NSRange linkRange = NSMakeRange(linkStart, max - linkStart);
return [[[URIParsedResult alloc] initWithURLString:[s substringWithRange:linkRange]
title:[s substringWithRange:titleRange]]
autorelease];
}
}
return nil;
}
@end

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,47 @@
/**
* Copyright 2009 Jeff Verkoeyen
*
* 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.
*/
#include <UIKit/UIKit.h>
#include <AudioToolbox/AudioToolbox.h>
#include "Decoder.h"
#include "ParsedResult.h"
#include "OverlayView.h"
@protocol ZXingDelegate;
@interface ZXingWidgetController : UIImagePickerController <DecoderDelegate, CancelDelegate> {
ParsedResult *result;
NSArray *actions;
OverlayView *overlayView;
SystemSoundID beepSound;
BOOL showCancel;
id<ZXingDelegate> delegate;
BOOL wasCancelled;
}
@property (nonatomic, assign) id<ZXingDelegate> delegate;
@property (nonatomic, assign) BOOL showCancel;
@property (nonatomic, retain) ParsedResult *result;
@property (nonatomic, retain) NSArray *actions;
- (id)initWithDelegate:(id<ZXingDelegate>)delegate;
- (BOOL)fixedFocus;
@end
@protocol ZXingDelegate
- (void)scanResult:(NSString *)result;
- (void)cancelled;
@end

View file

@ -0,0 +1,163 @@
/**
* Copyright 2009 Jeff Verkoeyen
*
* 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.
*/
#import "ZXingWidgetController.h"
#import "Decoder.h"
#import "NSString+HTML.h"
#import "ResultParser.h"
#import "ParsedResult.h"
#import "ResultAction.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#define CAMERA_SCALAR 1.12412 // scalar = (480 / (2048 / 480))
#define FIRST_TAKE_DELAY 1.0
CGImageRef UIGetScreenImage();
@implementation ZXingWidgetController
@synthesize result, actions, showCancel, delegate;
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate {
if (self = [super init]) {
[self setDelegate:scanDelegate];
showCancel = true;
self.wantsFullScreenLayout = YES;
self.sourceType = UIImagePickerControllerSourceTypeCamera;
float zoomFactor = CAMERA_SCALAR;
if ([self fixedFocus]) {
zoomFactor *= 1.5;
}
self.cameraViewTransform = CGAffineTransformScale(
self.cameraViewTransform, zoomFactor, zoomFactor);
overlayView = [[OverlayView alloc] initWithCancelEnabled:showCancel frame:[UIScreen mainScreen].bounds];
[overlayView setDelegate:self];
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.cameraOverlayView = overlayView;
self.allowsEditing = NO; // [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"];
}
return self;
}
- (void)cancelled {
NSLog(@"cancelled called in ZXingWidgetController");
wasCancelled = true;
if (delegate != nil) {
[delegate cancelled];
}
}
- (NSString *)getPlatform {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
return platform;
}
- (BOOL)fixedFocus {
NSString *platform = [self getPlatform];
if ([platform isEqualToString:@"iPhone1,1"] ||
[platform isEqualToString:@"iPhone1,2"]) return true;
return false;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
wasCancelled = false;
[NSTimer scheduledTimerWithTimeInterval: FIRST_TAKE_DELAY
target: self
selector: @selector(takePicture:)
userInfo: nil
repeats: NO];
}
- (void)takePicture:(NSTimer*)theTimer {
CGImageRef capture = UIGetScreenImage();
UIImage *scrn = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(capture, [overlayView cropRect])];
Decoder *d = [[Decoder alloc] init];
d.delegate = self;
CGRect cropRect = overlayView.cropRect;
cropRect.origin.x = 0.0;
cropRect.origin.y = 0.0;
NSLog(@"crop rect %f, %f, %f, %f", cropRect.origin.x, cropRect.origin.y, cropRect.size.width, cropRect.size.height);
[d decodeImage:scrn cropRect:cropRect];
}
// DecoderDelegate methods
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{
NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height);
}
- (void)decoder:(Decoder *)decoder
decodingImage:(UIImage *)image
usingSubset:(UIImage *)subset
progress:(NSString *)message {
NSLog(@"decoding image %@", message);
}
- (void)presentResultForString:(NSString *)resultString {
NSLog(@"in presentResultForString()");
self.result = [ResultParser parsedResultForString:resultString];
AudioServicesPlaySystemSound(beepSound);
// self.actions = self.result.actions;
#ifdef DEBUG
NSLog(@"result string = %@", resultString);
NSLog(@"result has %d actions", actions ? 0 : actions.count);
#endif
// [self updateToolbar];
}
- (void)presentResultPoints:(NSArray *)resultPoints
forImage:(UIImage *)image
usingSubset:(UIImage *)subset {
// simply add the points to the image view
NSLog(@"got points for display");
[overlayView setPoints:resultPoints];
}
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {
// [self presentResultForString:twoDResult.text];
NSLog(@"decoded image!!");
[self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset];
if (delegate != nil) {
[delegate scanResult:[twoDResult text]];
}
decoder.delegate = nil;
[decoder release];
// save the scan to the shared database
// [[Database sharedDatabase] addScanWithText:twoDResult.text];
// need to call delegate....`
// [self performResultAction:self];
}
- (void)decoder:(Decoder *)decoder failedToDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset reason:(NSString *)reason {
decoder.delegate = nil;
[decoder release];
[overlayView setPoints:nil];
if (!wasCancelled) {
[self takePicture:nil];
}
//[self updateToolbar];
}
@end

View file

@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'CocoaTouchStaticLibrary' target in the 'CocoaTouchStaticLibrary' project.
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

Binary file not shown.