Adding files for Android 6 Marshmallow compatibility and 64 bit devices, such as the Nexus 5x.
Fixes issue # 50 https://github.com/tjwoon/csZBar/issues/50
This commit is contained in:
parent
c51cfec6ff
commit
86f2ba77f7
@ -5,6 +5,7 @@ import java.lang.RuntimeException;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -16,6 +17,8 @@ import android.hardware.Camera.PreviewCallback;
|
|||||||
import android.hardware.Camera.AutoFocusCallback;
|
import android.hardware.Camera.AutoFocusCallback;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
@ -24,6 +27,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -52,7 +56,7 @@ implements SurfaceHolder.Callback {
|
|||||||
public static final String EXTRA_QRVALUE = "qrValue";
|
public static final String EXTRA_QRVALUE = "qrValue";
|
||||||
public static final String EXTRA_PARAMS = "params";
|
public static final String EXTRA_PARAMS = "params";
|
||||||
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
|
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
|
||||||
|
private static final int CAMERA_PERMISSION_REQUEST = 1;
|
||||||
// State -----------------------------------------------------------
|
// State -----------------------------------------------------------
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
@ -82,73 +86,111 @@ implements SurfaceHolder.Callback {
|
|||||||
// Activity Lifecycle ----------------------------------------------
|
// Activity Lifecycle ----------------------------------------------
|
||||||
|
|
||||||
@Override
|
@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);
|
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();
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
scanner = new ImageScanner();
|
String permissions[], int[] grantResults) {
|
||||||
scanner.setConfig(0, Config.X_DENSITY, 3);
|
switch (requestCode) {
|
||||||
scanner.setConfig(0, Config.Y_DENSITY, 3);
|
case CAMERA_PERMISSION_REQUEST: {
|
||||||
|
if (grantResults.length > 0
|
||||||
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
setUpCamera();
|
||||||
|
} else {
|
||||||
|
|
||||||
// Set the config for barcode formats
|
onBackPressed();
|
||||||
for(ZBarcodeFormat format : getFormats()) {
|
}
|
||||||
scanner.setConfig(format.getId(), Config.ENABLE, 1);
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// other 'case' lines to check for other
|
||||||
FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView"));
|
// permissions this app might request
|
||||||
scannerView.addView(scannerSurface);
|
}
|
||||||
|
}
|
||||||
|
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
|
@Override
|
||||||
@ -172,10 +214,10 @@ implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
if(camera == null) throw new Exception ("Error: No suitable camera found.");
|
if(camera == null) throw new Exception ("Error: No suitable camera found.");
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
die("Error: Could not open the camera.");
|
//die("Error: Could not open the camera.");
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
die(e.getMessage());
|
// die(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +232,7 @@ implements SurfaceHolder.Callback {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy ()
|
public void onDestroy ()
|
||||||
{
|
{
|
||||||
scanner.destroy();
|
if(scanner != null) scanner.destroy();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
android/libs/arm64-v8a/libiconv.so
Executable file
BIN
android/libs/arm64-v8a/libiconv.so
Executable file
Binary file not shown.
BIN
android/libs/arm64-v8a/libzbarjni.so
Executable file
BIN
android/libs/arm64-v8a/libzbarjni.so
Executable file
Binary file not shown.
@ -51,6 +51,8 @@
|
|||||||
<source-file src="android/libs/armeabi/libzbarjni.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/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/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/libiconv.so" target-dir="libs/x86" />
|
||||||
<source-file src="android/libs/x86/libzbarjni.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"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user