Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phonghan fixes and cordova-android 7 support #136

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
63 changes: 25 additions & 38 deletions android/ZBarScannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.AutoFocusCallback;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
Expand Down Expand Up @@ -201,19 +202,7 @@ public void onResume ()
super.onResume();

try {
if(whichCamera.equals("front")) {
int numCams = Camera.getNumberOfCameras();
CameraInfo cameraInfo = new CameraInfo();
for(int i=0; i<numCams; i++) {
Camera.getCameraInfo(i, cameraInfo);
if(cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
camera = Camera.open(i);
}
}
} else {
camera = Camera.open();
}

ensureCameraIsOpen();
if(camera == null) throw new Exception ("Error: No suitable camera found.");
} catch (RuntimeException e) {
//die("Error: Could not open the camera.");
Expand All @@ -223,7 +212,29 @@ public void onResume ()
return;
}
}

private void ensureCameraIsOpen() {
if (whichCamera.equals("front")) {
int numCams = Camera.getNumberOfCameras();
CameraInfo cameraInfo = new CameraInfo();
for(int i=0; i<numCams; i++) {
Camera.getCameraInfo(i, cameraInfo);
if(cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
camera = Camera.open(i);
}
}
} else {
camera = Camera.open();
}
}

private void setCameraDisplayOrientation(Activity activity ,int cameraId) {
ensureCameraIsOpen();
if (camera == null) {
Log.w(this.getClass().getName(), "No suitable camera found");
return;
}

android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
Expand Down Expand Up @@ -303,31 +314,7 @@ public void surfaceChanged (SurfaceHolder hld, int fmt, int w, int h)
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();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added android/res/drawable-hdpi/camera_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-ldpi/camera_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-mdpi/camera_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-xhdpi/camera_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/res/drawable-xxhdpi/camera_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/res/drawable/camera_flash.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 12 additions & 15 deletions android/res/layout/cszbarscanner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:paddingTop="15dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:gravity="center"
android:text="@string/csZbarScannerTitle"
android:textColor="@color/csZbarScannerTextColor"
android:background="@color/csZbarScannerTextBackground"
android:background="@color/csZbarScannerBackground"
android:fontFamily="sans-serif-light"
android:textSize="15pt" />
android:textSize="16sp" />

<TextView android:id="@+id/csZbarScannerInstructions"
android:layout_gravity="center|bottom"
android:layout_width="296dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="15dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:background="@color/csZbarScannerBackground"
android:gravity="center"
android:textSize="8pt"
android:textSize="14sp"
android:textColor="@color/csZbarScannerTextColor"
android:fontFamily="sans-serif-light"
android:text="@string/csZbarScannerInstructions" />
Expand All @@ -49,11 +46,11 @@
android:background="#ff0000" />

<ImageButton
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/camera_flash"
android:background="@color/csZbarScannerTextBackground"
android:background="@color/csZbarScannerBackground"
android:onClick="toggleFlash"
android:longClickable="true"
android:visibility="visible"
Expand Down
21 changes: 21 additions & 0 deletions ios/AlmaZBarReaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,25 @@ - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfac
}
}

- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

UIToolbar* toolbar = [[controls subviews] firstObject];
if (![toolbar isKindOfClass:UIToolbar.class])
return;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
// HACK to hide the Info button
for (UIBarButtonItem* item in [toolbar items]) {
UIButton* button = [item customView];
if ([button isKindOfClass:UIButton.class]) {
UIButtonType buttonType = [button buttonType];
if (buttonType == UIButtonTypeInfoDark || buttonType == UIButtonTypeInfoLight) {
[button setHidden:YES];
}
}
}
#endif
}

@end
16 changes: 15 additions & 1 deletion ios/CsZBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
// Hack to hide the bottom bar's Info button... originally based on http://stackoverflow.com/a/16353530
NSInteger infoButtonIndex;
if ([[[UIDevice currentDevice] systemVersion] compare:@"10.0" options:NSNumericSearch] != NSOrderedAscending) {
Expand All @@ -80,6 +81,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
}
UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:infoButtonIndex];
[infoButton setHidden:YES];
#endif

//UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"Press Me" forState:UIControlStateNormal]; [button sizeToFit]; [self.view addSubview:button];
CGRect screenRect = [[UIScreen mainScreen] bounds];
Expand All @@ -92,8 +94,20 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
//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)];
// UIBarButtonItem *buttonFlash = [[UIBarButtonItem alloc] initWithTitle:@"Flash" style:UIBarButtonItemStyleDone target:self action:@selector(toggleflash)];


NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"ZBar" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
NSString *imagePath = [bundle pathForResource:@"torch" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

UIBarButtonItem *buttonFlash = [[UIBarButtonItem alloc]
initWithImage:image
style:UIBarButtonItemStylePlain
target:(id)self
action:@selector(toggleflash)];

NSArray *buttons = [NSArray arrayWithObjects: buttonFlash, nil];
[toolbarViewFlash setItems:buttons animated:NO];
[self.scanReader.view addSubview:toolbarViewFlash];
Expand Down
Binary file added ios/ZBar.bundle/torch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ios/ZBar.bundle/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ios/ZBar.bundle/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 23 additions & 20 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="application">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="org.cloudsky.cordovaPlugins.ZBarScannerActivity"
android:screenOrientation="fullUser"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="org.cloudsky.cordovaPlugins.ZBarScannerActivity"
android:screenOrientation="fullUser"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-feature android:name="android.hardware.camera" />
Expand All @@ -44,25 +44,27 @@
<color name="csZbarScannerBackground">#000000</color>
</config-file>
<framework src="com.android.support:support-v4:23.1.0" />
<resource-file src="android/res/layout/cszbarscanner.xml" target="res/layout/cszbarscanner.xml" />
<source-file src="android/ZBarcodeFormat.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/ZBar.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/ZBarScannerActivity.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/libs/zbar.jar" target-dir="libs" />
<source-file src="android/libs/armeabi/libiconv.so" target-dir="libs/armeabi" />
<source-file src="android/libs/armeabi/libzbarjni.so" target-dir="libs/armeabi" />
<source-file src="android/libs/armeabi-v7a/libiconv.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/armeabi-v7a/libzbarjni.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/arm64-v8a/libiconv.so" target-dir="libs/arm64-v8a" />
<source-file src="android/libs/arm64-v8a/libzbarjni.so" target-dir="libs/arm64-v8a" />s
<source-file src="android/libs/x86/libiconv.so" target-dir="libs/x86" />
<source-file src="android/libs/x86/libzbarjni.so" target-dir="libs/x86" />
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-hdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-ldpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-mdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-xhdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-xxhdpi"/>
<lib-file src="android/libs/zbar.jar" />
<!-- jniLibs -->
<resource-file src="android/jniLibs/armeabi/libiconv.so" target="jniLibs/armeabi/libiconv.so" />
<resource-file src="android/jniLibs/armeabi/libzbarjni.so" target="jniLibs/armeabi/libzbarjni.so" />
<resource-file src="android/jniLibs/armeabi-v7a/libiconv.so" target="jniLibs/armeabi-v7a/libiconv.so" />
<resource-file src="android/jniLibs/armeabi-v7a/libzbarjni.so" target="jniLibs/armeabi-v7a/libzbarjni.so" />
<resource-file src="android/jniLibs/arm64-v8a/libiconv.so" target="jniLibs/arm64-v8a/libiconv.so" />
<resource-file src="android/jniLibs/arm64-v8a/libzbarjni.so" target="jniLibs/arm64-v8a/libzbarjni.so" />
<resource-file src="android/jniLibs/x86/libiconv.so" target="jniLibs/x86/libiconv.so" />
<resource-file src="android/jniLibs/x86/libzbarjni.so" target="jniLibs/x86/libzbarjni.so" />
<!-- resources -->
<resource-file src="android/res/layout/cszbarscanner.xml" target="res/layout/cszbarscanner.xml" />
<resource-file src="android/res/drawable/camera_flash.png" target="res/drawable/camera_flash.png"/>
<resource-file src="android/res/drawable-hdpi/camera_flash.png" target="res/drawable-hdpi/camera_flash.png"/>
<resource-file src="android/res/drawable-ldpi/camera_flash.png" target="res/drawable-ldpi/camera_flash.png"/>
<resource-file src="android/res/drawable-mdpi/camera_flash.png" target="res/drawable-mdpi/camera_flash.png"/>
<resource-file src="android/res/drawable-xhdpi/camera_flash.png" target="res/drawable-xhdpi/camera_flash.png"/>
<resource-file src="android/res/drawable-xxhdpi/camera_flash.png" target="res/drawable-xxhdpi/camera_flash.png"/>
</platform>

<platform name="ios">
Expand Down Expand Up @@ -108,6 +110,7 @@
<header-file src="ios/ZBarSDK/zbar/Video.h" />
<header-file src="ios/ZBarSDK/zbar/Window.h" />
<resource-file src="ios/Resources/CsZBarScanView.xib" />
<resource-file src="ios/ZBar.bundle"/>
</platform>

</plugin>