diff --git a/README.md b/README.md index 70b2610..6e2ed96 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This plugin integrates with the [ZBar](http://zbar.sourceforge.net/) library, exposing a JavaScript interface for scanning barcodes (QR, 2D, etc). +In this fork a button has been added to turn off and on device flash. In addition the plugin can now handle the device orientation change. ## Installation diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 06b3d86..9f23fa2 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -5,15 +5,20 @@ import java.lang.RuntimeException; import org.json.JSONException; import org.json.JSONObject; +import android.Manifest; import android.app.Activity; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.Resources; import android.hardware.Camera; import android.hardware.Camera.CameraInfo; +import android.hardware.Camera.Parameters; import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.AutoFocusCallback; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.Gravity; import android.view.SurfaceHolder; @@ -22,6 +27,9 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextView; +import android.content.pm.PackageManager; +import android.view.Surface; + import java.util.ArrayList; import java.util.Collection; @@ -43,14 +51,14 @@ implements SurfaceHolder.Callback { // Config ---------------------------------------------------------- - private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt. + private static int autoFocusInterval = 2000; // Interval between AFcallback and next AF attempt. // Public Constants ------------------------------------------------ public static final String EXTRA_QRVALUE = "qrValue"; public static final String EXTRA_PARAMS = "params"; public static final int RESULT_ERROR = RESULT_FIRST_USER + 1; - + private static final int CAMERA_PERMISSION_REQUEST = 1; // State ----------------------------------------------------------- private Camera camera; @@ -80,73 +88,111 @@ implements SurfaceHolder.Callback { // Activity Lifecycle ---------------------------------------------- @Override - public void onCreate (Bundle savedInstanceState) - { + public void onCreate (Bundle savedInstanceState) { + + + int permissionCheck = ContextCompat.checkSelfPermission(this.getBaseContext(), Manifest.permission.CAMERA); + + if(permissionCheck == PackageManager.PERMISSION_GRANTED){ + + setUpCamera(); + + } else { + + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.CAMERA}, + CAMERA_PERMISSION_REQUEST); + } super.onCreate(savedInstanceState); - // Get parameters from JS - Intent startIntent = getIntent(); - String paramStr = startIntent.getStringExtra(EXTRA_PARAMS); - JSONObject params; - try { params = new JSONObject(paramStr); } - catch (JSONException e) { params = new JSONObject(); } - String textTitle = params.optString("text_title"); - String textInstructions = params.optString("text_instructions"); - Boolean drawSight = params.optBoolean("drawSight", true); - whichCamera = params.optString("camera"); - flashMode = params.optString("flash"); - // Initiate instance variables - autoFocusHandler = new Handler(); - scanner = new ImageScanner(); - scanner.setConfig(0, Config.X_DENSITY, 3); - scanner.setConfig(0, Config.Y_DENSITY, 3); + } + public void onRequestPermissionsResult(int requestCode, + String permissions[], int[] grantResults) { + switch (requestCode) { + case CAMERA_PERMISSION_REQUEST: { + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + setUpCamera(); + } else { - // Set the config for barcode formats - for(ZBarcodeFormat format : getFormats()) { - scanner.setConfig(format.getId(), Config.ENABLE, 1); - } - - // Set content view - setContentView(getResourceId("layout/cszbarscanner")); - - // Update view with customisable strings - TextView view_textTitle = (TextView) findViewById(getResourceId("id/csZbarScannerTitle")); - TextView view_textInstructions = (TextView) findViewById(getResourceId("id/csZbarScannerInstructions")); - view_textTitle.setText(textTitle); - view_textInstructions.setText(textInstructions); - - // Draw/hide the sight - if(!drawSight) { - findViewById(getResourceId("id/csZbarScannerSight")).setVisibility(View.INVISIBLE); - } - - // Create preview SurfaceView - scannerSurface = new SurfaceView (this) { - @Override - public void onSizeChanged (int w, int h, int oldW, int oldH) { - surfW = w; - surfH = h; - matchSurfaceToPreviewRatio(); + onBackPressed(); + } + return; } - }; - scannerSurface.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, - Gravity.CENTER - )); - scannerSurface.getHolder().addCallback(this); - // Add preview SurfaceView to the screen - FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView")); - scannerView.addView(scannerSurface); + // other 'case' lines to check for other + // permissions this app might request + } + } + private void setUpCamera() { + // If request is cancelled, the result arrays are empty. + + + // Get parameters from JS + Intent startIntent = getIntent(); + String paramStr = startIntent.getStringExtra(EXTRA_PARAMS); + JSONObject params; + try { params = new JSONObject(paramStr); } + catch (JSONException e) { params = new JSONObject(); } + String textTitle = params.optString("text_title"); + String textInstructions = params.optString("text_instructions"); + Boolean drawSight = params.optBoolean("drawSight", true); + whichCamera = params.optString("camera"); + flashMode = params.optString("flash"); + + // Initiate instance variables + autoFocusHandler = new Handler(); + scanner = new ImageScanner(); + scanner.setConfig(0, Config.X_DENSITY, 3); + scanner.setConfig(0, Config.Y_DENSITY, 3); + + // Set the config for barcode formats + for(ZBarcodeFormat format : getFormats()) { + scanner.setConfig(format.getId(), Config.ENABLE, 1); + } + + // Set content view + setContentView(getResourceId("layout/cszbarscanner")); + + // Update view with customisable strings + TextView view_textTitle = (TextView) findViewById(getResourceId("id/csZbarScannerTitle")); + TextView view_textInstructions = (TextView) findViewById(getResourceId("id/csZbarScannerInstructions")); + view_textTitle.setText(textTitle); + view_textInstructions.setText(textInstructions); + + // Draw/hide the sight + if(!drawSight) { + findViewById(getResourceId("id/csZbarScannerSight")).setVisibility(View.INVISIBLE); + } + + // Create preview SurfaceView + scannerSurface = new SurfaceView (this) { + @Override + public void onSizeChanged (int w, int h, int oldW, int oldH) { + surfW = w; + surfH = h; + matchSurfaceToPreviewRatio(); + } + }; + scannerSurface.setLayoutParams(new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, + Gravity.CENTER + )); + scannerSurface.getHolder().addCallback(this); + + // Add preview SurfaceView to the screen + FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView")); + scannerView.addView(scannerSurface); + + findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront(); + findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront(); + findViewById(getResourceId("id/csZbarScannerSightContainer")).bringToFront(); + findViewById(getResourceId("id/csZbarScannerSight")).bringToFront(); + scannerView.requestLayout(); + scannerView.invalidate(); - findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront(); - findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront(); - findViewById(getResourceId("id/csZbarScannerSightContainer")).bringToFront(); - findViewById(getResourceId("id/csZbarScannerSight")).bringToFront(); - scannerView.requestLayout(); - scannerView.invalidate(); } @Override @@ -170,33 +216,36 @@ implements SurfaceHolder.Callback { if(camera == null) throw new Exception ("Error: No suitable camera found."); } catch (RuntimeException e) { - die("Error: Could not open the camera."); + //die("Error: Could not open the camera."); return; } catch (Exception e) { - die(e.getMessage()); + // die(e.getMessage()); return; } - - Camera.Parameters camParams = camera.getParameters(); - if(flashMode.equals("on")) { - camParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); - } else if(flashMode.equals("off")) { - camParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); - } else { - camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); - } - if (android.os.Build.VERSION.SDK_INT >= 14) { - camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); - } - - try { camera.setParameters(camParams); } - catch (RuntimeException e) { - Log.d("csZBar", "Unsupported camera parameter reported for flash mode: "+flashMode); - } - - tryStartPreview(); } + private void setCameraDisplayOrientation(Activity activity ,int cameraId) { + android.hardware.Camera.CameraInfo info = + new android.hardware.Camera.CameraInfo(); + android.hardware.Camera.getCameraInfo(cameraId, info); + int rotation = activity.getWindowManager().getDefaultDisplay() + .getRotation(); + int degrees = 0; + switch (rotation) { + case Surface.ROTATION_0: degrees = 0; break; + case Surface.ROTATION_90: degrees = 90; break; + case Surface.ROTATION_180: degrees = 180; break; + case Surface.ROTATION_270: degrees = 270; break; + } + int result; + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + result = (info.orientation + degrees) % 360; + result = (360 - result) % 360; // compensate the mirror + } else { // back-facing + result = (info.orientation - degrees + 360) % 360; + } + camera.setDisplayOrientation(result); + } @Override public void onPause () { @@ -207,7 +256,7 @@ implements SurfaceHolder.Callback { @Override public void onDestroy () { - scanner.destroy(); + if(scanner != null) scanner.destroy(); super.onDestroy(); } @@ -251,7 +300,75 @@ implements SurfaceHolder.Callback { holder = hld; tryStartPreview(); } + public void onConfigurationChanged(Configuration newConfig) + { + super.onConfigurationChanged(newConfig); + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + switch(rotation) + { + case 0: // '\0' + rotation = 90; + break; + case 1: // '\001' + rotation = 0; + break; + + case 2: // '\002' + rotation = 270; + break; + + case 3: // '\003' + rotation = 180; + break; + + default: + rotation = 90; + break; + } + camera.setDisplayOrientation(rotation); + android.hardware.Camera.Parameters params = camera.getParameters(); + tryStopPreview(); + tryStartPreview(); + + } + + public void toggleFlash(View view) { + camera.startPreview(); + android.hardware.Camera.Parameters camParams = camera.getParameters(); + //If the flash is set to off + try { + if (camParams.getFlashMode().equals(Parameters.FLASH_MODE_OFF) && !(camParams.getFlashMode().equals(Parameters.FLASH_MODE_TORCH)) && !(camParams.getFlashMode().equals(Parameters.FLASH_MODE_ON))) + camParams.setFlashMode(Parameters.FLASH_MODE_TORCH); + else //if(camParams.getFlashMode() == Parameters.FLASH_MODE_ON || camParams.getFlashMode()== Parameters.FLASH_MODE_TORCH) + camParams.setFlashMode(Parameters.FLASH_MODE_OFF); + } catch(RuntimeException e) { + + } + + try { + // camera.setParameters(camParams); + camera.setPreviewDisplay(holder); + camera.setPreviewCallback(previewCb); + camera.startPreview(); + if (android.os.Build.VERSION.SDK_INT >= 14) { + camera.autoFocus(autoFocusCb); // We are not using any of the + // continuous autofocus modes as that does not seem to work + // well with flash setting of "on"... At least with this + // simple and stupid focus method, we get to turn the flash + // on during autofocus. + camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); + } + //tryStopPreview(); + //tryStartPreview(); + //camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); + camera.setParameters(camParams); + } catch(RuntimeException e) { + Log.d("csZBar", (new StringBuilder("Unsupported camera parameter reported for flash mode: ")).append(flashMode).toString()); + } catch (IOException e) { + Log.d("csZBar", (new StringBuilder("Wrong holder data")).append(flashMode).toString()); + } + } // Continuously auto-focus ----------------------------------------- // For API Level < 14 @@ -380,8 +497,43 @@ implements SurfaceHolder.Callback { private void tryStartPreview () { if(holder != null) { try { + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + switch(rotation) + { + case 0: // '\0' + rotation = 90; + break; + + case 1: // '\001' + rotation = 0; + break; + + case 2: // '\002' + rotation = 270; + break; + + case 3: // '\003' + rotation = 180; + break; + + default: + rotation = 90; + break; + } // 90 degrees rotation for Portrait orientation Activity. - camera.setDisplayOrientation(90); + // camera.setDisplayOrientation(rotation); + setCameraDisplayOrientation(this, 0); + + android.hardware.Camera.Parameters camParams = camera.getParameters(); + + //camParams.setFlashMode(Parameters.FLASH_MODE_TORCH); + + try { + camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); + camera.setParameters(camParams); + } catch (Exception e) { + // TODO: don't swallow + } camera.setPreviewDisplay(holder); camera.setPreviewCallback(previewCb); diff --git a/android/libs/arm64-v8a/libiconv.so b/android/libs/arm64-v8a/libiconv.so new file mode 100755 index 0000000..31c8e4f Binary files /dev/null and b/android/libs/arm64-v8a/libiconv.so differ diff --git a/android/libs/arm64-v8a/libzbarjni.so b/android/libs/arm64-v8a/libzbarjni.so new file mode 100755 index 0000000..9e0ce49 Binary files /dev/null and b/android/libs/arm64-v8a/libzbarjni.so differ diff --git a/android/res/drawable/camera_flash.png b/android/res/drawable/camera_flash.png new file mode 100644 index 0000000..b6cf708 Binary files /dev/null and b/android/res/drawable/camera_flash.png differ diff --git a/android/res/layout/cszbarscanner.xml b/android/res/layout/cszbarscanner.xml index 4566d31..20bea7f 100644 --- a/android/res/layout/cszbarscanner.xml +++ b/android/res/layout/cszbarscanner.xml @@ -1,8 +1,8 @@ + android:textSize="15pt" /> + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:layout_gravity="center_horizontal|bottom"> + + diff --git a/ios/AlmaZBarReaderViewController.m b/ios/AlmaZBarReaderViewController.m index 9144939..c126506 100644 --- a/ios/AlmaZBarReaderViewController.m +++ b/ios/AlmaZBarReaderViewController.m @@ -7,6 +7,7 @@ // #import "AlmaZBarReaderViewController.h" +#import "CsZbar.h" @interface AlmaZBarReaderViewController () @@ -14,28 +15,92 @@ @implementation AlmaZBarReaderViewController + - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + //[button setTitle:@"Flash" forState:UIControlStateNormal]; + [button sizeToFit]; + CGRect screenRect = [[UIScreen mainScreen] bounds]; + //[button setContentEdgeInsets:UIEdgeInsetsMake(20, 30, 20, 30)]; + CGRect frame; + if(screenRect.size.height>(screenRect.size.width)){ + frame = CGRectMake(0,0, screenRect.size.width*(0.15), screenRect.size.height*0.15); + + //button.center = CGPointMake( 0,0); + }else{ + frame = CGRectMake(0,0, screenRect.size.width*(0.10), screenRect.size.height*0.20); + + //button.center = CGPointMake(0,0); + } + + button.frame =frame; + button.layer.cornerRadius = 10; + button.clipsToBounds = YES; + // Set a new (x,y) point for the button's center + + + + //[button setBackgroundColor:[UIColor colorWithRed:.859 green:.765 blue:.616 alpha:1.0] forState:UIControlStateHighlighted]; + + //button.center = CGPointMake( 0,0); + [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; + + [self.view addSubview:button]; + +} +- (BOOL)prefersStatusBarHidden { + return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - --(BOOL)shouldAutorotate{ - return NO; +//Techedge Changes NSS fase 2 +- (void)buttonPressed: (UIButton *) button { + + CsZBar *obj = [[CsZBar alloc] init]; + + [obj toggleflash]; + } + +- (BOOL)shouldAutorotate{ + return YES; +} +- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ + //AlmaZBarReaderViewController.scanner.scanner.cameraOverlayView = poli + //NSDictionary *params = (NSDictionary*) [command argumentAtIndex:0]; + BOOL drawSight = true;//[params objectForKey:@"drawSight"] ? [[params objectForKey:@"drawSight"] boolValue] : true; + if(drawSight){ + CGRect screenRect = [[UIScreen mainScreen] bounds]; + CGFloat screenWidth = screenRect.size.width; + CGFloat screenHeight = screenRect.size.height; + CGFloat dim = screenWidth < screenHeight ? screenWidth / 1.1 : screenHeight / 1.1; + UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)]; + //polygonView.center = self.scanReader.view.center; + //polygonView.layer.borderColor = [UIColor greenColor].CGColor; + //polygonView.layer.borderWidth = 3.0f; + + UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)]; + lineView.backgroundColor = [UIColor redColor]; + [polygonView addSubview:lineView]; + self.cameraOverlayView = polygonView; + + + } +} /* -#pragma mark - Navigation - -// In a storyboard-based application, you will often want to do a little preparation before navigation -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. -} -*/ + #pragma mark - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. + } + */ @end diff --git a/ios/CsZBar.h b/ios/CsZBar.h index e774ae2..f043e6c 100644 --- a/ios/CsZBar.h +++ b/ios/CsZBar.h @@ -1,9 +1,14 @@ #import #import "ZBarSDK.h" +#import @interface CsZBar : CDVPlugin - (void)scan: (CDVInvokedUrlCommand*)command; +- (void)toggleflash; + + + @end diff --git a/ios/CsZBar.m b/ios/CsZBar.m index 9d28c35..57959f9 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -1,4 +1,5 @@ #import "CsZBar.h" +#import #import "AlmaZBarReaderViewController.h" #pragma mark - State @@ -7,6 +8,7 @@ @property bool scanInProgress; @property NSString *scanCallbackId; @property AlmaZBarReaderViewController *scanReader; + @end @@ -25,12 +27,31 @@ { self.scanInProgress = NO; } +- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + return; +} +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait); +} +/* +- (void)viewDidLoad { + UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; + [button setTitle:@"Turn on Flash" forState:UIControlStateNormal]; + [button sizeToFit]; + // Set a new (x,y) point for the button's center + button.center = CGPointMake(320/2, 60); + [button addTarget:self action:@selector(flashOn) forControlEvents:UIControlEventTouchUpInside]; + [self.viewController parentViewController:button]; +}*/ #pragma mark - Plugin API - (void)scan: (CDVInvokedUrlCommand*)command; { + + if(self.scanInProgress) { [self.commandDelegate sendPluginResult: [CDVPluginResult @@ -53,29 +74,48 @@ // as not all devices will have a rear-facing camera. self.scanReader.cameraDevice = UIImagePickerControllerCameraDeviceFront; } + self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; + NSString *flash = [params objectForKey:@"flash"]; - if([flash isEqualToString:@"on"]) { + if([flash isEqualToString:@"on"]) { self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; } else if([flash isEqualToString:@"off"]) { self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; + }else if([flash isEqualToString:@"auto"]) { + self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } // Hack to hide the bottom bar's Info button... originally based on http://stackoverflow.com/a/16353530 UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3]; [infoButton setHidden:YES]; + // Add an action in current code file (i.e. target) + // [infoButton addTarget: action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside]; + //UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"Press Me" forState:UIControlStateNormal]; [button sizeToFit]; [self.view addSubview:button]; + CGRect screenRect = [[UIScreen mainScreen] bounds]; + CGFloat screenWidth = screenRect.size.width; + CGFloat screenHeight = screenRect.size.height; + + BOOL drawSight = [params objectForKey:@"drawSight"] ? [[params objectForKey:@"drawSight"] boolValue] : true; + UIToolbar *toolbarViewFlash = [[UIToolbar alloc] init]; + //The bar length it depends on the orientation + toolbarViewFlash.frame = CGRectMake(0.0, 0, (screenWidth > screenHeight ?screenWidth:screenHeight), 44.0); + toolbarViewFlash.barStyle = UIBarStyleBlackOpaque; + UIBarButtonItem *buttonFlash = [[UIBarButtonItem alloc] initWithTitle:@"Flash" style:UIBarButtonItemStyleDone target:self action:@selector(toggleflash)]; + NSArray *buttons = [NSArray arrayWithObjects: buttonFlash, nil]; + [toolbarViewFlash setItems:buttons animated:NO]; + [self.scanReader.view addSubview:toolbarViewFlash]; + if(drawSight){ - CGRect screenRect = [[UIScreen mainScreen] bounds]; - CGFloat screenWidth = screenRect.size.width; - CGFloat screenHeight = screenRect.size.height; + CGFloat dim = screenWidth < screenHeight ? screenWidth / 1.1 : screenHeight / 1.1; - UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)]; + UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)]; //polygonView.center = self.scanReader.view.center; //polygonView.layer.borderColor = [UIColor greenColor].CGColor; //polygonView.layer.borderWidth = 3.0f; - UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(dim / 2, 0, 1, dim)]; + UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)]; lineView.backgroundColor = [UIColor redColor]; [polygonView addSubview:lineView]; @@ -87,6 +127,23 @@ } } +- (void)toggleflash{ + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + [device lockForConfiguration:nil]; + if (device.torchAvailable == 1) { + if (device.torchMode == 0) { + [device setTorchMode:AVCaptureTorchModeOn]; + [device setFlashMode:AVCaptureFlashModeOn]; + + }else{ + [device setTorchMode:AVCaptureTorchModeOff]; + [device setFlashMode:AVCaptureFlashModeOff]; + } + + } + [device unlockForConfiguration]; + +} #pragma mark - Helpers @@ -98,6 +155,10 @@ #pragma mark - ZBarReaderDelegate +- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { + return; +} + - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { if ([self.scanReader isBeingDismissed]) { return; } diff --git a/package.json b/package.json index 798210f..3a59007 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-cszbar", - "version": "1.3.1", + "version": "1.3.3", "description": "Plugin to integrate with the ZBar barcode scanning library.", "cordova": { "id": "cordova-plugin-cszbar", diff --git a/plugin.xml b/plugin.xml index dd5c2b7..b370cf6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ + id="cordova-plugin-cszbar" version="1.3.2"> @@ -23,11 +23,10 @@ - - + android:screenOrientation="fullUser" + android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" /> @@ -43,6 +42,7 @@ #88000000 #000000 + @@ -52,8 +52,16 @@ + + s + + + + + +