mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -08:00
reduce the insanity in iphone
git-svn-id: https://zxing.googlecode.com/svn/trunk@2634 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
af0300ba91
commit
b7eda3b84d
|
@ -578,6 +578,7 @@
|
|||
"-Objc",
|
||||
);
|
||||
PRODUCT_NAME = Barcodes;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALID_ARCHS = "armv7 armv7s";
|
||||
};
|
||||
name = Debug;
|
||||
|
@ -604,6 +605,7 @@
|
|||
);
|
||||
PRODUCT_NAME = Barcodes;
|
||||
PROVISIONING_PROFILE = "";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VALID_ARCHS = "armv7 armv7s";
|
||||
};
|
||||
|
@ -662,6 +664,7 @@
|
|||
"-Objc",
|
||||
);
|
||||
PRODUCT_NAME = Barcodes;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VALID_ARCHS = "armv7 armv7s";
|
||||
};
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
return TITLE_HEIGHT;
|
||||
} else if (indexPath.row == 1) {
|
||||
CGSize size = [[result stringForDisplay] sizeWithFont:bodyFont constrainedToSize:CGSizeMake(280.0, TEXT_VIEW_HEIGHT) lineBreakMode:UILineBreakModeWordWrap];
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"text size = %f", size.height);
|
||||
#endif
|
||||
return fminf(TEXT_VIEW_HEIGHT, fmaxf(44, size.height + 24));
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//
|
||||
|
||||
#import "ZXMainViewController.h"
|
||||
#import <QRCodeReader.h>
|
||||
#import <MultiFormatReader.h>
|
||||
#import <UniversalResultParser.h>
|
||||
#import <ParsedResult.h>
|
||||
#import <ResultAction.h>
|
||||
|
@ -52,7 +52,7 @@
|
|||
|
||||
- (IBAction)scan:(id)sender {
|
||||
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
|
||||
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
|
||||
MultiFormatReader* qrcodeReader = [[MultiFormatReader alloc] init];
|
||||
NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
|
||||
[qrcodeReader release];
|
||||
widController.readers = readers;
|
||||
|
@ -109,7 +109,7 @@
|
|||
#pragma mark ZXingDelegateMethods
|
||||
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)resultString {
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"result has %d actions", actions ? 0 : actions.count);
|
||||
#endif
|
||||
Scan * scan = [[Database sharedDatabase] addScanWithText:resultString];
|
||||
|
@ -175,6 +175,7 @@
|
|||
cancelButtonTitle:@"Cancel"
|
||||
otherButtonTitles:@"Return", nil];
|
||||
[alert show];
|
||||
[alert release];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +196,7 @@
|
|||
|
||||
if (self.actions.count == 1) {
|
||||
ResultAction *action = [self.actions lastObject];
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"Result has the single action, (%@) '%@', performing it",
|
||||
NSStringFromClass([action class]), [action title]);
|
||||
#endif
|
||||
|
@ -203,7 +204,7 @@
|
|||
withObject:action
|
||||
afterDelay:0.0];
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"Result has multiple actions, popping up an action sheet");
|
||||
#endif
|
||||
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithFrame:self.view.bounds];
|
||||
|
|
|
@ -16,35 +16,7 @@
|
|||
*/
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
#ifndef ZXQR
|
||||
#define ZXQR 1
|
||||
#endif
|
||||
|
||||
#if ZXQR
|
||||
#import "QRCodeReader.h"
|
||||
#endif
|
||||
|
||||
#ifndef ZXAZ
|
||||
#define ZXAZ 1
|
||||
#endif
|
||||
|
||||
#if ZXAZ
|
||||
#import "AztecReader.h"
|
||||
#endif
|
||||
|
||||
#ifndef ZX1D
|
||||
#define ZX1D 1
|
||||
#endif
|
||||
|
||||
#if ZX1D
|
||||
#import "MultiFormatOneDReader.h"
|
||||
#endif
|
||||
|
||||
@interface RootViewController()
|
||||
|
||||
@end
|
||||
|
||||
#import "MultiFormatReader.h"
|
||||
|
||||
@implementation RootViewController
|
||||
@synthesize resultsView;
|
||||
|
@ -65,25 +37,9 @@
|
|||
|
||||
NSMutableSet *readers = [[NSMutableSet alloc ] init];
|
||||
|
||||
#if ZXQR
|
||||
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
|
||||
[readers addObject:qrcodeReader];
|
||||
[qrcodeReader release];
|
||||
#endif
|
||||
|
||||
#if ZXAZ
|
||||
AztecReader *aztecReader = [[AztecReader alloc] init];
|
||||
[readers addObject:aztecReader];
|
||||
[aztecReader release];
|
||||
#endif
|
||||
|
||||
#if ZX1D
|
||||
{
|
||||
MultiFormatOneDReader* reader = [[MultiFormatOneDReader alloc] init];
|
||||
[readers addObject:reader];
|
||||
[reader release];
|
||||
}
|
||||
#endif
|
||||
MultiFormatReader* reader = [[MultiFormatReader alloc] init];
|
||||
[readers addObject:reader];
|
||||
[reader release];
|
||||
|
||||
widController.readers = readers;
|
||||
[readers release];
|
||||
|
@ -91,7 +47,10 @@
|
|||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
widController.soundToPlay =
|
||||
[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO];
|
||||
|
||||
[self presentModalViewController:widController animated:YES];
|
||||
// [self presentViewController:widController animated:YES completion:nil];
|
||||
|
||||
[widController release];
|
||||
}
|
||||
|
||||
|
@ -105,10 +64,12 @@
|
|||
[resultsView setNeedsDisplay];
|
||||
}
|
||||
[self dismissModalViewControllerAnimated:NO];
|
||||
// [self dismissViewControllerAnimated:NO completion:nil];
|
||||
}
|
||||
|
||||
- (void)zxingControllerDidCancel:(ZXingWidgetController*)controller {
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
[self dismissModalViewControllerAnimated:NO];
|
||||
// [self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
|
@ -30,5 +26,11 @@
|
|||
<true/>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainWindow</string>
|
||||
<key>NSMainNibFile~ipad</key>
|
||||
<string>MainWindow-iPad</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
3B0A5DB91444C492000EC568 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 3B0A5DB81444C492000EC568 /* Icon.png */; };
|
||||
3B331CEE161BB74E007313B6 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3B331CED161BB74E007313B6 /* Default-568h@2x.png */; };
|
||||
3B43FDCB15939575001CD5C9 /* libZXingWidget.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F027F7E11A7BAD4006B06DE /* libZXingWidget.a */; };
|
||||
3B6AA67A1710EF3400DF84C0 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B6AA6791710EF3400DF84C0 /* MainWindow-iPad.xib */; };
|
||||
3BCED5C8120F84C900131FA0 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BCED5C7120F84C900131FA0 /* AVFoundation.framework */; };
|
||||
3BCED5CE120F84E000131FA0 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BCED5CD120F84E000131FA0 /* CoreVideo.framework */; };
|
||||
3BCED5EB120F885C00131FA0 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BCED5EA120F885C00131FA0 /* CoreMedia.framework */; };
|
||||
|
@ -67,6 +68,7 @@
|
|||
28F335F01007B36200424DE2 /* RootViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RootViewController.xib; sourceTree = "<group>"; };
|
||||
3B0A5DB81444C492000EC568 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
|
||||
3B331CED161BB74E007313B6 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
|
||||
3B6AA6791710EF3400DF84C0 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
|
||||
3BCED5C7120F84C900131FA0 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
|
||||
3BCED5CD120F84E000131FA0 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
|
||||
3BCED5EA120F885C00131FA0 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
|
||||
|
@ -133,6 +135,7 @@
|
|||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */,
|
||||
29B97317FDCFA39411CA2CEA /* Resources */,
|
||||
3B6AA6781710EF3400DF84C0 /* iPad */,
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */,
|
||||
19C28FACFE9D520D11CA2CBB /* Products */,
|
||||
);
|
||||
|
@ -175,6 +178,14 @@
|
|||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
3B6AA6781710EF3400DF84C0 /* iPad */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3B6AA6791710EF3400DF84C0 /* MainWindow-iPad.xib */,
|
||||
);
|
||||
name = iPad;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
@ -257,6 +268,7 @@
|
|||
E548755C119C62B9001CC0F8 /* beep-beep.aiff in Resources */,
|
||||
3B0A5DB91444C492000EC568 /* Icon.png in Resources */,
|
||||
3B331CEE161BB74E007313B6 /* Default-568h@2x.png in Resources */,
|
||||
3B6AA67A1710EF3400DF84C0 /* MainWindow-iPad.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -298,6 +310,7 @@
|
|||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
"GCC_THUMB_SUPPORT[arch=armv6]" = NO;
|
||||
INFOPLIST_FILE = "ScanTest-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
OTHER_LDFLAGS = "";
|
||||
|
@ -305,6 +318,7 @@
|
|||
PRODUCT_NAME = ScanTest;
|
||||
"PROVISIONING_PROFILE[sdk=*]" = "";
|
||||
STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
@ -319,7 +333,9 @@
|
|||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
"GCC_THUMB_SUPPORT[arch=armv6]" = NO;
|
||||
INFOPLIST_FILE = "ScanTest-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
PRODUCT_NAME = ScanTest;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
|
|
270
iphone/ScanTest/iPad/MainWindow-iPad.xib
Normal file
270
iphone/ScanTest/iPad/MainWindow-iPad.xib
Normal file
|
@ -0,0 +1,270 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1552</int>
|
||||
<string key="IBDocument.SystemVersion">12D78</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
|
||||
<string key="IBDocument.AppKitVersion">1187.37</string>
|
||||
<string key="IBDocument.HIToolboxVersion">626.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string key="NS.object.0">2083</string>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>IBProxyObject</string>
|
||||
<string>IBUICustomObject</string>
|
||||
<string>IBUINavigationBar</string>
|
||||
<string>IBUINavigationController</string>
|
||||
<string>IBUINavigationItem</string>
|
||||
<string>IBUIViewController</string>
|
||||
<string>IBUIWindow</string>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
||||
<integer value="1" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBProxyObject" id="841351856">
|
||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
</object>
|
||||
<object class="IBProxyObject" id="302016328">
|
||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
</object>
|
||||
<object class="IBUICustomObject" id="664661524">
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
</object>
|
||||
<object class="IBUIWindow" id="380026005">
|
||||
<nil key="NSNextResponder"/>
|
||||
<int key="NSvFlags">1316</int>
|
||||
<object class="NSPSMatrix" key="NSFrameMatrix"/>
|
||||
<string key="NSFrameSize">{768, 1024}</string>
|
||||
<object class="NSColor" key="IBUIBackgroundColor">
|
||||
<int key="NSColorSpace">1</int>
|
||||
<bytes key="NSRGB">MSAxIDEAA</bytes>
|
||||
</object>
|
||||
<bool key="IBUIOpaque">NO</bool>
|
||||
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
|
||||
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics" id="681401188">
|
||||
<int key="IBUIStatusBarStyle">2</int>
|
||||
</object>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
<bool key="IBUIResizesToFullScreen">YES</bool>
|
||||
</object>
|
||||
<object class="IBUINavigationController" id="701001926">
|
||||
<reference key="IBUISimulatedStatusBarMetrics" ref="681401188"/>
|
||||
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
|
||||
<int key="IBUIInterfaceOrientation">1</int>
|
||||
<int key="interfaceOrientation">1</int>
|
||||
</object>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
<bool key="IBUIHorizontal">NO</bool>
|
||||
<object class="IBUINavigationBar" key="IBUINavigationBar" id="207850653">
|
||||
<nil key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<string key="NSFrameSize">{0, 0}</string>
|
||||
<bool key="IBUIOpaque">NO</bool>
|
||||
<bool key="IBUIClipsSubviews">YES</bool>
|
||||
<bool key="IBUIMultipleTouchEnabled">YES</bool>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBUIViewControllers">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBUIViewController" id="619226028">
|
||||
<object class="IBUINavigationItem" key="IBUINavigationItem" id="394667715">
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
</object>
|
||||
<reference key="IBUIParentViewController" ref="701001926"/>
|
||||
<string key="IBUINibName">RootViewController</string>
|
||||
<reference key="IBUISimulatedStatusBarMetrics" ref="681401188"/>
|
||||
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
|
||||
<int key="IBUIInterfaceOrientation">1</int>
|
||||
<int key="interfaceOrientation">1</int>
|
||||
</object>
|
||||
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
|
||||
<bool key="IBUIHorizontal">NO</bool>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">delegate</string>
|
||||
<reference key="source" ref="841351856"/>
|
||||
<reference key="destination" ref="664661524"/>
|
||||
</object>
|
||||
<int key="connectionID">4</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">window</string>
|
||||
<reference key="source" ref="664661524"/>
|
||||
<reference key="destination" ref="380026005"/>
|
||||
</object>
|
||||
<int key="connectionID">5</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">navigationController</string>
|
||||
<reference key="source" ref="664661524"/>
|
||||
<reference key="destination" ref="701001926"/>
|
||||
</object>
|
||||
<int key="connectionID">15</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<object class="NSArray" key="object" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">2</int>
|
||||
<reference key="object" ref="380026005"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="841351856"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">3</int>
|
||||
<reference key="object" ref="664661524"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="302016328"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">9</int>
|
||||
<reference key="object" ref="701001926"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="207850653"/>
|
||||
<reference ref="619226028"/>
|
||||
</object>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">11</int>
|
||||
<reference key="object" ref="207850653"/>
|
||||
<reference key="parent" ref="701001926"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">13</int>
|
||||
<reference key="object" ref="619226028"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="394667715"/>
|
||||
</object>
|
||||
<reference key="parent" ref="701001926"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">14</int>
|
||||
<reference key="object" ref="394667715"/>
|
||||
<reference key="parent" ref="619226028"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-1.CustomClassName</string>
|
||||
<string>-1.IBPluginDependency</string>
|
||||
<string>-2.CustomClassName</string>
|
||||
<string>-2.IBPluginDependency</string>
|
||||
<string>11.IBPluginDependency</string>
|
||||
<string>13.CustomClassName</string>
|
||||
<string>13.IBLastUsedUIStatusBarStylesToTargetRuntimesMap</string>
|
||||
<string>13.IBPluginDependency</string>
|
||||
<string>14.IBPluginDependency</string>
|
||||
<string>2.IBAttributePlaceholdersKey</string>
|
||||
<string>2.IBLastUsedUIStatusBarStylesToTargetRuntimesMap</string>
|
||||
<string>2.IBPluginDependency</string>
|
||||
<string>3.CustomClassName</string>
|
||||
<string>3.IBPluginDependency</string>
|
||||
<string>9.IBLastUsedUIStatusBarStylesToTargetRuntimesMap</string>
|
||||
<string>9.IBPluginDependency</string>
|
||||
</object>
|
||||
<object class="NSArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>UIApplication</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>UIResponder</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>RootViewController</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<string key="NS.key.0">IBCocoaTouchFramework</string>
|
||||
<integer value="0" key="NS.object.0"/>
|
||||
</object>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary">
|
||||
<string key="NS.key.0">IBCocoaTouchFramework</string>
|
||||
<integer value="0" key="NS.object.0"/>
|
||||
</object>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>ScanTestAppDelegate</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<string key="NS.key.0">IBCocoaTouchFramework</string>
|
||||
<integer value="0" key="NS.object.0"/>
|
||||
</object>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">15</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes"/>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
|
||||
<integer value="3100" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
<string key="IBCocoaTouchPluginVersion">2083</string>
|
||||
</data>
|
||||
</archive>
|
|
@ -1,9 +1,4 @@
|
|||
//
|
||||
// Decoder.h
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 31/03/2008.
|
||||
//
|
||||
// -*- mode:objc; c-basic-offset:2; indent-tabs-mode:nil -*-
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
|
@ -36,14 +31,6 @@
|
|||
|
||||
@property(nonatomic, retain) UIImage *image;
|
||||
@property(nonatomic, retain) NSSet *readers;
|
||||
#if 0
|
||||
@property(nonatomic, assign) CGRect cropRect;
|
||||
@property(nonatomic, retain) UIImage *subsetImage;
|
||||
@property(nonatomic, assign) char *subsetData;
|
||||
@property(assign) size_t subsetWidth;
|
||||
@property(assign) size_t subsetHeight;
|
||||
@property(assign) size_t subsetBytesPerRow;
|
||||
#endif
|
||||
@property(nonatomic, assign) id<DecoderDelegate> delegate;
|
||||
|
||||
- (BOOL) decodeImage:(UIImage *)image;
|
||||
|
|
|
@ -48,17 +48,9 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
|
||||
@synthesize image;
|
||||
@synthesize subsetImage;
|
||||
#if 0
|
||||
@synthesize cropRect;
|
||||
@synthesize subsetData;
|
||||
@synthesize subsetWidth;
|
||||
@synthesize subsetHeight;
|
||||
@synthesize subsetBytesPerRow;
|
||||
#endif
|
||||
@synthesize delegate;
|
||||
@synthesize readers;
|
||||
|
||||
|
||||
- (void)willDecodeImage {
|
||||
if ([self.delegate respondsToSelector:@selector(decoder:willDecodeImage:usingSubset:)]) {
|
||||
[self.delegate decoder:self willDecodeImage:self.image usingSubset:self.subsetImage];
|
||||
|
@ -86,15 +78,16 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
}
|
||||
|
||||
#define SUBSET_SIZE 360
|
||||
|
||||
- (ArrayRef<char>) prepareSubset {
|
||||
CGSize size = [image size];
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_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
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@" offset = (%.1f, %.1f), scale = %.3f", offset.x, offset.y, scale);
|
||||
#endif
|
||||
|
||||
|
@ -102,13 +95,13 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
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);
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"decoding: image to decode is (%lu x %lu) (%lu bytes/row)", subsetWidth, subsetHeight, subsetBytesPerRow);
|
||||
#endif
|
||||
|
||||
ArrayRef<char> subsetData (subsetBytesPerRow * subsetHeight);
|
||||
#ifdef DEBUG
|
||||
NSLog(@"allocated %d bytes of memory", subsetBytesPerRow * subsetHeight);
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"allocated %lu bytes of memory", subsetBytesPerRow * subsetHeight);
|
||||
#endif
|
||||
|
||||
CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();
|
||||
|
@ -124,28 +117,28 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
CGContextTranslateCTM(ctx, 0.0, subsetHeight);
|
||||
CGContextScaleCTM(ctx, 1.0, -1.0);
|
||||
|
||||
#ifdef DEBUG
|
||||
NSLog(@"created %dx%d bitmap context", subsetWidth, subsetHeight);
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"created %lux%lu bitmap context", subsetWidth, subsetHeight);
|
||||
#endif
|
||||
|
||||
UIGraphicsPushContext(ctx);
|
||||
CGRect rect = CGRectMake(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_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);
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"drew image into %lu(%lu)x%lu bitmap context", subsetWidth, subsetBytesPerRow, subsetHeight);
|
||||
#endif
|
||||
CGContextFlush(ctx);
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"flushed context");
|
||||
#endif
|
||||
|
||||
CGImageRef subsetImageRef = CGBitmapContextCreateImage(ctx);
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"created CGImage from context");
|
||||
#endif
|
||||
|
||||
|
@ -153,7 +146,7 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
CGImageRelease(subsetImageRef);
|
||||
|
||||
CGContextRelease(ctx);
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"released context");
|
||||
#endif
|
||||
return subsetData;
|
||||
|
@ -183,13 +176,13 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
NSMutableArray *points = nil;
|
||||
NSString *resultString = nil;
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"decoding gray image");
|
||||
#endif
|
||||
ResultPointCallback* callback_pointer(new ZXingWidgetControllerCallback(self));
|
||||
Ref<ResultPointCallback> callback(callback_pointer);
|
||||
Ref<Result> result([reader decode:grayImage andCallback:callback]);
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"gray image decoded");
|
||||
#endif
|
||||
|
||||
|
@ -208,12 +201,12 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
if (decoderResult) [decoderResult release];
|
||||
decoderResult = [[TwoDDecoderResult alloc] initWithText:resultString points:points];
|
||||
} catch (ReaderException &rex) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"failed to decode, caught ReaderException '%s'",
|
||||
rex.what());
|
||||
#endif
|
||||
} catch (IllegalArgumentException &iex) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"failed to decode, caught IllegalArgumentException '%s'",
|
||||
iex.what());
|
||||
#endif
|
||||
|
@ -227,11 +220,11 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
|
||||
#ifdef TRY_ROTATIONS
|
||||
if (!decoderResult) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"rotating gray image");
|
||||
#endif
|
||||
grayImage = grayImage->rotateCounterClockwise();
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"gray image rotated");
|
||||
#endif
|
||||
}
|
||||
|
@ -252,7 +245,7 @@ ZXingWidgetControllerCallback(Decoder* _decoder) : decoder(_decoder) {}
|
|||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"finished decoding.");
|
||||
#endif
|
||||
[mainpool release];
|
||||
|
|
16
iphone/ZXingWidget/Classes/MultiFormatReader.h
Normal file
16
iphone/ZXingWidget/Classes/MultiFormatReader.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// MultiFormatReader.h
|
||||
// ZXingWidget
|
||||
//
|
||||
// Created by Romain Pechayre on 6/14/10.
|
||||
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FormatReader.h"
|
||||
|
||||
|
||||
@interface MultiFormatReader : FormatReader {
|
||||
}
|
||||
- (id) init;
|
||||
@end
|
|
@ -96,20 +96,31 @@ static const CGFloat kLicenseButtonPadding = 10;
|
|||
}
|
||||
|
||||
- (void)showLicenseAlert:(id)sender {
|
||||
NSString *title = NSLocalizedStringWithDefaultValue(@"OverlayView license alert title", nil, [NSBundle mainBundle], @"License", @"License");
|
||||
NSString *message = NSLocalizedStringWithDefaultValue(@"OverlayView license alert message", nil, [NSBundle mainBundle], @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.", @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.");
|
||||
NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"OverlayView license alert cancel title", nil, [NSBundle mainBundle], @"OK", @"OK");
|
||||
NSString *viewTitle = NSLocalizedStringWithDefaultValue(@"OverlayView license alert view title", nil, [NSBundle mainBundle], @"View License", @"View License");
|
||||
NSString *title =
|
||||
NSLocalizedStringWithDefaultValue(@"OverlayView license alert title", nil, [NSBundle mainBundle], @"License", @"License");
|
||||
|
||||
NSString *message =
|
||||
NSLocalizedStringWithDefaultValue(@"OverlayView license alert message", nil, [NSBundle mainBundle], @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.", @"Scanning functionality provided by ZXing library, licensed under Apache 2.0 license.");
|
||||
|
||||
NSString *cancelTitle =
|
||||
NSLocalizedStringWithDefaultValue(@"OverlayView license alert cancel title", nil, [NSBundle mainBundle], @"OK", @"OK");
|
||||
|
||||
NSString *viewTitle =
|
||||
NSLocalizedStringWithDefaultValue(@"OverlayView license alert view title", nil, [NSBundle mainBundle], @"View License", @"View License");
|
||||
|
||||
UIAlertView *av =
|
||||
[[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:viewTitle, nil];
|
||||
|
||||
UIAlertView *av = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:viewTitle, nil];
|
||||
[av show];
|
||||
[self retain]; // For the delegate callback ...
|
||||
[av release];
|
||||
}
|
||||
|
||||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
||||
if (buttonIndex == [alertView firstOtherButtonIndex]) {
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apache.org/licenses/LICENSE-2.0.html"]];
|
||||
}
|
||||
if (buttonIndex == [alertView firstOtherButtonIndex]) {
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apache.org/licenses/LICENSE-2.0.html"]];
|
||||
}
|
||||
[self release];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -237,7 +237,7 @@
|
|||
// DecoderDelegate methods
|
||||
|
||||
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height);
|
||||
#endif
|
||||
}
|
||||
|
@ -252,7 +252,7 @@
|
|||
if (beepSound != (SystemSoundID)-1) {
|
||||
AudioServicesPlaySystemSound(beepSound);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"result string = %@", resultString);
|
||||
#endif
|
||||
}
|
||||
|
@ -307,7 +307,7 @@
|
|||
|
||||
// Gross, I know. But you can't use the device idiom because it's not iPad when running
|
||||
// in zoomed iphone mode but the camera still acts like an ipad.
|
||||
#if HAS_AVFF
|
||||
#if 0 && HAS_AVFF
|
||||
static bool isIPad() {
|
||||
static int is_ipad = -1;
|
||||
if (is_ipad < 0) {
|
||||
|
@ -326,9 +326,9 @@ static bool isIPad() {
|
|||
- (void)initCapture {
|
||||
#if HAS_AVFF
|
||||
AVCaptureDevice* inputDevice =
|
||||
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
||||
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
||||
AVCaptureDeviceInput *captureInput =
|
||||
[AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];
|
||||
[AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];
|
||||
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
|
||||
captureOutput.alwaysDiscardsLateVideoFrames = YES;
|
||||
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
|
||||
|
@ -339,16 +339,24 @@ static bool isIPad() {
|
|||
self.captureSession = [[[AVCaptureSession alloc] init] autorelease];
|
||||
|
||||
NSString* preset = 0;
|
||||
if (NSClassFromString(@"NSOrderedSet") && // Proxy for "is this iOS 5" ...
|
||||
[UIScreen mainScreen].scale > 1 &&
|
||||
isIPad() &&
|
||||
[inputDevice
|
||||
supportsAVCaptureSessionPreset:AVCaptureSessionPresetiFrame960x540]) {
|
||||
// NSLog(@"960");
|
||||
preset = AVCaptureSessionPresetiFrame960x540;
|
||||
|
||||
#if 0
|
||||
// to be deleted when verified ...
|
||||
if (isIPad()) {
|
||||
if (NSClassFromString(@"NSOrderedSet") && // Proxy for "is this iOS 5" ...
|
||||
[UIScreen mainScreen].scale > 1 &&
|
||||
[inputDevice
|
||||
supportsAVCaptureSessionPreset:AVCaptureSessionPresetiFrame960x540]) {
|
||||
preset = AVCaptureSessionPresetiFrame960x540;
|
||||
}
|
||||
if (false && !preset &&
|
||||
[inputDevice supportsAVCaptureSessionPreset:AVCaptureSessionPresetHigh]) {
|
||||
preset = AVCaptureSessionPresetHigh;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!preset) {
|
||||
// NSLog(@"MED");
|
||||
preset = AVCaptureSessionPresetMedium;
|
||||
}
|
||||
self.captureSession.sessionPreset = preset;
|
||||
|
@ -358,44 +366,6 @@ static bool isIPad() {
|
|||
|
||||
[captureOutput release];
|
||||
|
||||
/*
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(stopPreview:)
|
||||
name:AVCaptureSessionDidStopRunningNotification
|
||||
object:self.captureSession];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(notification:)
|
||||
name:AVCaptureSessionDidStopRunningNotification
|
||||
object:self.captureSession];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(notification:)
|
||||
name:AVCaptureSessionRuntimeErrorNotification
|
||||
object:self.captureSession];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(notification:)
|
||||
name:AVCaptureSessionDidStartRunningNotification
|
||||
object:self.captureSession];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(notification:)
|
||||
name:AVCaptureSessionWasInterruptedNotification
|
||||
object:self.captureSession];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(notification:)
|
||||
name:AVCaptureSessionInterruptionEndedNotification
|
||||
object:self.captureSession];
|
||||
*/
|
||||
|
||||
if (!self.prevLayer) {
|
||||
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
|
||||
}
|
||||
|
@ -424,6 +394,8 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||
size_t width = CVPixelBufferGetWidth(imageBuffer);
|
||||
size_t height = CVPixelBufferGetHeight(imageBuffer);
|
||||
|
||||
// NSLog(@"wxh: %lu x %lu", width, height);
|
||||
|
||||
uint8_t* baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
|
||||
void* free_me = 0;
|
||||
if (true) { // iOS bug?
|
||||
|
@ -436,8 +408,8 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGContextRef newContext =
|
||||
CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace,
|
||||
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
|
||||
CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace,
|
||||
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirts);
|
||||
|
||||
CGImageRef capture = CGBitmapContextCreateImage(newContext);
|
||||
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
|
||||
|
@ -446,56 +418,84 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||
CGContextRelease(newContext);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
|
||||
CGRect cropRect = [overlayView cropRect];
|
||||
if (oneDMode) {
|
||||
// let's just give the decoder a vertical band right above the red line
|
||||
cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
|
||||
cropRect.size.width = ONE_D_BAND_HEIGHT;
|
||||
// do a rotate
|
||||
CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
|
||||
if (false) {
|
||||
CGRect cropRect = [overlayView cropRect];
|
||||
if (oneDMode) {
|
||||
// let's just give the decoder a vertical band right above the red line
|
||||
cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
|
||||
cropRect.size.width = ONE_D_BAND_HEIGHT;
|
||||
// do a rotate
|
||||
CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
|
||||
CGImageRelease(capture);
|
||||
capture = [self CGImageRotated90:croppedImg];
|
||||
capture = [self CGImageRotated180:capture];
|
||||
// UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
|
||||
CGImageRelease(croppedImg);
|
||||
CGImageRetain(capture);
|
||||
cropRect.origin.x = 0.0;
|
||||
cropRect.origin.y = 0.0;
|
||||
cropRect.size.width = CGImageGetWidth(capture);
|
||||
cropRect.size.height = CGImageGetHeight(capture);
|
||||
}
|
||||
|
||||
// N.B.
|
||||
// - Won't work if the overlay becomes uncentered ...
|
||||
// - iOS always takes videos in landscape
|
||||
// - images are always 4x3; device is not
|
||||
// - iOS uses virtual pixels for non-image stuff
|
||||
|
||||
{
|
||||
float height = CGImageGetHeight(capture);
|
||||
float width = CGImageGetWidth(capture);
|
||||
|
||||
NSLog(@"%f %f", width, height);
|
||||
|
||||
CGRect screen = UIScreen.mainScreen.bounds;
|
||||
float tmp = screen.size.width;
|
||||
screen.size.width = screen.size.height;;
|
||||
screen.size.height = tmp;
|
||||
|
||||
cropRect.origin.x = (width-cropRect.size.width)/2;
|
||||
cropRect.origin.y = (height-cropRect.size.height)/2;
|
||||
}
|
||||
|
||||
NSLog(@"sb %@", NSStringFromCGRect(UIScreen.mainScreen.bounds));
|
||||
NSLog(@"cr %@", NSStringFromCGRect(cropRect));
|
||||
|
||||
CGImageRef newImage = CGImageCreateWithImageInRect(capture, cropRect);
|
||||
CGImageRelease(capture);
|
||||
capture = [self CGImageRotated90:croppedImg];
|
||||
capture = [self CGImageRotated180:capture];
|
||||
// UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
|
||||
CGImageRelease(croppedImg);
|
||||
CGImageRetain(capture);
|
||||
cropRect.origin.x = 0.0;
|
||||
cropRect.origin.y = 0.0;
|
||||
cropRect.size.width = CGImageGetWidth(capture);
|
||||
cropRect.size.height = CGImageGetHeight(capture);
|
||||
capture = newImage;
|
||||
}
|
||||
|
||||
// N.B.
|
||||
// - Won't work if the overlay becomes uncentered ...
|
||||
// - iOS always takes videos in landscape
|
||||
// - images are always 4x3; device is not
|
||||
// - iOS uses virtual pixels for non-image stuff
|
||||
UIImage* scrn = [[[UIImage alloc] initWithCGImage:capture] autorelease];
|
||||
|
||||
{
|
||||
float height = CGImageGetHeight(capture);
|
||||
float width = CGImageGetWidth(capture);
|
||||
|
||||
CGRect screen = UIScreen.mainScreen.bounds;
|
||||
float tmp = screen.size.width;
|
||||
screen.size.width = screen.size.height;;
|
||||
screen.size.height = tmp;
|
||||
|
||||
cropRect.origin.x = (width-cropRect.size.width)/2;
|
||||
cropRect.origin.y = (height-cropRect.size.height)/2;
|
||||
}
|
||||
CGImageRef newImage = CGImageCreateWithImageInRect(capture, cropRect);
|
||||
CGImageRelease(capture);
|
||||
UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage];
|
||||
CGImageRelease(newImage);
|
||||
Decoder *d = [[Decoder alloc] init];
|
||||
|
||||
Decoder* d = [[Decoder alloc] init];
|
||||
d.readers = readers;
|
||||
d.delegate = self;
|
||||
cropRect.origin.x = 0.0;
|
||||
cropRect.origin.y = 0.0;
|
||||
decoding = [d decodeImage:scrn cropRect:cropRect] == YES ? NO : YES;
|
||||
|
||||
decoding = [d decodeImage:scrn] == YES ? NO : YES;
|
||||
|
||||
[d release];
|
||||
[scrn release];
|
||||
}
|
||||
|
||||
if (decoding) {
|
||||
|
||||
d = [[Decoder alloc] init];
|
||||
d.readers = readers;
|
||||
d.delegate = self;
|
||||
|
||||
scrn = [[[UIImage alloc] initWithCGImage:scrn.CGImage
|
||||
scale:1.0
|
||||
orientation:UIImageOrientationLeft] autorelease];
|
||||
|
||||
// NSLog(@"^ %@ %f", NSStringFromCGSize([scrn size]), scrn.scale);
|
||||
decoding = [d decodeImage:scrn] == YES ? NO : YES;
|
||||
|
||||
[d release];
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)stopCapture {
|
||||
|
@ -508,18 +508,6 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||
[captureSession removeOutput:output];
|
||||
[self.prevLayer removeFromSuperlayer];
|
||||
|
||||
/*
|
||||
// heebee jeebees here ... is iOS still writing into the layer?
|
||||
if (self.prevLayer) {
|
||||
layer.session = nil;
|
||||
AVCaptureVideoPreviewLayer* layer = prevLayer;
|
||||
[self.prevLayer retain];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 12000000000), dispatch_get_main_queue(), ^{
|
||||
[layer release];
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
self.prevLayer = nil;
|
||||
self.captureSession = nil;
|
||||
#endif
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
}
|
||||
|
||||
- (void)populateActions {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"creating action to open URL '%@'", self.urlString);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -53,23 +53,23 @@ static NSMutableSet *sResultParsers = nil;
|
|||
|
||||
+ (ParsedResult *)parsedResultForString:(NSString *)s
|
||||
format:(BarcodeFormat)barcodeFormat {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"parsing result:\n<<<\n%@\n>>>\n", s);
|
||||
#endif
|
||||
for (Class c in [self resultParsers]) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"trying %@", NSStringFromClass(c));
|
||||
#endif
|
||||
ParsedResult *result = [c parsedResultForString:s format:barcodeFormat];
|
||||
if (result != nil) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"parsed as %@ %@", NSStringFromClass([result class]), result);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"No result parsers matched. Falling back to text.");
|
||||
#endif
|
||||
return [TextResultParser parsedResultForString:s format:barcodeFormat];
|
||||
|
|
|
@ -69,16 +69,16 @@ static NSMutableArray *sTheResultParsers = nil;
|
|||
|
||||
+ (ParsedResult *)parsedResultForString:(NSString *)s
|
||||
format:(BarcodeFormat)format {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"parsing result:\n<<<\n%@\n>>>\n", s);
|
||||
#endif
|
||||
for (Class c in sTheResultParsers) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"trying %@", NSStringFromClass(c));
|
||||
#endif
|
||||
ParsedResult *result = [c parsedResultForString:s format:format];
|
||||
if (result != nil) {
|
||||
#ifdef DEBUG
|
||||
#ifdef ZXING_DEBUG
|
||||
NSLog(@"parsed as %@ %@", NSStringFromClass([result class]), result);
|
||||
#endif
|
||||
return result;
|
||||
|
|
3
iphone/legacy/Barcodes_original/.gitignore
vendored
3
iphone/legacy/Barcodes_original/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
/build
|
||||
/ZXing.xcodeproj/*.mode1v3
|
||||
/ZXing.xcodeproj/*.pbxuser
|
|
@ -1,51 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,224 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// ArchiveController.h
|
||||
// UIShowcase
|
||||
//
|
||||
// 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>
|
||||
|
||||
@class DecoderViewController;
|
||||
|
||||
@interface ArchiveController : UITableViewController {
|
||||
NSMutableArray *scans;
|
||||
NSMutableArray *results;
|
||||
DecoderViewController *decoderViewController;
|
||||
NSDateFormatter *dateFormatter;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *scans;
|
||||
@property (nonatomic, retain) NSMutableArray *results;
|
||||
@property (nonatomic, retain) DecoderViewController *decoderViewController;
|
||||
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
|
||||
|
||||
- (NSInteger)scanIndexForRow:(NSInteger)row;
|
||||
- (id)initWithDecoderViewController:(DecoderViewController *)dc;
|
||||
|
||||
@end
|
|
@ -1,161 +0,0 @@
|
|||
//
|
||||
// ArchiveController.m
|
||||
// UIShowcase
|
||||
//
|
||||
// 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 "ArchiveController.h"
|
||||
#import "Database.h"
|
||||
#import "Scan.h"
|
||||
#import "ResultParser.h"
|
||||
#import "ParsedResult.h"
|
||||
#import "DecoderViewController.h"
|
||||
#import "ScanViewController.h"
|
||||
#import "ScanCell.h"
|
||||
|
||||
@implementation ArchiveController
|
||||
|
||||
@synthesize scans;
|
||||
@synthesize results;
|
||||
@synthesize decoderViewController;
|
||||
@synthesize dateFormatter;
|
||||
|
||||
- (id)initWithDecoderViewController:(DecoderViewController *)dc {
|
||||
if ((self = [super initWithStyle:UITableViewStylePlain])) {
|
||||
decoderViewController = [dc retain];
|
||||
scans = [[NSMutableArray alloc] init];
|
||||
results = [[NSMutableArray alloc] init];
|
||||
dateFormatter = [[NSDateFormatter alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return [scans count];
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 44.0;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
static NSString *ScanIdentifier = @"ScanIdentifier";
|
||||
|
||||
ScanCell *cell = (ScanCell *)[tableView dequeueReusableCellWithIdentifier:ScanIdentifier];
|
||||
if (cell == nil) {
|
||||
cell = [[[ScanCell alloc] initWithFrame:CGRectZero reuseIdentifier:ScanIdentifier] autorelease];
|
||||
}
|
||||
|
||||
// Configure the cell
|
||||
int idx = [self scanIndexForRow:indexPath.row];
|
||||
Scan *scan = [scans objectAtIndex:idx];
|
||||
[cell setScan:scan];
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
//[decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]];
|
||||
int idx = [self scanIndexForRow:indexPath.row];
|
||||
Scan *scan = [scans objectAtIndex:idx];
|
||||
ParsedResult *result = [results objectAtIndex:idx];
|
||||
ScanViewController *scanViewController = [[ScanViewController alloc] initWithResult:result forScan:scan];
|
||||
[self.navigationController pushViewController:scanViewController animated:YES];
|
||||
[scanViewController release];
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
int idx = [self scanIndexForRow:indexPath.row];
|
||||
Scan *scan = [self.scans objectAtIndex:idx];
|
||||
// delete the scan from the database ...
|
||||
[[Database sharedDatabase] deleteScan:scan];
|
||||
// ... delete the scan from our in-memory cache of the database ...
|
||||
[scans removeObjectAtIndex:idx];
|
||||
// ... delete the corresponding result from our in-memory cache ...
|
||||
[results removeObjectAtIndex:idx];
|
||||
// ... and remove the row from the table view.
|
||||
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
// [tableView reloadData];
|
||||
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
// no insertions!
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[scans release];
|
||||
[results release];
|
||||
[decoderViewController release];
|
||||
[dateFormatter release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.title = NSLocalizedString(@"ScanArchiveTitle", @"Scan Archive");
|
||||
self.navigationItem.rightBarButtonItem = [self editButtonItem];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
self.scans = [NSMutableArray arrayWithArray:[[Database sharedDatabase] scans]];
|
||||
self.results = [NSMutableArray arrayWithCapacity:self.scans.count];
|
||||
for (Scan *scan in scans) {
|
||||
[results addObject:[ResultParser parsedResultForString:scan.text]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
self.scans = nil;
|
||||
self.results = nil;
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
}
|
||||
|
||||
- (NSInteger)scanIndexForRow:(NSInteger)row {
|
||||
return scans.count - 1 - row;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,84 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,67 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// Database.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 <sqlite3.h>
|
||||
|
||||
@class Scan;
|
||||
|
||||
@interface Database : NSObject {
|
||||
sqlite3 *connection;
|
||||
int nextScanIdent;
|
||||
}
|
||||
|
||||
@property sqlite3 *connection;
|
||||
@property int nextScanIdent;
|
||||
|
||||
+ (id)sharedDatabase;
|
||||
|
||||
- (void)addScanWithText:(NSString *)text;
|
||||
- (NSArray *)scans;
|
||||
- (void)deleteScan:(Scan *)scan;
|
||||
|
||||
@end
|
|
@ -1,115 +0,0 @@
|
|||
//
|
||||
// Database.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 "Database.h"
|
||||
#import "Scan.h"
|
||||
|
||||
@implementation Database
|
||||
|
||||
static sqlite3_stmt *maxIdStatement;
|
||||
static sqlite3_stmt *selectAllStatement;
|
||||
static sqlite3_stmt *insertStatement;
|
||||
static sqlite3_stmt *deleteStatement;
|
||||
|
||||
@synthesize connection;
|
||||
@synthesize nextScanIdent;
|
||||
|
||||
static Database *sharedDatabase = nil;
|
||||
|
||||
+ (id)sharedDatabase {
|
||||
if (!sharedDatabase) {
|
||||
sharedDatabase = [[self alloc] init];
|
||||
|
||||
BOOL success;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSError *error;
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDirectory = [paths objectAtIndex:0];
|
||||
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"scans.db"];
|
||||
success = [fileManager fileExistsAtPath:writableDBPath];
|
||||
if (!success) {
|
||||
// The writable database does not exist, so copy the default to the appropriate location.
|
||||
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"scans.db"];
|
||||
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
|
||||
if (!success) {
|
||||
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3 *connection;
|
||||
sqlite3_open([writableDBPath UTF8String], &connection);
|
||||
sharedDatabase.connection = connection;
|
||||
|
||||
static const char *maxIdSql = "SELECT MAX(id) FROM SCAN";
|
||||
sqlite3_prepare_v2(connection, maxIdSql, -1, &maxIdStatement, NULL);
|
||||
|
||||
static const char *selectAllSql = "SELECT id, text, stamp FROM SCAN ORDER BY id";
|
||||
sqlite3_prepare_v2(connection, selectAllSql, -1, &selectAllStatement, NULL);
|
||||
|
||||
static const char *insertSql =
|
||||
"INSERT INTO SCAN (id, text, stamp) VALUES (?, ?, ?)";
|
||||
sqlite3_prepare_v2(connection, insertSql, -1, &insertStatement, NULL);
|
||||
|
||||
static const char *deleteSql = "DELETE FROM SCAN WHERE id = ?";
|
||||
sqlite3_prepare_v2(connection, deleteSql, -1, &deleteStatement, NULL);
|
||||
|
||||
if (SQLITE_ROW == sqlite3_step(maxIdStatement)) {
|
||||
int maxId = sqlite3_column_int(maxIdStatement, 0);
|
||||
sharedDatabase.nextScanIdent = maxId + 1;
|
||||
sqlite3_reset(maxIdStatement);
|
||||
} else {
|
||||
NSLog(@"failed to read max ID from database\n");
|
||||
}
|
||||
|
||||
}
|
||||
return sharedDatabase;
|
||||
}
|
||||
|
||||
- (void)addScanWithText:(NSString *)text {
|
||||
sqlite3_bind_int(insertStatement, 1, nextScanIdent++);
|
||||
sqlite3_bind_text(insertStatement, 2, [text UTF8String], -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_double(insertStatement, 3, [[NSDate date] timeIntervalSince1970]);
|
||||
sqlite3_step(insertStatement);
|
||||
sqlite3_reset(insertStatement);
|
||||
}
|
||||
|
||||
- (NSArray *)scans {
|
||||
NSMutableArray *scans = [NSMutableArray array];
|
||||
while (SQLITE_ROW == sqlite3_step(selectAllStatement)) {
|
||||
int ident = sqlite3_column_int(selectAllStatement, 0);
|
||||
NSString *text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectAllStatement, 1)];
|
||||
NSDate *stamp = [NSDate dateWithTimeIntervalSince1970:sqlite3_column_double(selectAllStatement, 2)];
|
||||
Scan *scan = [[Scan alloc] initWithIdent:ident text:text stamp:stamp];
|
||||
[scans addObject:scan];
|
||||
[scan release];
|
||||
}
|
||||
sqlite3_reset(selectAllStatement);
|
||||
return scans;
|
||||
}
|
||||
|
||||
- (void)deleteScan:(Scan *)scan {
|
||||
sqlite3_bind_int(deleteStatement, 1, [scan ident]);
|
||||
sqlite3_step(deleteStatement);
|
||||
sqlite3_reset(deleteStatement);
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,266 +0,0 @@
|
|||
//
|
||||
// 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];
|
||||
}
|
||||
|
||||
[result release];
|
||||
}
|
||||
|
||||
- (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];
|
||||
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] retain];
|
||||
} 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
|
||||
|
||||
free(subsetData);
|
||||
self.subsetData = NULL;
|
||||
|
||||
if (decoderResult) {
|
||||
[self performSelectorOnMainThread:@selector(didDecodeImage:)
|
||||
withObject:decoderResult
|
||||
waitUntilDone:NO];
|
||||
} else {
|
||||
[self performSelectorOnMainThread:@selector(failedToDecodeImage:)
|
||||
withObject:NSLocalizedString(@"Decoder BarcodeDetectionFailure", @"No barcode detected.")
|
||||
waitUntilDone:NO];
|
||||
}
|
||||
}
|
||||
[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, i.size.width, i.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
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,98 +0,0 @@
|
|||
//
|
||||
// DecoderViewController.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>
|
||||
#import "Decoder.h"
|
||||
#import "DecoderDelegate.h"
|
||||
#import "ScannedImageView.h"
|
||||
|
||||
@class ParsedResult;
|
||||
@class Scan;
|
||||
@class TwoDDecoderResult;
|
||||
@class ResultAction;
|
||||
|
||||
|
||||
@interface DecoderViewController : UIViewController <DecoderDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate> {
|
||||
IBOutlet UIBarItem *cameraBarItem;
|
||||
IBOutlet UIBarItem *savedPhotosBarItem;
|
||||
IBOutlet UIBarItem *libraryBarItem;
|
||||
IBOutlet UIBarItem *archiveBarItem;
|
||||
IBOutlet UIBarItem *actionBarItem;
|
||||
|
||||
IBOutlet UIView *messageView;
|
||||
IBOutlet UITextView *messageTextView;
|
||||
IBOutlet UIButton *messageHelpButton;
|
||||
IBOutlet ScannedImageView *imageView;
|
||||
IBOutlet UIToolbar *toolbar;
|
||||
UIImagePickerController *picker;
|
||||
|
||||
Decoder *decoder;
|
||||
ParsedResult *result;
|
||||
NSArray *actions;
|
||||
|
||||
NSMutableArray *resultPointViews;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) UIBarItem *cameraBarItem;
|
||||
@property (nonatomic, retain) UIBarItem *savedPhotosBarItem;
|
||||
@property (nonatomic, retain) UIBarItem *libraryBarItem;
|
||||
@property (nonatomic, retain) UIBarItem *archiveBarItem;
|
||||
@property (nonatomic, retain) UIBarItem *actionBarItem;
|
||||
|
||||
@property (nonatomic, retain) UIView *messageView;
|
||||
@property (nonatomic, retain) UITextView *messageTextView;
|
||||
@property (nonatomic, retain) UIButton *messageHelpButton;
|
||||
@property (nonatomic, retain) ScannedImageView *imageView;
|
||||
@property (nonatomic, retain) UIImagePickerController *picker;
|
||||
@property (nonatomic, retain) UIToolbar *toolbar;
|
||||
|
||||
@property (nonatomic, retain) Decoder *decoder;
|
||||
@property (nonatomic, retain) ParsedResult *result;
|
||||
@property (nonatomic, retain) NSArray *actions;
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *resultPointViews;
|
||||
|
||||
- (void)clearImageView;
|
||||
- (void)updateToolbar;
|
||||
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType;
|
||||
- (IBAction)pickAndDecode:(id)sender;
|
||||
- (void)showMessage:(NSString *)message helpButton:(BOOL)showHelpButton;
|
||||
- (IBAction)performResultAction:(id)sender;
|
||||
- (IBAction)showArchive:(id)sender;
|
||||
- (void)showScan:(Scan *)scan;
|
||||
|
||||
/* DecoderDelegate methods */
|
||||
|
||||
- (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;
|
||||
|
||||
/* UIImagePickerControllerDelegate methods */
|
||||
|
||||
- (void)imagePickerController:(UIImagePickerController *)picker
|
||||
didFinishPickingMediaWithInfo:(NSDictionary *)info;
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
|
||||
|
||||
/* UINavigationControllerDelegate methods */
|
||||
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
|
||||
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
|
||||
|
||||
@end
|
|
@ -1,630 +0,0 @@
|
|||
//
|
||||
// DecoderViewController.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 "DecoderViewController.h"
|
||||
#import "Decoder.h"
|
||||
#import "NSString+HTML.h"
|
||||
#import "ResultParser.h"
|
||||
#import "ParsedResult.h"
|
||||
#import "ResultAction.h"
|
||||
|
||||
#import "Database.h"
|
||||
#import "ArchiveController.h"
|
||||
#import "MessageViewController.h"
|
||||
#import "Scan.h"
|
||||
#import "TwoDDecoderResult.h"
|
||||
|
||||
// Michael Jurewitz, Dec 16, 2009 6:32 PM writes:
|
||||
// https://devforums.apple.com/message/149553
|
||||
// Notice Regarding UIGetScreenImage()
|
||||
// After carefully considering the issue, Apple is now allowing applications to
|
||||
// use the function UIGetScreenImage() to programmatically capture the current
|
||||
// screen contents.
|
||||
// Note that a future release of iPhone OS may provide a public API equivalent
|
||||
// of this functionality. At such time, all applications using
|
||||
// UIGetScreenImage() will be required to adopt the public API.
|
||||
CGImageRef MyCGImageCopyScreenContents(void) {
|
||||
extern CGImageRef UIGetScreenImage(void);
|
||||
return UIGetScreenImage(); /* already retained */
|
||||
}
|
||||
|
||||
@interface DecoderViewController()
|
||||
- (void)takeScreenshot;
|
||||
@end
|
||||
|
||||
@implementation DecoderViewController
|
||||
|
||||
@synthesize cameraBarItem;
|
||||
@synthesize libraryBarItem;
|
||||
@synthesize savedPhotosBarItem;
|
||||
@synthesize archiveBarItem;
|
||||
@synthesize actionBarItem;
|
||||
|
||||
@synthesize messageView;
|
||||
@synthesize messageTextView;
|
||||
@synthesize messageHelpButton;
|
||||
@synthesize imageView;
|
||||
@synthesize picker;
|
||||
@synthesize toolbar;
|
||||
|
||||
@synthesize decoder;
|
||||
@synthesize result;
|
||||
@synthesize actions;
|
||||
|
||||
@synthesize resultPointViews;
|
||||
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
||||
// Initialization code
|
||||
self.title =
|
||||
NSLocalizedString(@"DecoderViewController AppTitle", @"Barcode Scanner");
|
||||
|
||||
Decoder *d = [[Decoder alloc] init];
|
||||
self.decoder = d;
|
||||
d.delegate = self;
|
||||
[d release];
|
||||
resultPointViews = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) messageReady:(id)sender {
|
||||
MessageViewController *messageController = sender;
|
||||
[[self navigationController] pushViewController:messageController animated:true];
|
||||
[messageController release];
|
||||
}
|
||||
|
||||
- (void) messageFailed:(id)sender {
|
||||
MessageViewController *messageController = sender;
|
||||
NSLog(@"Failed to load message!");
|
||||
[messageController release];
|
||||
}
|
||||
|
||||
- (void) showHints:(id)sender {
|
||||
NSLog(@"Showing Hints!");
|
||||
|
||||
MessageViewController *hintsController =
|
||||
[[MessageViewController alloc] initWithMessageFilename:@"Hints"
|
||||
target:self
|
||||
onSuccess:@selector(messageReady:)
|
||||
onFailure:@selector(messageFailed:)];
|
||||
hintsController.title =
|
||||
NSLocalizedString(@"DecoderViewController Hints MessageViewController title", @"Hints");
|
||||
[hintsController view];
|
||||
}
|
||||
|
||||
- (void) showAbout:(id)sender {
|
||||
NSLog(@"Showing About!");
|
||||
|
||||
MessageViewController *aboutController =
|
||||
[[MessageViewController alloc] initWithMessageFilename:@"About"
|
||||
target:self
|
||||
onSuccess:@selector(messageReady:)
|
||||
onFailure:@selector(messageFailed:)];
|
||||
aboutController.title =
|
||||
NSLocalizedString(@"DecoderViewController About MessageViewController title", @"About");
|
||||
[aboutController view];
|
||||
}
|
||||
|
||||
|
||||
#define HELP_BUTTON_WIDTH (44.0)
|
||||
#define HELP_BUTTON_HEIGHT (55.0)
|
||||
|
||||
|
||||
#define FONT_NAME @"TimesNewRomanPSMT"
|
||||
#define FONT_SIZE 16.0
|
||||
|
||||
- (void) reset {
|
||||
self.result = nil;
|
||||
[self clearImageView];
|
||||
[self updateToolbar];
|
||||
[self showMessage:NSLocalizedString(@"DecoderViewController take or choose picture",
|
||||
@"Please take or choose a picture containing a barcode") helpButton:YES];
|
||||
}
|
||||
|
||||
// Implement loadView if you want to create a view hierarchy programmatically
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
|
||||
CGRect messageViewFrame = imageView.frame;
|
||||
UIView *mView = [[UIView alloc] initWithFrame:messageViewFrame];
|
||||
mView.backgroundColor = [UIColor darkGrayColor];
|
||||
mView.alpha = 0.9;
|
||||
mView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
|
||||
UIViewAutoresizingFlexibleWidth |
|
||||
UIViewAutoresizingFlexibleTopMargin;
|
||||
|
||||
UITextView *mTextView = [[UITextView alloc] initWithFrame:messageViewFrame];
|
||||
mTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
|
||||
UIViewAutoresizingFlexibleWidth;
|
||||
mTextView.editable = false;
|
||||
mTextView.scrollEnabled = true;
|
||||
mTextView.font = [UIFont fontWithName:FONT_NAME size:FONT_SIZE];
|
||||
mTextView.textColor = [UIColor whiteColor];
|
||||
mTextView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.0];
|
||||
mTextView.textAlignment = UITextAlignmentLeft;
|
||||
mTextView.alpha = 1.0;
|
||||
[mView addSubview:mTextView];
|
||||
|
||||
UIButton *mHelpButton = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
|
||||
mHelpButton.frame = CGRectMake(messageViewFrame.size.width - HELP_BUTTON_WIDTH, 0.0, HELP_BUTTON_WIDTH, HELP_BUTTON_HEIGHT);
|
||||
|
||||
mHelpButton.backgroundColor = [UIColor clearColor];
|
||||
[mHelpButton setUserInteractionEnabled:YES];
|
||||
[mHelpButton addTarget:self action:@selector(showHints:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
self.messageHelpButton = mHelpButton;
|
||||
[mHelpButton release];
|
||||
|
||||
self.messageTextView = mTextView;
|
||||
[mTextView release];
|
||||
|
||||
self.messageView = mView;
|
||||
[mView release];
|
||||
|
||||
[self.view addSubview:self.messageView];
|
||||
|
||||
// add the 'About' button at the top-right of the navigation bar
|
||||
UIBarButtonItem *aboutButton =
|
||||
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"DecoderViewController about button title", @"About")
|
||||
style:UIBarButtonItemStyleBordered
|
||||
target:self
|
||||
action:@selector(showAbout:)];
|
||||
self.navigationItem.rightBarButtonItem = aboutButton;
|
||||
[aboutButton release];
|
||||
|
||||
[self reset];
|
||||
}
|
||||
|
||||
- (void) updateToolbar {
|
||||
self.cameraBarItem.enabled = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
|
||||
self.savedPhotosBarItem.enabled = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
|
||||
self.libraryBarItem.enabled = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
|
||||
self.archiveBarItem.enabled = true;
|
||||
self.actionBarItem.enabled = (self.result != nil) && ([self.result actions] != nil) && ([self.result actions].count > 0);
|
||||
}
|
||||
|
||||
|
||||
// If you need to do additional setup after loading the view, override viewDidLoad.
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
|
||||
- (void)clearImageView {
|
||||
imageView.image = nil;
|
||||
for (UIView *view in resultPointViews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
[resultPointViews removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType {
|
||||
[self reset];
|
||||
|
||||
// Create the Image Picker
|
||||
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
|
||||
UIImagePickerController* aPicker =
|
||||
[[[UIImagePickerController alloc] init] autorelease];
|
||||
aPicker.sourceType = sourceType;
|
||||
aPicker.delegate = self;
|
||||
self.picker = aPicker;
|
||||
|
||||
// [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"];
|
||||
BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera);
|
||||
if ([picker respondsToSelector:@selector(setAllowsEditing:)]) {
|
||||
// not in 3.0
|
||||
[picker setAllowsEditing:!isCamera];
|
||||
}
|
||||
if (isCamera) {
|
||||
if ([picker respondsToSelector:@selector(setShowsCameraControls:)]) {
|
||||
[picker setShowsCameraControls:NO];
|
||||
UIButton *cancelButton =
|
||||
[UIButton buttonWithType:UIButtonTypeRoundedRect];
|
||||
NSString *cancelString =
|
||||
NSLocalizedString(@"DecoderViewController cancel button title", @"");
|
||||
CGFloat height = [UIFont systemFontSize];
|
||||
CGSize size =
|
||||
[cancelString sizeWithFont:[UIFont systemFontOfSize:height]];
|
||||
[cancelButton setTitle:cancelString forState:UIControlStateNormal];
|
||||
CGRect appFrame = [[UIScreen mainScreen] bounds];
|
||||
static const int kMargin = 10;
|
||||
static const int kInternalXMargin = 10;
|
||||
static const int kInternalYMargin = 10;
|
||||
CGRect frame = CGRectMake(kMargin,
|
||||
appFrame.size.height - (height + 2*kInternalYMargin + kMargin),
|
||||
2*kInternalXMargin + size.width,
|
||||
height + 2*kInternalYMargin);
|
||||
[cancelButton setFrame:frame];
|
||||
[cancelButton addTarget:self
|
||||
action:@selector(cancel:)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
picker.cameraOverlayView = cancelButton;
|
||||
// The camera takes quite a while to start up. Hence the 2 second delay.
|
||||
[self performSelector:@selector(takeScreenshot)
|
||||
withObject:nil
|
||||
afterDelay:2.0];
|
||||
}
|
||||
}
|
||||
|
||||
// Picker is displayed asynchronously.
|
||||
[self presentModalViewController:picker animated:YES];
|
||||
} else {
|
||||
NSLog(@"Attempted to pick an image with illegal source type '%d'", sourceType);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)pickAndDecode:(id) sender {
|
||||
UIImagePickerControllerSourceType sourceType;
|
||||
int i = [sender tag];
|
||||
|
||||
switch (i) {
|
||||
case 0: sourceType = UIImagePickerControllerSourceTypeCamera; break;
|
||||
case 1: sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; break;
|
||||
case 2: sourceType = UIImagePickerControllerSourceTypePhotoLibrary; break;
|
||||
default: sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
|
||||
}
|
||||
[self pickAndDecodeFromSource:sourceType];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
// Return YES for supported orientations
|
||||
return (interfaceOrientation == UIInterfaceOrientationPortrait);
|
||||
}
|
||||
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
|
||||
// Release anything that's not essential, such as cached data
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[decoder release];
|
||||
[self clearImageView];
|
||||
[imageView release];
|
||||
[actionBarItem release];
|
||||
[cameraBarItem release];
|
||||
[libraryBarItem release];
|
||||
[savedPhotosBarItem release];
|
||||
[archiveBarItem release];
|
||||
[toolbar release];
|
||||
[picker release];
|
||||
[actions release];
|
||||
[resultPointViews release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)showMessage:(NSString *)message helpButton:(BOOL)showHelpButton {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"Showing message '%@' %@ help Button", message, showHelpButton ? @"with" : @"without");
|
||||
#endif
|
||||
|
||||
CGSize imageMaxSize = imageView.bounds.size;
|
||||
if (showHelpButton) {
|
||||
imageMaxSize.width -= messageHelpButton.frame.size.width;
|
||||
}
|
||||
CGSize size = [message sizeWithFont:messageTextView.font constrainedToSize:imageMaxSize lineBreakMode:UILineBreakModeWordWrap];
|
||||
float height = 20.0 + fmin(100.0, size.height);
|
||||
if (showHelpButton) {
|
||||
height = fmax(HELP_BUTTON_HEIGHT, height);
|
||||
}
|
||||
|
||||
CGRect messageFrame = imageView.bounds;
|
||||
messageFrame.origin.y = CGRectGetMaxY(messageFrame) - height;
|
||||
messageFrame.size.height = height;
|
||||
[self.messageView setFrame:messageFrame];
|
||||
messageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
|
||||
CGRect messageViewBounds = [messageView bounds];
|
||||
|
||||
self.messageTextView.text = message;
|
||||
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
if (showHelpButton) {
|
||||
CGRect textViewFrame;
|
||||
CGRect helpButtonFrame;
|
||||
|
||||
CGRectDivide(messageViewBounds, &helpButtonFrame, &textViewFrame, HELP_BUTTON_WIDTH, CGRectMaxXEdge);
|
||||
[self.messageTextView setFrame:textViewFrame];
|
||||
|
||||
[messageHelpButton setFrame:helpButtonFrame];
|
||||
messageHelpButton.alpha = 1.0;
|
||||
messageHelpButton.enabled = YES;
|
||||
messageHelpButton.autoresizingMask =
|
||||
UIViewAutoresizingFlexibleLeftMargin |
|
||||
UIViewAutoresizingFlexibleTopMargin;
|
||||
[messageView addSubview:messageHelpButton];
|
||||
} else {
|
||||
[messageHelpButton removeFromSuperview];
|
||||
messageHelpButton.alpha = 0.0;
|
||||
messageHelpButton.enabled = NO;
|
||||
|
||||
[self.messageTextView setFrame:messageViewBounds];
|
||||
}
|
||||
}
|
||||
|
||||
// DecoderDelegate methods
|
||||
|
||||
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{
|
||||
[self clearImageView];
|
||||
[self.imageView setImage:subset];
|
||||
[self showMessage:[NSString stringWithFormat:NSLocalizedString(@"DecoderViewController MessageWhileDecodingWithDimensions", @"Decoding image (%.0fx%.0f) ..."), image.size.width, image.size.height]
|
||||
helpButton:NO];
|
||||
}
|
||||
|
||||
- (void)decoder:(Decoder *)decoder
|
||||
decodingImage:(UIImage *)image
|
||||
usingSubset:(UIImage *)subset
|
||||
progress:(NSString *)message {
|
||||
[self clearImageView];
|
||||
[self.imageView setImage:subset];
|
||||
[self showMessage:message helpButton:NO];
|
||||
}
|
||||
|
||||
- (void)presentResultForString:(NSString *)resultString {
|
||||
self.result = [ResultParser parsedResultForString:resultString];
|
||||
[self showMessage:[self.result stringForDisplay] helpButton:NO];
|
||||
self.actions = self.result.actions;
|
||||
#ifdef DEBUG
|
||||
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
|
||||
imageView.image = subset;
|
||||
for (NSValue *pointValue in resultPoints) {
|
||||
[imageView addResultPoint:[pointValue CGPointValue]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {
|
||||
self.picker = nil;
|
||||
[self presentResultForString:twoDResult.text];
|
||||
|
||||
[self presentResultPoints:twoDResult.points forImage:image usingSubset:subset];
|
||||
|
||||
// save the scan to the shared database
|
||||
[[Database sharedDatabase] addScanWithText:twoDResult.text];
|
||||
|
||||
[self performResultAction:self];
|
||||
}
|
||||
|
||||
- (void)decoder:(Decoder *)decoder failedToDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset reason:(NSString *)reason {
|
||||
if (self.picker && UIImagePickerControllerSourceTypeCamera == self.picker.sourceType) {
|
||||
// If we are using the camera, and the user hasn't manually cancelled,
|
||||
// take another snapshot and try to decode it.
|
||||
[self takeScreenshot];
|
||||
} else {
|
||||
[self showMessage:reason helpButton:YES];
|
||||
[self updateToolbar];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
||||
[super willAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
|
||||
|
||||
if (imageView.image) {
|
||||
/*
|
||||
CGRect viewBounds = imageView.bounds;
|
||||
CGSize imageSize = imageView.image.size;
|
||||
float scale = fmin(viewBounds.size.width / imageSize.width,
|
||||
viewBounds.size.height / imageSize.height);
|
||||
float xOffset = (viewBounds.size.width - scale * imageSize.width) / 2.0;
|
||||
float yOffset = (viewBounds.size.height - scale * imageSize.height) / 2.0;
|
||||
*/
|
||||
|
||||
for (UIView *view in resultPointViews) {
|
||||
view.alpha = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
|
||||
[super willAnimateSecondHalfOfRotationFromInterfaceOrientation:fromInterfaceOrientation duration:duration];
|
||||
|
||||
if (imageView.image) {
|
||||
/*
|
||||
CGRect viewBounds = imageView.bounds;
|
||||
CGSize imageSize = imageView.image.size;
|
||||
float scale = fmin(viewBounds.size.width / imageSize.width,
|
||||
viewBounds.size.height / imageSize.height);
|
||||
float xOffset = (viewBounds.size.width - scale * imageSize.width) / 2.0;
|
||||
float yOffset = (viewBounds.size.height - scale * imageSize.height) / 2.0;
|
||||
*/
|
||||
|
||||
for (UIView *view in resultPointViews) {
|
||||
view.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancel:(id)sender {
|
||||
self.picker = nil;
|
||||
}
|
||||
|
||||
- (void)takeScreenshot {
|
||||
if (picker) {
|
||||
CGImageRef cgScreen = MyCGImageCopyScreenContents();
|
||||
if (cgScreen) {
|
||||
CGRect croppedFrame = CGRectMake(0, 0, CGImageGetWidth(cgScreen),
|
||||
CGImageGetHeight(cgScreen) - (10+toolbar.bounds.size.height));
|
||||
CGImageRef cgCropped = CGImageCreateWithImageInRect(cgScreen, croppedFrame);
|
||||
if (cgCropped) {
|
||||
UIImage *screenshot = [UIImage imageWithCGImage:cgCropped];
|
||||
CGImageRelease(cgCropped);
|
||||
[self.decoder decodeImage:screenshot];
|
||||
}
|
||||
CGImageRelease(cgScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UIImagePickerControllerDelegate methods
|
||||
|
||||
- (void)imagePickerController:(UIImagePickerController *)aPicker
|
||||
didFinishPickingMediaWithInfo:(NSDictionary *)info {
|
||||
UIImage *imageToDecode =
|
||||
[info objectForKey:UIImagePickerControllerEditedImage];
|
||||
if (!imageToDecode) {
|
||||
imageToDecode = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
}
|
||||
CGSize size = [imageToDecode size];
|
||||
CGRect cropRect = CGRectMake(0.0, 0.0, size.width, size.height);
|
||||
|
||||
#ifdef DEBUG
|
||||
NSLog(@"picked image size = (%f, %f)", size.width, size.height);
|
||||
#endif
|
||||
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
|
||||
|
||||
NSValue *cropRectValue = [info objectForKey:UIImagePickerControllerCropRect];
|
||||
if (cropRectValue) {
|
||||
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
if (originalImage) {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"original image size = (%f, %f)", originalImage.size.width, originalImage.size.height);
|
||||
#endif
|
||||
cropRect = [cropRectValue CGRectValue];
|
||||
#ifdef DEBUG
|
||||
NSLog(@"crop rect = (%f, %f) x (%f, %f)", CGRectGetMinX(cropRect), CGRectGetMinY(cropRect), CGRectGetWidth(cropRect), CGRectGetHeight(cropRect));
|
||||
#endif
|
||||
if (([picker sourceType] == UIImagePickerControllerSourceTypeSavedPhotosAlbum) &&
|
||||
[@"2.1" isEqualToString:systemVersion]) {
|
||||
// adjust crop rect to work around bug in iPhone OS 2.1 when selecting from the photo roll
|
||||
cropRect.origin.x *= 2.5;
|
||||
cropRect.origin.y *= 2.5;
|
||||
cropRect.size.width *= 2.5;
|
||||
cropRect.size.height *= 2.5;
|
||||
#ifdef DEBUG
|
||||
NSLog(@"2.1-adjusted crop rect = (%f, %f) x (%f, %f)", CGRectGetMinX(cropRect), CGRectGetMinY(cropRect), CGRectGetWidth(cropRect), CGRectGetHeight(cropRect));
|
||||
#endif
|
||||
}
|
||||
|
||||
imageToDecode = originalImage;
|
||||
}
|
||||
}
|
||||
|
||||
[imageToDecode retain];
|
||||
self.picker = nil;
|
||||
[self.decoder decodeImage:imageToDecode cropRect:cropRect];
|
||||
[imageToDecode release];
|
||||
}
|
||||
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)aPicker {
|
||||
self.picker = nil;
|
||||
}
|
||||
|
||||
- (void)setPicker:(UIImagePickerController *)aPicker {
|
||||
if (picker != aPicker) {
|
||||
[picker dismissModalViewControllerAnimated:YES];
|
||||
picker = [aPicker retain];
|
||||
[self updateToolbar];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)navigationController:(UINavigationController *)navigationController
|
||||
didShowViewController:(UIViewController *)viewController
|
||||
animated:(BOOL)animated {
|
||||
// no-op
|
||||
}
|
||||
|
||||
- (void)navigationController:(UINavigationController *)navigationController
|
||||
willShowViewController:(UIViewController *)viewController
|
||||
animated:(BOOL)animated {
|
||||
// no-op
|
||||
}
|
||||
|
||||
- (void)performAction:(ResultAction *)action {
|
||||
[action performActionWithController:self shouldConfirm:NO];
|
||||
}
|
||||
|
||||
- (void)confirmAndPerformAction:(ResultAction *)action {
|
||||
[action performActionWithController:self shouldConfirm:YES];
|
||||
}
|
||||
|
||||
|
||||
- (IBAction)performResultAction:(id)sender {
|
||||
if (self.result == nil) {
|
||||
NSLog(@"no result to perform an action on!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.actions == nil || self.actions.count == 0) {
|
||||
NSLog(@"result has no actions to perform!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.actions.count == 1) {
|
||||
ResultAction *action = [self.actions lastObject];
|
||||
#ifdef DEBUG
|
||||
NSLog(@"Result has the single action, (%@) '%@', performing it",
|
||||
NSStringFromClass([action class]), [action title]);
|
||||
#endif
|
||||
[self performSelector:@selector(confirmAndPerformAction:)
|
||||
withObject:action
|
||||
afterDelay:0.0];
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"Result has multiple actions, popping up an action sheet");
|
||||
#endif
|
||||
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithFrame:self.view.bounds];
|
||||
|
||||
for (ResultAction *action in self.actions) {
|
||||
[actionSheet addButtonWithTitle:[action title]];
|
||||
}
|
||||
|
||||
int cancelIndex = [actionSheet addButtonWithTitle:NSLocalizedString(@"DecoderViewController cancel button title", @"Cancel")];
|
||||
actionSheet.cancelButtonIndex = cancelIndex;
|
||||
|
||||
actionSheet.delegate = self;
|
||||
|
||||
[actionSheet showFromToolbar:self.toolbar];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
|
||||
if (buttonIndex < self.actions.count) {
|
||||
int actionIndex = buttonIndex;
|
||||
ResultAction *action = [self.actions objectAtIndex:actionIndex];
|
||||
[self performSelector:@selector(performAction:)
|
||||
withObject:action
|
||||
afterDelay:0.0];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)showArchive:(id)sender {
|
||||
ArchiveController *archiveController = [[ArchiveController alloc] initWithDecoderViewController:self];
|
||||
[[self navigationController] pushViewController:archiveController animated:true];
|
||||
[archiveController release];
|
||||
}
|
||||
|
||||
- (void)showScan:(Scan *)scan {
|
||||
[self clearImageView];
|
||||
[self presentResultForString:scan.text];
|
||||
[[self navigationController] popToViewController:self animated:YES];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,439 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.02">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">512</int>
|
||||
<string key="IBDocument.SystemVersion">9D34</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">667</string>
|
||||
<string key="IBDocument.AppKitVersion">949.33</string>
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="1"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBProxyObject" id="372490531">
|
||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
||||
</object>
|
||||
<object class="IBProxyObject" id="1031470122">
|
||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
||||
</object>
|
||||
<object class="IBUIView" id="191373211">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBUIImageView" id="752226104">
|
||||
<reference key="NSNextResponder" ref="191373211"/>
|
||||
<int key="NSvFlags">274</int>
|
||||
<string key="NSFrameSize">{320, 431}</string>
|
||||
<reference key="NSSuperview" ref="191373211"/>
|
||||
<bool key="IBUIOpaque">NO</bool>
|
||||
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
|
||||
<int key="IBUIContentMode">1</int>
|
||||
<bool key="IBUIUserInteractionEnabled">NO</bool>
|
||||
</object>
|
||||
<object class="IBUIToolbar" id="17982920">
|
||||
<reference key="NSNextResponder" ref="191373211"/>
|
||||
<int key="NSvFlags">266</int>
|
||||
<string key="NSFrame">{{0, 431}, {320, 49}}</string>
|
||||
<reference key="NSSuperview" ref="191373211"/>
|
||||
<bool key="IBUIOpaque">NO</bool>
|
||||
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
|
||||
<object class="NSMutableArray" key="IBUIItems">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBUIBarButtonItem" id="536190161">
|
||||
<int key="IBUISystemItemIdentifier">15</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="89345691">
|
||||
<int key="IBUIStyle">1</int>
|
||||
<int key="IBUISystemItemIdentifier">5</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="463045255">
|
||||
<int key="IBUITag">1</int>
|
||||
<int key="IBUISystemItemIdentifier">12</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="202327917">
|
||||
<int key="IBUISystemItemIdentifier">5</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="953226107">
|
||||
<int key="IBUITag">2</int>
|
||||
<int key="IBUISystemItemIdentifier">11</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="466815205">
|
||||
<int key="IBUIStyle">1</int>
|
||||
<int key="IBUISystemItemIdentifier">5</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="802193351">
|
||||
<int key="IBUITag">16</int>
|
||||
<int key="IBUISystemItemIdentifier">10</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="461368038">
|
||||
<int key="IBUIStyle">1</int>
|
||||
<int key="IBUISystemItemIdentifier">5</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBUIBarButtonItem" id="613772718">
|
||||
<int key="IBUITag">17</int>
|
||||
<int key="IBUISystemItemIdentifier">9</int>
|
||||
<reference key="IBUIToolbar" ref="17982920"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{320, 480}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<object class="NSColor" key="IBUIBackgroundColor">
|
||||
<int key="NSColorSpace">1</int>
|
||||
<bytes key="NSRGB">MCAwIDAAA</bytes>
|
||||
</object>
|
||||
<int key="IBUIContentMode">3</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">view</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="191373211"/>
|
||||
</object>
|
||||
<int key="connectionID">9</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">imageView</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="752226104"/>
|
||||
</object>
|
||||
<int key="connectionID">18</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">actionBarItem</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="613772718"/>
|
||||
</object>
|
||||
<int key="connectionID">51</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchEventConnection" key="connection">
|
||||
<string key="label">performResultAction:</string>
|
||||
<reference key="source" ref="613772718"/>
|
||||
<reference key="destination" ref="372490531"/>
|
||||
</object>
|
||||
<int key="connectionID">53</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">toolbar</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="17982920"/>
|
||||
</object>
|
||||
<int key="connectionID">57</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchEventConnection" key="connection">
|
||||
<string key="label">pickAndDecode:</string>
|
||||
<reference key="source" ref="536190161"/>
|
||||
<reference key="destination" ref="372490531"/>
|
||||
</object>
|
||||
<int key="connectionID">60</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchEventConnection" key="connection">
|
||||
<string key="label">pickAndDecode:</string>
|
||||
<reference key="source" ref="463045255"/>
|
||||
<reference key="destination" ref="372490531"/>
|
||||
</object>
|
||||
<int key="connectionID">61</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchEventConnection" key="connection">
|
||||
<string key="label">pickAndDecode:</string>
|
||||
<reference key="source" ref="953226107"/>
|
||||
<reference key="destination" ref="372490531"/>
|
||||
</object>
|
||||
<int key="connectionID">62</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">cameraBarItem</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="536190161"/>
|
||||
</object>
|
||||
<int key="connectionID">63</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">savedPhotosBarItem</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="463045255"/>
|
||||
</object>
|
||||
<int key="connectionID">64</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">libraryBarItem</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="953226107"/>
|
||||
</object>
|
||||
<int key="connectionID">65</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">archiveBarItem</string>
|
||||
<reference key="source" ref="372490531"/>
|
||||
<reference key="destination" ref="802193351"/>
|
||||
</object>
|
||||
<int key="connectionID">66</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchEventConnection" key="connection">
|
||||
<string key="label">showArchive:</string>
|
||||
<reference key="source" ref="802193351"/>
|
||||
<reference key="destination" ref="372490531"/>
|
||||
</object>
|
||||
<int key="connectionID">67</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<object class="NSArray" key="object" id="360949347">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">1</int>
|
||||
<reference key="object" ref="191373211"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="752226104"/>
|
||||
<reference ref="17982920"/>
|
||||
</object>
|
||||
<reference key="parent" ref="360949347"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="372490531"/>
|
||||
<reference key="parent" ref="360949347"/>
|
||||
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="1031470122"/>
|
||||
<reference key="parent" ref="360949347"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">16</int>
|
||||
<reference key="object" ref="752226104"/>
|
||||
<reference key="parent" ref="191373211"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">34</int>
|
||||
<reference key="object" ref="17982920"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="536190161"/>
|
||||
<reference ref="953226107"/>
|
||||
<reference ref="802193351"/>
|
||||
<reference ref="613772718"/>
|
||||
<reference ref="89345691"/>
|
||||
<reference ref="466815205"/>
|
||||
<reference ref="461368038"/>
|
||||
<reference ref="463045255"/>
|
||||
<reference ref="202327917"/>
|
||||
</object>
|
||||
<reference key="parent" ref="191373211"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">35</int>
|
||||
<reference key="object" ref="536190161"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">36</int>
|
||||
<reference key="object" ref="953226107"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">37</int>
|
||||
<reference key="object" ref="802193351"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">38</int>
|
||||
<reference key="object" ref="613772718"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">54</int>
|
||||
<reference key="object" ref="89345691"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">55</int>
|
||||
<reference key="object" ref="466815205"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">56</int>
|
||||
<reference key="object" ref="461368038"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">58</int>
|
||||
<reference key="object" ref="463045255"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">59</int>
|
||||
<reference key="object" ref="202327917"/>
|
||||
<reference key="parent" ref="17982920"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-1.CustomClassName</string>
|
||||
<string>-2.CustomClassName</string>
|
||||
<string>1.IBEditorWindowLastContentRect</string>
|
||||
<string>1.IBPluginDependency</string>
|
||||
<string>16.IBPluginDependency</string>
|
||||
<string>34.IBPluginDependency</string>
|
||||
<string>35.IBPluginDependency</string>
|
||||
<string>36.IBPluginDependency</string>
|
||||
<string>37.IBPluginDependency</string>
|
||||
<string>38.IBPluginDependency</string>
|
||||
<string>54.IBPluginDependency</string>
|
||||
<string>55.IBPluginDependency</string>
|
||||
<string>56.IBPluginDependency</string>
|
||||
<string>58.IBPluginDependency</string>
|
||||
<string>59.IBPluginDependency</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>DecodingController</string>
|
||||
<string>UIResponder</string>
|
||||
<string>{{387, 315}, {320, 480}}</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">67</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">DecodingController</string>
|
||||
<string key="superclassName">UIViewController</string>
|
||||
<object class="NSMutableDictionary" key="actions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>performResultAction:</string>
|
||||
<string>pickAndDecode:</string>
|
||||
<string>showArchive:</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>actionBarItem</string>
|
||||
<string>archiveBarItem</string>
|
||||
<string>cameraBarItem</string>
|
||||
<string>imageView</string>
|
||||
<string>libraryBarItem</string>
|
||||
<string>messageView</string>
|
||||
<string>savedPhotosBarItem</string>
|
||||
<string>toolbar</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIImageView</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UITextView</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIToolbar</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">Classes/DecodingController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">DecodingController</string>
|
||||
<string key="superclassName">UIViewController</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">../ZXing.xcodeproj</string>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
</data>
|
||||
</archive>
|
|
@ -1,38 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,114 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,68 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,50 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,74 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,62 +0,0 @@
|
|||
//
|
||||
// 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];
|
||||
}
|
||||
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
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,59 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,43 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,50 +0,0 @@
|
|||
//
|
||||
// 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];
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
//
|
||||
// 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__
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,54 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// MessageViewController.h
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 30/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>
|
||||
|
||||
@interface MessageViewController : UIViewController <UIWebViewDelegate> {
|
||||
id callbackTarget;
|
||||
SEL callbackSelectorSuccess;
|
||||
SEL callbackSelectorFailure;
|
||||
NSURL *contentURL;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) id callbackTarget;
|
||||
@property (nonatomic, assign) SEL callbackSelectorSuccess;
|
||||
@property (nonatomic, assign) SEL callbackSelectorFailure;
|
||||
|
||||
@property (nonatomic, readonly) UIWebView *webView;
|
||||
|
||||
@property (nonatomic, retain) NSURL *contentURL;
|
||||
|
||||
- (id)initWithMessageFilename:(NSString *)filename target:(id)cbt onSuccess:(SEL)ss onFailure:(SEL)fs;
|
||||
|
||||
@end
|
|
@ -1,108 +0,0 @@
|
|||
//
|
||||
// MessageViewController.m
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 30/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 "MessageViewController.h"
|
||||
|
||||
|
||||
@implementation MessageViewController
|
||||
|
||||
@synthesize callbackTarget;
|
||||
@synthesize callbackSelectorSuccess;
|
||||
@synthesize callbackSelectorFailure;
|
||||
@synthesize contentURL;
|
||||
|
||||
- (UIWebView *)webView {
|
||||
return (UIWebView *)self.view;
|
||||
}
|
||||
|
||||
- (id)initWithMessageFilename:(NSString *)filename
|
||||
target:(id)cbt
|
||||
onSuccess:(SEL)ss
|
||||
onFailure:(SEL)fs {
|
||||
if ((self = [super initWithNibName:@"Message" bundle:nil])) {
|
||||
self.callbackTarget = cbt;
|
||||
self.callbackSelectorSuccess = ss;
|
||||
self.callbackSelectorFailure = fs;
|
||||
self.contentURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename
|
||||
ofType:@"html"]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
self.webView.delegate = self;
|
||||
[self.webView loadRequest:[NSURLRequest requestWithURL:self.contentURL]];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
// Return YES for supported orientations
|
||||
return (interfaceOrientation == UIInterfaceOrientationPortrait);
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
|
||||
// Release anything that's not essential, such as cached data
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// open a URL, asynchronously
|
||||
- (void) openURL:(NSURL *)url {
|
||||
[url autorelease];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
|
||||
|
||||
// UIWebViewDelegate methods
|
||||
|
||||
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
|
||||
if ([[request URL] isFileURL]) {
|
||||
// only load 'file' URL requests ourselves
|
||||
return true;
|
||||
} else {
|
||||
// any other url:s are handed off to the system
|
||||
NSURL *url = [[request URL] retain];
|
||||
[self performSelectorOnMainThread:@selector(openURL:) withObject:url waitUntilDone:false];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
|
||||
NSLog(@"failed to load content, performing failure callback");
|
||||
[self.callbackTarget performSelector:self.callbackSelectorFailure withObject:self afterDelay:0.0];
|
||||
}
|
||||
|
||||
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
||||
NSLog(@"finished loading content, performing success callback");
|
||||
[self.callbackTarget performSelector:self.callbackSelectorSuccess withObject:self afterDelay:0.0];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// 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];
|
||||
[FormatReader registerFormatReader:[[[self alloc] init] autorelease]];
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
zxing::MultiFormatReader *reader = new zxing::MultiFormatReader();
|
||||
return [super initWithReader:reader];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,32 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,70 +0,0 @@
|
|||
//
|
||||
// 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:
|
||||
@"&", @"&",
|
||||
@"<", @"<",
|
||||
@">", @">",
|
||||
nil
|
||||
];
|
||||
}
|
||||
return htmlEscapes;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)htmlUnescapes {
|
||||
if (!htmlUnescapes) {
|
||||
htmlUnescapes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
@"&", @"&",
|
||||
@"<", @"<",
|
||||
@">", @">",
|
||||
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
|
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,82 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,35 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,104 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,30 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// QRCodeFormatReader.mm
|
||||
// OTPAuth
|
||||
//
|
||||
// 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/qrcode/QRCodeReader.h>
|
||||
|
||||
@interface QRCodeFormatReader : FormatReader
|
||||
@end
|
||||
|
||||
@implementation QRCodeFormatReader
|
||||
|
||||
+ (void)load {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[FormatReader registerFormatReader:[[[self alloc] init] autorelease]];
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
zxing::qrcode::QRCodeReader *reader = new zxing::qrcode::QRCodeReader();
|
||||
return [super initWithReader:reader];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,32 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,31 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,78 +0,0 @@
|
|||
//
|
||||
// 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
|
||||
|
||||
// Make the parser of last resort the last parser we try.
|
||||
NSMutableArray *resultParsers =
|
||||
[NSMutableArray arrayWithArray:[[self resultParsers] allObjects]];
|
||||
NSUInteger textIndex =
|
||||
[resultParsers indexOfObject:NSClassFromString(@"TextResultParser")];
|
||||
if (NSNotFound != textIndex) {
|
||||
// If it is present, make sure it is last.
|
||||
[resultParsers exchangeObjectAtIndex:textIndex
|
||||
withObjectAtIndex:[resultParsers count] - 1];
|
||||
}
|
||||
|
||||
for (Class c in 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
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,85 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,65 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,78 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,57 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// Scan.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>
|
||||
|
||||
|
||||
@interface Scan : NSObject {
|
||||
NSInteger ident;
|
||||
NSString *text;
|
||||
NSDate *stamp;
|
||||
}
|
||||
|
||||
@property NSInteger ident;
|
||||
@property (nonatomic, copy) NSString *text;
|
||||
@property (nonatomic, retain) NSDate *stamp;
|
||||
|
||||
- (id)initWithIdent:(int)i text:(NSString *)t stamp:(NSDate *)s;
|
||||
|
||||
@end
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// Scan.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 "Scan.h"
|
||||
|
||||
|
||||
@implementation Scan
|
||||
|
||||
@synthesize ident;
|
||||
@synthesize text;
|
||||
@synthesize stamp;
|
||||
|
||||
- (id)initWithIdent:(int)i text:(NSString *)t stamp:(NSDate *)s {
|
||||
if ((self = [super init]) != nil) {
|
||||
self.ident = i;
|
||||
self.text = t;
|
||||
self.stamp = s;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// ScanCell.h
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 30/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>
|
||||
|
||||
@class Scan;
|
||||
@class ParsedResult;
|
||||
|
||||
@interface ScanCell : UITableViewCell {
|
||||
Scan *scan;
|
||||
ParsedResult *result;
|
||||
UIImageView *imageView;
|
||||
UILabel *textView;
|
||||
UILabel *dateView;
|
||||
UILabel *timeView;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) Scan *scan;
|
||||
@property (nonatomic, retain) UIImageView *imageView;
|
||||
@property (nonatomic, retain) UILabel *textView;
|
||||
@property (nonatomic, retain) UILabel *dateView;
|
||||
@property (nonatomic, retain) UILabel *timeView;
|
||||
|
||||
@end
|
|
@ -1,175 +0,0 @@
|
|||
//
|
||||
// ScanCell.m
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 30/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 "ScanCell.h"
|
||||
#import "Scan.h"
|
||||
#import "ParsedResult.h"
|
||||
#import "ResultParser.h"
|
||||
|
||||
static NSDateFormatter *_makeDateFormatter(NSDateFormatterStyle dateStyle,
|
||||
NSDateFormatterStyle timeStyle) {
|
||||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||||
[dateFormatter setDateStyle:dateStyle];
|
||||
[dateFormatter setTimeStyle:timeStyle];
|
||||
return dateFormatter;
|
||||
}
|
||||
|
||||
static NSString *_dateString(NSDate *date) {
|
||||
static NSDateFormatter *dateFormatter = nil;
|
||||
if (!dateFormatter) {
|
||||
dateFormatter =
|
||||
_makeDateFormatter(NSDateFormatterShortStyle, NSDateFormatterNoStyle);
|
||||
}
|
||||
return [dateFormatter stringFromDate:date];
|
||||
}
|
||||
|
||||
static NSString *_timeString(NSDate *date) {
|
||||
static NSDateFormatter *timeFormatter = nil;
|
||||
if (!timeFormatter) {
|
||||
timeFormatter =
|
||||
|
||||
_makeDateFormatter(NSDateFormatterNoStyle, NSDateFormatterShortStyle);
|
||||
}
|
||||
return [timeFormatter stringFromDate:date];
|
||||
}
|
||||
|
||||
#define VIEW_PADDING 2.0
|
||||
#define IMAGE_SIZE 40.0
|
||||
#define EDITING_INSET 10.0
|
||||
#define CONTENT_HEIGHT (IMAGE_SIZE + 2.0 * VIEW_PADDING)
|
||||
#define DATE_TIME_WIDTH 50.0
|
||||
|
||||
@implementation ScanCell
|
||||
|
||||
@synthesize imageView;
|
||||
@synthesize textView;
|
||||
@synthesize dateView;
|
||||
@synthesize timeView;
|
||||
|
||||
|
||||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
||||
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
|
||||
imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
|
||||
imageView.contentMode = UIViewContentModeCenter;
|
||||
[self.contentView addSubview:imageView];
|
||||
|
||||
textView = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
textView.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
|
||||
textView.textAlignment = UITextAlignmentLeft;
|
||||
textView.textColor = [UIColor blackColor];
|
||||
[self.contentView addSubview:textView];
|
||||
|
||||
dateView = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
dateView.font = [UIFont systemFontOfSize:(2 * [UIFont systemFontSize]) / 3];
|
||||
dateView.textAlignment = UITextAlignmentRight;
|
||||
dateView.textColor = [UIColor grayColor];
|
||||
[self.contentView addSubview:dateView];
|
||||
|
||||
timeView = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
timeView.font = [UIFont systemFontOfSize:(2 * [UIFont systemFontSize]) / 3];
|
||||
timeView.textAlignment = UITextAlignmentRight;
|
||||
timeView.textColor = [UIColor grayColor];
|
||||
[self.contentView addSubview:timeView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGRect) _imageViewFrame {
|
||||
CGRect frame = CGRectMake(VIEW_PADDING, VIEW_PADDING, IMAGE_SIZE, IMAGE_SIZE);
|
||||
if (self.editing) {
|
||||
frame.origin.x += EDITING_INSET;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
- (CGRect) _textViewFrame {
|
||||
CGRect frame = CGRectMake(2 * VIEW_PADDING + IMAGE_SIZE, VIEW_PADDING, self.contentView.bounds.size.width - IMAGE_SIZE - DATE_TIME_WIDTH - 3 * VIEW_PADDING, CONTENT_HEIGHT - 2 * VIEW_PADDING);
|
||||
if (self.editing) {
|
||||
frame.origin.x += EDITING_INSET;
|
||||
frame.size.width += DATE_TIME_WIDTH + VIEW_PADDING - EDITING_INSET;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
- (CGRect) _timeViewFrame {
|
||||
float x = CGRectGetMaxX(self.contentView.bounds) - DATE_TIME_WIDTH - VIEW_PADDING;
|
||||
CGRect frame = CGRectMake(x, VIEW_PADDING, DATE_TIME_WIDTH, (CONTENT_HEIGHT - 2 * VIEW_PADDING) / 2);
|
||||
return frame;
|
||||
}
|
||||
|
||||
- (CGRect) _dateViewFrame {
|
||||
float x = CGRectGetMaxX(self.contentView.bounds) - DATE_TIME_WIDTH - VIEW_PADDING;
|
||||
CGRect frame = CGRectMake(x, (CONTENT_HEIGHT - 2 * VIEW_PADDING) / 2, DATE_TIME_WIDTH, (CONTENT_HEIGHT - 2 * VIEW_PADDING) / 2);
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
[imageView setFrame:[self _imageViewFrame]];
|
||||
[textView setFrame:[self _textViewFrame]];
|
||||
[dateView setFrame:[self _dateViewFrame]];
|
||||
[timeView setFrame:[self _timeViewFrame]];
|
||||
if (self.editing) {
|
||||
dateView.alpha = 0.0;
|
||||
timeView.alpha = 0.0;
|
||||
} else {
|
||||
dateView.alpha = 1.0;
|
||||
timeView.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)setScan:(Scan *)newScan {
|
||||
if (newScan != scan) {
|
||||
[newScan retain];
|
||||
[scan release];
|
||||
scan = newScan;
|
||||
[result release];
|
||||
result = [[ResultParser parsedResultForString:[scan text]] retain];
|
||||
|
||||
imageView.image = [result icon];
|
||||
textView.text = [result stringForDisplay];
|
||||
|
||||
NSDate *date = [scan stamp];
|
||||
dateView.text = _dateString(date);
|
||||
timeView.text = _timeString(date);
|
||||
}
|
||||
}
|
||||
|
||||
- (Scan *)scan {
|
||||
return scan;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[imageView release];
|
||||
[textView release];
|
||||
[dateView release];
|
||||
[timeView release];
|
||||
[scan release];
|
||||
[result release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -1,39 +0,0 @@
|
|||
//
|
||||
// ScanViewController.h
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 24/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 "Scan.h"
|
||||
#import "ParsedResult.h"
|
||||
|
||||
@interface ScanViewController : UITableViewController {
|
||||
IBOutlet ParsedResult *result;
|
||||
IBOutlet Scan *scan;
|
||||
UIFont *bodyFont;
|
||||
NSDateFormatter *dateFormatter;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) ParsedResult *result;
|
||||
@property (nonatomic, retain) Scan *scan;
|
||||
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
|
||||
|
||||
- (id)initWithResult:(ParsedResult *)r forScan:(Scan *)s;
|
||||
|
||||
@end
|
|
@ -1,255 +0,0 @@
|
|||
//
|
||||
// ScanViewController.m
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 24/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 "ScanViewController.h"
|
||||
#import "ResultAction.h"
|
||||
|
||||
|
||||
#define TEXT_VIEW_TAG 0x17
|
||||
#define DATETIME_VIEW_TAG 0x18
|
||||
#define BUTTON_LABEL_TAG 0x19
|
||||
#define TITLE_HEIGHT 44
|
||||
#define BODY_HEIGHT 88
|
||||
|
||||
@implementation ScanViewController
|
||||
|
||||
@synthesize result;
|
||||
@synthesize scan;
|
||||
@synthesize dateFormatter;
|
||||
|
||||
#define FONT_NAME @"TimesNewRomanPSMT"
|
||||
#define FONT_SIZE 16
|
||||
|
||||
- (id)initWithResult:(ParsedResult *)r forScan:(Scan *)s {
|
||||
if ((self = [super initWithStyle:UITableViewStyleGrouped])) {
|
||||
self.result = r;
|
||||
self.scan = s;
|
||||
self.title = NSLocalizedString(@"ScanViewController title", @"Scan");
|
||||
dateFormatter = [[NSDateFormatter alloc] init];
|
||||
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
|
||||
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
|
||||
bodyFont = [[UIFont fontWithName:FONT_NAME size:FONT_SIZE] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return [[result actions] count] ? 2 : 1;
|
||||
}
|
||||
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return 3;
|
||||
case 1:
|
||||
return [[result actions] count];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (UITableViewCell *)cellWithIdentifier:(NSString *)identifier inTableView:(UITableView *)tableView {
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
||||
if (cell == nil) {
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)titleCellInTableView:(UITableView *)tableView {
|
||||
static NSString *TitleIdentifier = @"ScanViewTitleIdentifier";
|
||||
return [self cellWithIdentifier:TitleIdentifier inTableView:tableView];
|
||||
}
|
||||
|
||||
- (UITableViewCell *)datetimeCellInTableView:(UITableView *)tableView {
|
||||
static NSString *DatetimeIdentifier = @"ScanViewDatetimeIdentifier";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DatetimeIdentifier];
|
||||
if (cell == nil) {
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 34) reuseIdentifier:DatetimeIdentifier] autorelease];
|
||||
UILabel *label = [cell textLabel];
|
||||
label.font = [UIFont systemFontOfSize:[UIFont systemFontSize] * 2.0 / 3.0];
|
||||
label.textColor = [UIColor grayColor];
|
||||
label.textAlignment = UITextAlignmentCenter;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)bodyCellInTableView:(UITableView *)tableView {
|
||||
static NSString *BodyIdentifier = @"ScanViewBodyIdentifier";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:BodyIdentifier];
|
||||
if (cell == nil) {
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, BODY_HEIGHT) reuseIdentifier:BodyIdentifier] autorelease];
|
||||
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(cell.contentView.bounds, 6, 6)];
|
||||
textView.font = bodyFont;
|
||||
[textView setTag:TEXT_VIEW_TAG];
|
||||
textView.editable = NO;
|
||||
[textView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
|
||||
[cell.contentView addSubview:textView];
|
||||
[textView release];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)buttonCellInTableView:(UITableView *)tableView {
|
||||
static NSString *ButtonIdentifier = @"ScanViewButtonIdentifier";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ButtonIdentifier];
|
||||
if (cell == nil) {
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 44) reuseIdentifier:ButtonIdentifier] autorelease];
|
||||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(cell.contentView.bounds, 6, 6)];
|
||||
label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
|
||||
[label setTag:BUTTON_LABEL_TAG];
|
||||
label.lineBreakMode = UILineBreakModeMiddleTruncation;
|
||||
label.textColor = [UIColor grayColor];
|
||||
label.textAlignment = UITextAlignmentCenter;
|
||||
[label setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
|
||||
[cell.contentView addSubview:label];
|
||||
[label release];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
#define TEXT_VIEW_HEIGHT 330.0
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section == 0) {
|
||||
if (indexPath.row == 0) {
|
||||
return TITLE_HEIGHT;
|
||||
} else if (indexPath.row == 1) {
|
||||
CGSize size = [[result stringForDisplay] sizeWithFont:bodyFont constrainedToSize:CGSizeMake(280.0, TEXT_VIEW_HEIGHT) lineBreakMode:UILineBreakModeWordWrap];
|
||||
#ifdef DEBUG
|
||||
NSLog(@"text size = %f", size.height);
|
||||
#endif
|
||||
return fminf(TEXT_VIEW_HEIGHT, fmaxf(44, size.height + 24));
|
||||
} else if (indexPath.row == 2) {
|
||||
return 24.0;
|
||||
}
|
||||
}
|
||||
return tableView.rowHeight;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
UITableViewCell *cell;
|
||||
|
||||
if (indexPath.section == 0) {
|
||||
if (indexPath.row == 0) {
|
||||
cell = [self titleCellInTableView:tableView];
|
||||
UIImageView *imageView = cell.imageView;
|
||||
imageView.image = [result icon];
|
||||
UILabel *textLabel = cell.textLabel;
|
||||
textLabel.text = [[result class] typeName];
|
||||
} else if (indexPath.row == 1) {
|
||||
cell = [self bodyCellInTableView:tableView];
|
||||
UITextView *textView = (UITextView *)[cell viewWithTag:TEXT_VIEW_TAG];
|
||||
textView.text = [result stringForDisplay];
|
||||
} else if (indexPath.row == 2) {
|
||||
cell = [self datetimeCellInTableView:tableView];
|
||||
UILabel *textLabel = cell.textLabel;
|
||||
textLabel.text = [dateFormatter stringFromDate:[scan stamp]];
|
||||
}
|
||||
} else if (indexPath.section == 1) {
|
||||
cell = [self buttonCellInTableView:tableView];
|
||||
ResultAction *action = [[result actions] objectAtIndex:indexPath.row];
|
||||
UILabel *label = (UILabel *)[cell viewWithTag:BUTTON_LABEL_TAG];
|
||||
label.text = [action title];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)performAction:(ResultAction *)action {
|
||||
[action performActionWithController:self shouldConfirm:NO];
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section == 1) {
|
||||
ResultAction *action = [[result actions] objectAtIndex:indexPath.row];
|
||||
[self performSelector:@selector(performAction:) withObject:action afterDelay:0.0];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
}
|
||||
if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section != 1) {
|
||||
return nil;
|
||||
}
|
||||
return indexPath;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[result release];
|
||||
[scan release];
|
||||
[bodyFont release];
|
||||
[dateFormatter release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// ScannedImageView.h
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 01/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>
|
||||
|
||||
|
||||
@interface ScannedImageView : UIView {
|
||||
UIImage *image;
|
||||
NSMutableArray *resultPoints;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) UIImage *image;
|
||||
|
||||
- (void) addResultPoint:(CGPoint)p;
|
||||
|
||||
@end
|
|
@ -1,118 +0,0 @@
|
|||
//
|
||||
// ScannedImageView.m
|
||||
// ZXing
|
||||
//
|
||||
// Created by Christian Brunschen on 01/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 "ScannedImageView.h"
|
||||
#import <math.h>
|
||||
|
||||
@implementation ScannedImageView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
if ((self = [super initWithFrame:frame])) {
|
||||
resultPoints = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)decoder {
|
||||
if ((self = [super initWithCoder:decoder]) != nil) {
|
||||
resultPoints = [[NSMutableArray alloc] initWithCapacity:10];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect {
|
||||
[super drawRect:rect];
|
||||
|
||||
if (image) {
|
||||
// draw the image, scaled to fit, top and center
|
||||
CGSize imageSize = image.size;
|
||||
CGRect bounds = [self bounds];
|
||||
double imageScale = fminf(bounds.size.width / imageSize.width,
|
||||
bounds.size.height / imageSize.height);
|
||||
double dx = (bounds.size.width - imageSize.width * imageScale) / 2.0;
|
||||
double dy = 0.0;
|
||||
|
||||
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
||||
CGContextSetInterpolationQuality(ctx, kCGInterpolationDefault);
|
||||
CGRect imageRect = CGRectMake(dx, dy,
|
||||
imageSize.width * imageScale,
|
||||
imageSize.height * imageScale);
|
||||
[image drawInRect:imageRect];
|
||||
|
||||
[[UIColor greenColor] set];
|
||||
|
||||
if (resultPoints && [resultPoints count]) {
|
||||
#define R 4.0
|
||||
if ([resultPoints count] == 2) {
|
||||
CGPoint p0 = [[resultPoints objectAtIndex:0] CGPointValue];
|
||||
CGPoint p1 = [[resultPoints objectAtIndex:1] CGPointValue];
|
||||
CGContextMoveToPoint(ctx, dx + p0.x * imageScale, dy + p0.y * imageScale);
|
||||
CGContextAddLineToPoint(ctx, dx + p1.x * imageScale, dy + p1.y * imageScale);
|
||||
CGContextSetLineWidth(ctx, 4.0);
|
||||
CGContextSetLineCap(ctx, kCGLineCapSquare);
|
||||
CGContextStrokePath(ctx);
|
||||
} else {
|
||||
// for each resultPoint, draw it
|
||||
for (NSValue *pointValue in resultPoints) {
|
||||
CGPoint resultPoint = [pointValue CGPointValue];
|
||||
float px = dx + resultPoint.x * imageScale;
|
||||
float py = dy + resultPoint.y * imageScale;
|
||||
CGContextAddRect(ctx,
|
||||
CGRectMake(px - R, py - R, 2 * R, 2 * R));
|
||||
}
|
||||
CGContextFillPath(ctx);
|
||||
}
|
||||
CGContextFlush(ctx);
|
||||
#undef R
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addResultPoint:(CGPoint)p {
|
||||
[resultPoints addObject:[NSValue valueWithCGPoint:p]];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (void) clearResultPoints {
|
||||
[resultPoints removeAllObjects];
|
||||
}
|
||||
|
||||
- (void) setImage:(UIImage *)newImage {
|
||||
[newImage retain];
|
||||
[image release];
|
||||
image = newImage;
|
||||
[self clearResultPoints];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (UIImage *)image {
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[image release];
|
||||
[resultPoints release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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
|
|
@ -1,68 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,33 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,58 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,44 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,58 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,30 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,35 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,52 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,87 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,30 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,80 +0,0 @@
|
|||
//
|
||||
// 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
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue