mirror of
https://github.com/wahyd4/BarcodeScanner.git
synced 2026-08-10 05:26:06 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb3812c0cb | ||
|
|
029cb4de7d | ||
|
|
1e2535ad01 | ||
|
|
695f524777 | ||
|
|
084594d86c | ||
|
|
87ffa13f2c | ||
|
|
413b023697 | ||
|
|
566c1f166a | ||
|
|
e0f7b9a33e |
+6
-1
@@ -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.3.0">
|
||||
|
||||
<name>BarcodeScanner</name>
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
<platform name="ios">
|
||||
<plugins-plist key="BarcodeScanner" string="CDVBarcodeScanner" />
|
||||
|
||||
<!-- Cordova >= 2.3 -->
|
||||
<config-file target="config.xml" parent="/cordova/plugins">
|
||||
<plugin name="BarcodeScanner" value="CDVBarcodeScanner"/>
|
||||
</config-file>
|
||||
|
||||
<resource-file src="scannerOverlay.xib" />
|
||||
|
||||
<header-file src="zxing-all-in-one.h" />
|
||||
|
||||
@@ -121,7 +121,7 @@ public class BarcodeScanner extends Plugin {
|
||||
//Log.d(LOG_TAG, "This should never happen");
|
||||
}
|
||||
this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
|
||||
} if (resultCode == Activity.RESULT_CANCELED) {
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put(TEXT, "");
|
||||
|
||||
@@ -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];
|
||||
@@ -283,7 +300,7 @@ parentViewController:(UIViewController*)parentViewController
|
||||
- (NSString*)setUpCaptureSession {
|
||||
NSError* error = nil;
|
||||
|
||||
AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
|
||||
AVCaptureSession* captureSession = [[[AVCaptureSession alloc] init] autorelease];
|
||||
self.captureSession = captureSession;
|
||||
|
||||
AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user