Permalink
Browse files

[Demo] Updated demo application

- Added Custom Camera Overlay example
- Added sample on how to use camera pausing/resuimg
- Sample for handling uncertain barcodes
  • Loading branch information...
1 parent 47a0276 commit ce0b700495fe621f2cd4fbcd1b81f13be80fbb45 @Cerovec Cerovec committed Nov 15, 2013
View
BIN beep.mp3
Binary file not shown.
@@ -30,6 +30,9 @@
18508F3017CB9E4B00C6FA35 /* en.strings in Resources */ = {isa = PBXBuildFile; fileRef = 18508F2C17CB9E4B00C6FA35 /* en.strings */; };
18508F3117CB9E4B00C6FA35 /* hr.strings in Resources */ = {isa = PBXBuildFile; fileRef = 18508F2D17CB9E4B00C6FA35 /* hr.strings */; };
188175F217FC351F0077AC76 /* libc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 188175F117FC351F0077AC76 /* libc++.dylib */; };
+ 18C1114818345DF80004CFFD /* beep.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 18C1114718345DF80004CFFD /* beep.mp3 */; };
+ 18D58A001833017F008EC99C /* PPCameraOverlayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18D589FE1833017F008EC99C /* PPCameraOverlayViewController.m */; };
+ 18D58A011833017F008EC99C /* PPCameraOverlayViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 18D589FF1833017F008EC99C /* PPCameraOverlayViewController.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -61,6 +64,10 @@
18508F2C17CB9E4B00C6FA35 /* en.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = en.strings; sourceTree = "<group>"; };
18508F2D17CB9E4B00C6FA35 /* hr.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = hr.strings; sourceTree = "<group>"; };
188175F117FC351F0077AC76 /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "usr/lib/libc++.dylib"; sourceTree = SDKROOT; };
+ 18C1114718345DF80004CFFD /* beep.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = beep.mp3; path = ../../beep.mp3; sourceTree = "<group>"; };
+ 18D589FD1833017F008EC99C /* PPCameraOverlayViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPCameraOverlayViewController.h; sourceTree = "<group>"; };
+ 18D589FE1833017F008EC99C /* PPCameraOverlayViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPCameraOverlayViewController.m; sourceTree = "<group>"; };
+ 18D589FF1833017F008EC99C /* PPCameraOverlayViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PPCameraOverlayViewController.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -130,6 +137,9 @@
1818D851174D14DB00136FD2 /* PPRootViewController.h */,
1818D852174D14DB00136FD2 /* PPRootViewController.m */,
1818D853174D14DB00136FD2 /* PPRootViewController.xib */,
+ 18D589FD1833017F008EC99C /* PPCameraOverlayViewController.h */,
+ 18D589FE1833017F008EC99C /* PPCameraOverlayViewController.m */,
+ 18D589FF1833017F008EC99C /* PPCameraOverlayViewController.xib */,
1818D832174D146F00136FD2 /* Supporting Files */,
);
path = "pdf417-sample";
@@ -138,6 +148,7 @@
1818D832174D146F00136FD2 /* Supporting Files */ = {
isa = PBXGroup;
children = (
+ 18C1114718345DF80004CFFD /* beep.mp3 */,
1818D833174D146F00136FD2 /* pdf417-sample-Info.plist */,
1818D834174D146F00136FD2 /* InfoPlist.strings */,
1818D837174D146F00136FD2 /* main.m */,
@@ -225,7 +236,9 @@
1818D83E174D146F00136FD2 /* Default.png in Resources */,
1818D840174D146F00136FD2 /* Default@2x.png in Resources */,
1818D842174D146F00136FD2 /* Default-568h@2x.png in Resources */,
+ 18D58A011833017F008EC99C /* PPCameraOverlayViewController.xib in Resources */,
1818D855174D14DB00136FD2 /* PPRootViewController.xib in Resources */,
+ 18C1114818345DF80004CFFD /* beep.mp3 in Resources */,
18508F2F17CB9E4B00C6FA35 /* de.strings in Resources */,
18508F3017CB9E4B00C6FA35 /* en.strings in Resources */,
18508F3117CB9E4B00C6FA35 /* hr.strings in Resources */,
@@ -239,6 +252,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 18D58A001833017F008EC99C /* PPCameraOverlayViewController.m in Sources */,
1818D838174D146F00136FD2 /* main.m in Sources */,
1818D83C174D146F00136FD2 /* PPAppDelegate.m in Sources */,
1818D854174D14DB00136FD2 /* PPRootViewController.m in Sources */,
@@ -3,8 +3,8 @@
LastUpgradeVersion = "0460"
version = "1.3">
<BuildAction
- parallelizeBuildables = "YES"
- buildImplicitDependencies = "YES">
+ parallelizeBuildables = "NO"
+ buildImplicitDependencies = "NO">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
@@ -0,0 +1,22 @@
+//
+// PPCameraOverlayViewController.h
+// pdf417-sample
+//
+// Created by Jurica Cerovec on 13/11/13.
+// Copyright (c) 2013 PhotoPay. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <pdf417/PPBarcode.h>
+
+@interface PPCameraOverlayViewController : PPOverlayViewController
+
+@property (weak, nonatomic) IBOutlet UIButton *closeButton;
+
+@property (weak, nonatomic) IBOutlet UIButton *torchButton;
+
+- (IBAction)closePressed:(id)sender;
+
+- (IBAction)torchPressed:(id)sender;
+
+@end
@@ -0,0 +1,278 @@
+//
+// PPCameraOverlayViewController.m
+// pdf417-sample
+//
+// Created by Jurica Cerovec on 13/11/13.
+// Copyright (c) 2013 PhotoPay. All rights reserved.
+//
+
+#import "PPCameraOverlayViewController.h"
+#import <QuartzCore/QuartzCore.h>
+
+@interface PPCameraOverlayViewController ()
+
+/* Animation layer for barcode location drawing */
+@property (nonatomic, retain) CAShapeLayer* drawingLayer;
+
+@end
+
+@implementation PPCameraOverlayViewController
+
+@synthesize drawingLayer;
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ // Do any additional setup after loading the view from its nib.
+}
+
+- (void)viewDidUnload {
+ [[self drawingLayer] setDelegate:nil];
+ [self setDrawingLayer:nil];
+ [self setCloseButton:nil];
+ [self setTorchButton:nil];
+ [super viewDidUnload];
+}
+
+- (void)dealloc {
+ [[self drawingLayer] setDelegate:nil];
+ [self setDrawingLayer:nil];
+}
+
+- (void)didReceiveMemoryWarning
+{
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+
+ // on devices which don't support torch, torch button should be disabled
+ if (![[self delegate] overlayViewControllerShouldDisplayTorch:self]) {
+ [[self torchButton] setHidden:YES];
+ }
+
+ // add drawing layer to view
+ [self initDrawingLayerWithBounds:[self view].bounds];
+}
+
+- (void)viewDidDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
+}
+
+#pragma mark user interaction methods
+
+- (IBAction)closePressed:(id)sender {
+ [[self delegate] overlayViewControllerWillCloseCamera:self];
+}
+
+- (IBAction)torchPressed:(id)sender {
+ static BOOL torchOn = NO;
+ torchOn = [[self delegate] isTorchOn];
+ torchOn = !torchOn;
+ if ([[self delegate] overlayViewControllerShouldDisplayTorch:self]) {
+ [[self delegate] overlayViewController:self
+ willSetTorch:torchOn];
+ }
+}
+
+#pragma mark -
+#pragma mark autorotation
+
+- (BOOL)shouldAutorotate {
+ return YES;
+}
+
+- (NSUInteger)supportedInterfaceOrientations {
+ return UIInterfaceOrientationMaskAllButUpsideDown;
+}
+
+- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
+ return UIInterfaceOrientationPortrait;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
+}
+
+#pragma mark Controlling camera view
+
+- (void)cameraViewControllerDidResumeScanning:(id)cameraViewController {
+ NSLog(@"Barcode scanning process initialized");
+}
+
+- (void)cameraViewControllerDidStopScanning:(id)cameraViewController {
+ NSLog(@"Barcode scanning process terminated");
+}
+
+- (void)cameraViewController:(id)cameraViewController
+ didPublishProgress:(float)progress {
+ NSLog(@"Barcode scanning don't have progress reporting implemented yet");
+}
+
+- (void)cameraViewControllerDidStartRecognition:(id)cameraViewController {
+}
+
+- (void)cameraViewController:(id)cameraViewController
+didFinishRecognitionWithResult:(id)result {
+ NSLog(@"Barcode scanning process finished with result %@", result);
+}
+
+- (void)cameraViewController:(id)cameraViewController
+ didTimeoutWithResult:(id)result {
+ NSLog(@"Barcode scanning process timed out with result %@", result);
+}
+
+- (void)cameraViewController:(id)cameraViewController
+ didFindLocation:(NSArray*)cornerPoints
+ withStatus:(PPDetectionStatus)status {
+
+ CGRect size = [[self view] bounds];
+
+ BOOL detectionSuccess = NO;
+
+ switch (status) {
+ case PPDetectionStatusSuccess: {
+ NSLog(@"Detection was success");
+ detectionSuccess = YES;
+ break;
+ } case PPDetectionStatusPdf417Success: {
+ NSLog(@"PDF417 Barcode detection was success");
+ detectionSuccess = YES;
+ break;
+ } case PPDetectionStatusQRSuccess: {
+ detectionSuccess = YES;
+ NSLog(@"QR code detection was success");
+ break;
+ }
+ case PPDetectionStatusFallbackSuccess: {
+ detectionSuccess = YES;
+ NSLog(@"Detection fallback was success");
+ break;
+ }
+ case PPDetectionStatusFail:
+ NSLog(@"Detection failed");
+ break;
+ case PPDetectionStatusCameraAtAngle:
+ NSLog(@"Camera is at an angle");
+ break;
+ case PPDetectionStatusCameraRotated:
+ NSLog(@"Camera is rotated");
+ break;
+ case PPDetectionStatusCameraTooHigh:
+ NSLog(@"Camera is too high");
+ break;
+ case PPDetectionStatusPartialForm:
+ NSLog(@"The form detected is only partially on screen");
+ break;
+ default:
+ break;
+ }
+
+ if (detectionSuccess) {
+ CGMutablePathRef drawingPath = CGPathCreateMutable();
+ [PPCameraOverlayViewController createPath:drawingPath
+ withDots:cornerPoints
+ forSize:size];
+ drawingLayer.path = drawingPath;
+ [self startDotAnimation:[[UIColor greenColor] CGColor]];
+ }
+}
+
+- (void)cameraViewController:(id)cameraViewController
+ willRotateToOrientation:(UIDeviceOrientation)orientation {
+
+}
+
+/** Camera view did rotate */
+- (void)cameraViewController:(id)cameraViewController
+ didRotateToOrientation:(UIDeviceOrientation)orientation {
+ NSString* orientationString = @"Portrait";
+ if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
+ orientationString = @"Upside Down";
+ } else if (orientation == UIInterfaceOrientationLandscapeLeft) {
+ orientationString = @"Landscape Left";
+ } else if (orientation == UIInterfaceOrientationLandscapeRight) {
+ orientationString = @"Landscape Right";
+ }
+ NSLog(@"Orientation was changed to %@", orientationString);
+}
+
+#pragma mark - Location drawing
+
+- (void)initDrawingLayerWithBounds:(CGRect)bounds {
+ [[self drawingLayer] removeFromSuperlayer];
+
+ CAShapeLayer *newDrawingLayer = [[CAShapeLayer alloc] init];
+ UIColor* color = [UIColor greenColor];
+ [self setDrawingLayer:newDrawingLayer];
+
+ drawingLayer.frame = bounds;
+ drawingLayer.contentsGravity = kCAGravityResize;
+ drawingLayer.strokeColor = [color CGColor];
+ drawingLayer.fillColor = [[UIColor clearColor] CGColor];
+ drawingLayer.opacity = 0.9f;
+ drawingLayer.delegate = self;
+ drawingLayer.lineWidth = 4.0f;
+ drawingLayer.masksToBounds = YES;
+
+ CGMutablePathRef newPath = CGPathCreateMutable();
+ drawingLayer.path = newPath;
+ CGPathRelease(newPath);
+
+ // we have to do this trick to make it work in all orientations
+ // we add drawing layer to view's superview, which isn't rotatable
+ CALayer *viewLayer = [[[self view] superview] layer];
+ [viewLayer setMasksToBounds:YES];
+ [viewLayer addSublayer:drawingLayer];
+}
+
+- (void)startDotAnimation:(CGColorRef)toColor {
+ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
+
+ animation.duration = 0.4f;
+ animation.repeatCount = 1;
+ animation.autoreverses = YES;
+ animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
+
+ CAShapeLayer *layer = (CAShapeLayer*)[drawingLayer presentationLayer];
+ animation.fromValue = (id)layer.strokeColor;
+ animation.toValue = (__bridge id)toColor;
+ animation.removedOnCompletion = YES;
+
+ drawingLayer.strokeColor = toColor;
+
+ [drawingLayer addAnimation:animation forKey:@"strokeColor"];
+}
+
++ (void)createPath:(CGMutablePathRef)path
+ withDots:(NSArray*)dots
+ forSize:(CGRect)size {
+
+ const int radius = 4;
+ if (dots != nil) {
+ for (int i = 0; i < [dots count]; i++) {
+ CGPoint point = [[dots objectAtIndex:i] CGPointValue];
+ CGPathMoveToPoint(path, nil, point.x + radius, point.y);
+ CGPathAddArc(path, nil, point.x, point.y, radius, 0, 2*M_PI, YES);
+ }
+ if ([dots count] > 1) {
+ CGPoint point = [[dots objectAtIndex:0] CGPointValue];
+ CGPathMoveToPoint(path, nil, point.x, point.y);
+ }
+ }
+
+ CGPathCloseSubpath(path);
+}
+
+@end
Oops, something went wrong.

0 comments on commit ce0b700

Please sign in to comment.