5 Commits
2 changed files with 70 additions and 11 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.barcodescanner"
version="0.1.1">
version="0.2.1">
<name>BarcodeScanner</name>
+69 -10
View File
@@ -16,7 +16,20 @@
//------------------------------------------------------------------------------
#import "zxing-all-in-one.h"
#import <CORDOVA/CDVPlugin.h>
#import <Cordova/CDVPlugin.h>
//------------------------------------------------------------------------------
// Delegate to handle orientation functions
//
//------------------------------------------------------------------------------
@protocol CDVBarcodeScannerOrientationDelegate <NSObject>
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotate;
@end
//------------------------------------------------------------------------------
// Adds a shutter button to the UI, and changes the scan from continuous to
@@ -72,11 +85,13 @@
//------------------------------------------------------------------------------
// view controller for the ui
//------------------------------------------------------------------------------
@interface CDVbcsViewController : UIViewController {}
@interface CDVbcsViewController : UIViewController <CDVBarcodeScannerOrientationDelegate> {}
@property (nonatomic, retain) CDVbcsProcessor* processor;
@property (nonatomic, retain) NSString* alternateXib;
@property (nonatomic) BOOL shutterPressed;
@property (nonatomic, retain) IBOutlet UIView* overlayView;
// unsafe_unretained is equivalent to assign - used to prevent retain cycles in the property below
@property (nonatomic, unsafe_unretained) id orientationDelegate;
- (id)initWithProcessor:(CDVbcsProcessor*)processor alternateOverlay:(NSString *)alternateXib;
- (void)startCapturing;
@@ -234,6 +249,8 @@ parentViewController:(UIViewController*)parentViewController
}
self.viewController = [[[CDVbcsViewController alloc] initWithProcessor: self alternateOverlay:self.alternateXib] autorelease];
// here we set the orientation delegate to the MainViewController of the app (orientation controlled in the Project Settings)
self.viewController.orientationDelegate = self.plugin.viewController;
// delayed [self openDialog];
[self performSelector:@selector(openDialog) withObject:nil afterDelay:1];
@@ -629,6 +646,17 @@ parentViewController:(UIViewController*)parentViewController
[self.view addSubview:[self buildOverlayView]];
}
//--------------------------------------------------------------------------
- (void)viewWillAppear:(BOOL)animated {
// set video orientation to what the camera sees
self.processor.previewLayer.orientation = [[UIApplication sharedApplication] statusBarOrientation];
// this fixes the bug when the statusbar is landscape, and the preview layer
// starts up in portrait (not filling the whole view)
self.processor.previewLayer.frame = self.view.bounds;
}
//--------------------------------------------------------------------------
- (void)viewDidAppear:(BOOL)animated {
[self startCapturing];
@@ -641,13 +669,6 @@ parentViewController:(UIViewController*)parentViewController
self.processor.capturing = YES;
}
//--------------------------------------------------------------------------
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// rotation currently not supported
if (interfaceOrientation == UIInterfaceOrientationPortrait) return YES;
return NO;
}
//--------------------------------------------------------------------------
- (void)shutterButtonPressed {
self.shutterPressed = YES;
@@ -796,4 +817,42 @@ parentViewController:(UIViewController*)parentViewController
return result;
}
@end
#pragma mark CDVBarcodeScannerOrientationDelegate
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
return YES;
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
[CATransaction begin];
self.processor.previewLayer.orientation = orientation;
[self.processor.previewLayer layoutSublayers];
self.processor.previewLayer.frame = self.view.bounds;
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
}
@end