Added beep. Settable sound file location via widget property. Client app sets this.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1361 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dkavanagh 2010-05-13 17:34:36 +00:00
parent e99dd51de9
commit e8b3606779
6 changed files with 31 additions and 18 deletions

View file

@ -19,6 +19,8 @@
[super viewDidLoad]; [super viewDidLoad];
[self setTitle:@"ZXing"]; [self setTitle:@"ZXing"];
scanController = [[ZXingWidgetController alloc] initWithDelegate:self]; scanController = [[ZXingWidgetController alloc] initWithDelegate:self];
NSBundle *mainBundle = [NSBundle mainBundle];
[scanController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]];
} }
- (IBAction)scanPressed:(id)sender { - (IBAction)scanPressed:(id)sender {

View file

@ -17,6 +17,7 @@
28F335F11007B36200424DE2 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* RootViewController.xib */; }; 28F335F11007B36200424DE2 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* RootViewController.xib */; };
E5345BC91198D74D000CB77F /* libZXingWidget.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BC81198D74D000CB77F /* libZXingWidget.a */; }; E5345BC91198D74D000CB77F /* libZXingWidget.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BC81198D74D000CB77F /* libZXingWidget.a */; };
E5345BF11198D81A000CB77F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BF01198D81A000CB77F /* AudioToolbox.framework */; }; E5345BF11198D81A000CB77F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BF01198D81A000CB77F /* AudioToolbox.framework */; };
E548755C119C62B9001CC0F8 /* beep-beep.aiff in Resources */ = {isa = PBXBuildFile; fileRef = E548755B119C62B9001CC0F8 /* beep-beep.aiff */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -72,6 +73,7 @@
E5345BED1198D7E2000CB77F /* ZXingWidgetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZXingWidgetController.h; path = ../ZXingWidget/ZXingWidgetController.h; sourceTree = SOURCE_ROOT; }; E5345BED1198D7E2000CB77F /* ZXingWidgetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZXingWidgetController.h; path = ../ZXingWidget/ZXingWidgetController.h; sourceTree = SOURCE_ROOT; };
E5345BF01198D81A000CB77F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; E5345BF01198D81A000CB77F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
E5345FD6119B27D2000CB77F /* libZXingWidget.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libZXingWidget.a; path = "build/Debug-iphoneos/libZXingWidget.a"; sourceTree = "<group>"; }; E5345FD6119B27D2000CB77F /* libZXingWidget.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libZXingWidget.a; path = "build/Debug-iphoneos/libZXingWidget.a"; sourceTree = "<group>"; };
E548755B119C62B9001CC0F8 /* beep-beep.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; path = "beep-beep.aiff"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -135,6 +137,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = { 29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
E548755B119C62B9001CC0F8 /* beep-beep.aiff */,
28F335F01007B36200424DE2 /* RootViewController.xib */, 28F335F01007B36200424DE2 /* RootViewController.xib */,
28AD735F0D9D9599002E5188 /* MainWindow.xib */, 28AD735F0D9D9599002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* ScanTest-Info.plist */, 8D1107310486CEB800E47090 /* ScanTest-Info.plist */,
@ -248,6 +251,7 @@
files = ( files = (
28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */, 28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */,
28F335F11007B36200424DE2 /* RootViewController.xib in Resources */, 28F335F11007B36200424DE2 /* RootViewController.xib in Resources */,
E548755C119C62B9001CC0F8 /* beep-beep.aiff in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

Binary file not shown.

View file

@ -430,7 +430,6 @@
E5345AA21198859A000CB77F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; E5345AA21198859A000CB77F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
E5345AC611988B6E000CB77F /* GrayBytesMonochromeBitmapSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GrayBytesMonochromeBitmapSource.h; sourceTree = "<group>"; }; E5345AC611988B6E000CB77F /* GrayBytesMonochromeBitmapSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GrayBytesMonochromeBitmapSource.h; sourceTree = "<group>"; };
E5345AC711988B6E000CB77F /* GrayBytesMonochromeBitmapSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GrayBytesMonochromeBitmapSource.cpp; sourceTree = "<group>"; }; E5345AC711988B6E000CB77F /* GrayBytesMonochromeBitmapSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GrayBytesMonochromeBitmapSource.cpp; sourceTree = "<group>"; };
E5345D2911999F62000CB77F /* beep-beep.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "beep-beep.caf"; sourceTree = "<group>"; };
E5345F2B119B0762000CB77F /* Decoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Decoder.mm; sourceTree = "<group>"; }; E5345F2B119B0762000CB77F /* Decoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Decoder.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -816,7 +815,6 @@
E5345D2811999F53000CB77F /* Resources */ = { E5345D2811999F53000CB77F /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
E5345D2911999F62000CB77F /* beep-beep.caf */,
); );
name = Resources; name = Resources;
sourceTree = "<group>"; sourceTree = "<group>";

View file

@ -28,12 +28,14 @@
OverlayView *overlayView; OverlayView *overlayView;
SystemSoundID beepSound; SystemSoundID beepSound;
BOOL showCancel; BOOL showCancel;
NSURL *soundToPlay;
id<ZXingDelegate> delegate; id<ZXingDelegate> delegate;
BOOL wasCancelled; BOOL wasCancelled;
} }
@property (nonatomic, assign) id<ZXingDelegate> delegate; @property (nonatomic, assign) id<ZXingDelegate> delegate;
@property (nonatomic, assign) BOOL showCancel; @property (nonatomic, assign) BOOL showCancel;
@property (nonatomic, assign) NSURL *soundToPlay;
@property (nonatomic, retain) ParsedResult *result; @property (nonatomic, retain) ParsedResult *result;
@property (nonatomic, retain) NSArray *actions; @property (nonatomic, retain) NSArray *actions;

View file

@ -29,12 +29,13 @@
CGImageRef UIGetScreenImage(); CGImageRef UIGetScreenImage();
@implementation ZXingWidgetController @implementation ZXingWidgetController
@synthesize result, actions, showCancel, delegate; @synthesize result, actions, showCancel, delegate, soundToPlay;
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate { - (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate {
if (self = [super init]) { if (self = [super init]) {
[self setDelegate:scanDelegate]; [self setDelegate:scanDelegate];
showCancel = true; showCancel = true;
beepSound = -1;
self.wantsFullScreenLayout = YES; self.wantsFullScreenLayout = YES;
self.sourceType = UIImagePickerControllerSourceTypeCamera; self.sourceType = UIImagePickerControllerSourceTypeCamera;
float zoomFactor = CAMERA_SCALAR; float zoomFactor = CAMERA_SCALAR;
@ -55,7 +56,9 @@ CGImageRef UIGetScreenImage();
} }
- (void)dealloc { - (void)dealloc {
AudioServicesDisposeSystemSoundID(beepSound); if (beepSound != -1) {
AudioServicesDisposeSystemSoundID(beepSound);
}
[overlayView dealloc]; [overlayView dealloc];
[super dealloc]; [super dealloc];
} }
@ -85,12 +88,15 @@ CGImageRef UIGetScreenImage();
return false; return false;
} }
- (void)viewDidLoad { - (void)viewWillAppear:(BOOL)animated {
[super viewDidLoad]; [super viewWillAppear:animated];
NSBundle *mainBundle = [NSBundle mainBundle]; NSLog(@"should load sound");
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"caf"] isDirectory:NO], &beepSound); if ([self soundToPlay] != nil) {
if (error != kAudioServicesNoError) { NSLog(@"will try to load sound");
NSLog(@"Problem loading nearSound.caf"); OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[self soundToPlay], &beepSound);
if (error != kAudioServicesNoError) {
NSLog(@"Problem loading nearSound.caf");
}
} }
} }
@ -113,27 +119,30 @@ CGImageRef UIGetScreenImage();
CGRect cropRect = overlayView.cropRect; CGRect cropRect = overlayView.cropRect;
cropRect.origin.x = 0.0; cropRect.origin.x = 0.0;
cropRect.origin.y = 0.0; cropRect.origin.y = 0.0;
NSLog(@"crop rect %f, %f, %f, %f", cropRect.origin.x, cropRect.origin.y, cropRect.size.width, cropRect.size.height);
[d decodeImage:scrn cropRect:cropRect]; [d decodeImage:scrn cropRect:cropRect];
} }
// DecoderDelegate methods // DecoderDelegate methods
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{ - (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{
#ifdef DEBUG
NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height); NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height);
#endif
} }
- (void)decoder:(Decoder *)decoder - (void)decoder:(Decoder *)decoder
decodingImage:(UIImage *)image decodingImage:(UIImage *)image
usingSubset:(UIImage *)subset usingSubset:(UIImage *)subset
progress:(NSString *)message { progress:(NSString *)message {
NSLog(@"decoding image %@", message);
} }
- (void)presentResultForString:(NSString *)resultString { - (void)presentResultForString:(NSString *)resultString {
NSLog(@"in presentResultForString()");
self.result = [ResultParser parsedResultForString:resultString]; self.result = [ResultParser parsedResultForString:resultString];
AudioServicesPlaySystemSound(beepSound);
if (beepSound != -1) {
NSLog(@"about to play beep... trying...");
AudioServicesPlaySystemSound(beepSound);
}
#ifdef DEBUG #ifdef DEBUG
NSLog(@"result string = %@", resultString); NSLog(@"result string = %@", resultString);
NSLog(@"result has %d actions", actions ? 0 : actions.count); NSLog(@"result has %d actions", actions ? 0 : actions.count);
@ -145,13 +154,11 @@ CGImageRef UIGetScreenImage();
forImage:(UIImage *)image forImage:(UIImage *)image
usingSubset:(UIImage *)subset { usingSubset:(UIImage *)subset {
// simply add the points to the image view // simply add the points to the image view
NSLog(@"got points for display");
[overlayView setPoints:resultPoints]; [overlayView setPoints:resultPoints];
} }
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult { - (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {
// [self presentResultForString:twoDResult.text]; [self presentResultForString:[twoDResult text]];
NSLog(@"decoded image!!");
[self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset]; [self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset];
// now, in a selector, call the delegate to give this overlay time to show the points // now, in a selector, call the delegate to give this overlay time to show the points
[self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:1.0]; [self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:1.0];