Добавил библиотеку zbar, она медленно, но верно распознает код на серебрянной карточке. Нужно настроить конфиг.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,7 +3,9 @@
|
|||||||
.idea
|
.idea
|
||||||
.packages
|
.packages
|
||||||
.pub/
|
.pub/
|
||||||
|
.gradle/
|
||||||
build/
|
build/
|
||||||
|
gen/
|
||||||
ios/.generated/
|
ios/.generated/
|
||||||
packages
|
packages
|
||||||
pubspec.lock
|
pubspec.lock
|
||||||
|
|||||||
12
android.iml
12
android.iml
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/android">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Flutter for Android" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -36,6 +36,10 @@ android {
|
|||||||
signingConfig signingConfigs.debug
|
signingConfig signingConfigs.debug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets.main {
|
||||||
|
jniLibs.srcDir 'jniLibs'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flutter {
|
flutter {
|
||||||
@@ -43,6 +47,7 @@ flutter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
androidTestCompile 'com.android.support:support-annotations:25.4.0'
|
androidTestCompile 'com.android.support:support-annotations:25.4.0'
|
||||||
androidTestCompile 'com.android.support.test:runner:0.5'
|
androidTestCompile 'com.android.support.test:runner:0.5'
|
||||||
androidTestCompile 'com.android.support.test:rules:0.5'
|
androidTestCompile 'com.android.support.test:rules:0.5'
|
||||||
|
|||||||
BIN
android/app/jniLibs/armeabi-v7a/libiconv.so
Normal file
BIN
android/app/jniLibs/armeabi-v7a/libiconv.so
Normal file
Binary file not shown.
BIN
android/app/jniLibs/armeabi-v7a/libzbarjni.so
Normal file
BIN
android/app/jniLibs/armeabi-v7a/libzbarjni.so
Normal file
Binary file not shown.
BIN
android/app/jniLibs/armeabi/libiconv.so
Normal file
BIN
android/app/jniLibs/armeabi/libiconv.so
Normal file
Binary file not shown.
BIN
android/app/jniLibs/armeabi/libzbarjni.so
Normal file
BIN
android/app/jniLibs/armeabi/libzbarjni.so
Normal file
Binary file not shown.
BIN
android/app/jniLibs/x86/libiconv.so
Normal file
BIN
android/app/jniLibs/x86/libiconv.so
Normal file
Binary file not shown.
BIN
android/app/jniLibs/x86/libzbarjni.so
Normal file
BIN
android/app/jniLibs/x86/libzbarjni.so
Normal file
Binary file not shown.
BIN
android/app/libs/zbar.jar
Normal file
BIN
android/app/libs/zbar.jar
Normal file
Binary file not shown.
@@ -10,6 +10,7 @@
|
|||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
|
|
||||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.yourcompany.checker;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.yourcompany.checker.R;
|
|
||||||
|
|
||||||
public class CameraActivity extends Activity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.a_scanner);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package com.yourcompany.checker;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import android.hardware.Camera;
|
||||||
|
import android.hardware.Camera.PreviewCallback;
|
||||||
|
import android.hardware.Camera.AutoFocusCallback;
|
||||||
|
import android.hardware.Camera.Parameters;
|
||||||
|
import android.hardware.Camera.Size;
|
||||||
|
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
|
import android.graphics.ImageFormat;
|
||||||
|
import net.sourceforge.zbar.ImageScanner;
|
||||||
|
import net.sourceforge.zbar.Image;
|
||||||
|
import net.sourceforge.zbar.Symbol;
|
||||||
|
import net.sourceforge.zbar.SymbolSet;
|
||||||
|
import net.sourceforge.zbar.Config;
|
||||||
|
|
||||||
|
import com.yourcompany.checker.R;
|
||||||
|
import com.yourcompany.checker.view.CameraPreview;
|
||||||
|
|
||||||
|
public class CameraActivity extends Activity {
|
||||||
|
|
||||||
|
private Camera mCamera;
|
||||||
|
private SurfaceView mPreview;
|
||||||
|
private Handler autoFocusHandler;
|
||||||
|
|
||||||
|
ImageScanner scanner;
|
||||||
|
|
||||||
|
private boolean barcodeScanned = false;
|
||||||
|
private boolean previewing = true;
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("iconv");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.a_scanner);
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
|
||||||
|
autoFocusHandler = new Handler();
|
||||||
|
mCamera = getCameraInstance();
|
||||||
|
|
||||||
|
/* Instance barcode scanner */
|
||||||
|
scanner = new ImageScanner();
|
||||||
|
scanner.setConfig(0, Config.X_DENSITY, 3);
|
||||||
|
scanner.setConfig(0, Config.Y_DENSITY, 3);
|
||||||
|
|
||||||
|
mPreview = (SurfaceView) findViewById(R.id.cameraPreview);
|
||||||
|
|
||||||
|
SurfaceHolder holder = mPreview.getHolder();
|
||||||
|
holder.addCallback(new SurfaceHolder.Callback() {
|
||||||
|
@Override
|
||||||
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
try {
|
||||||
|
mCamera.setPreviewDisplay(holder);
|
||||||
|
mCamera.startPreview();
|
||||||
|
mCamera.setPreviewCallback(previewCallback);
|
||||||
|
mCamera.autoFocus(autoFocusCB);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||||
|
mCamera.setDisplayOrientation(270);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
releaseCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A safe way to get an instance of the Camera object. */
|
||||||
|
public static Camera getCameraInstance(){
|
||||||
|
Camera c = null;
|
||||||
|
try {
|
||||||
|
c = Camera.open();
|
||||||
|
} catch (Exception e){
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseCamera() {
|
||||||
|
if (mCamera != null) {
|
||||||
|
previewing = false;
|
||||||
|
mCamera.setPreviewCallback(null);
|
||||||
|
mCamera.release();
|
||||||
|
mCamera = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Runnable doAutoFocus = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (previewing)
|
||||||
|
mCamera.autoFocus(autoFocusCB);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
PreviewCallback previewCallback = new PreviewCallback() {
|
||||||
|
public void onPreviewFrame(byte[] data, Camera camera) {
|
||||||
|
Camera.Parameters parameters = camera.getParameters();
|
||||||
|
Size size = parameters.getPreviewSize();
|
||||||
|
|
||||||
|
Image barcode = new Image(size.width, size.height, "Y800");
|
||||||
|
barcode.setData(data);
|
||||||
|
|
||||||
|
int result = scanner.scanImage(barcode);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
previewing = false;
|
||||||
|
mCamera.setPreviewCallback(null);
|
||||||
|
mCamera.stopPreview();
|
||||||
|
|
||||||
|
SymbolSet syms = scanner.getResults();
|
||||||
|
for (Symbol sym : syms) {
|
||||||
|
barcodeScanned = true;
|
||||||
|
Toast.makeText(CameraActivity.this, sym.getData(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mimic continuous auto-focusing
|
||||||
|
AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
|
||||||
|
public void onAutoFocus(boolean success, Camera camera) {
|
||||||
|
autoFocusHandler.postDelayed(doAutoFocus, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startScanner() {
|
public void startScanner() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.yourcompany.checker.view;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Surface;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import android.hardware.Camera;
|
||||||
|
import android.hardware.Camera.PreviewCallback;
|
||||||
|
import android.hardware.Camera.AutoFocusCallback;
|
||||||
|
import android.hardware.Camera.Parameters;
|
||||||
|
|
||||||
|
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
|
private SurfaceHolder mHolder;
|
||||||
|
private Camera mCamera;
|
||||||
|
private PreviewCallback previewCallback;
|
||||||
|
private AutoFocusCallback autoFocusCallback;
|
||||||
|
|
||||||
|
public CameraPreview(Context context, Camera camera,
|
||||||
|
PreviewCallback previewCb,
|
||||||
|
AutoFocusCallback autoFocusCb) {
|
||||||
|
super(context);
|
||||||
|
mCamera = camera;
|
||||||
|
previewCallback = previewCb;
|
||||||
|
autoFocusCallback = autoFocusCb;
|
||||||
|
mHolder = getHolder();
|
||||||
|
mHolder.addCallback(this);
|
||||||
|
|
||||||
|
// deprecated setting, but required on Android versions prior to 3.0
|
||||||
|
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
// The Surface has been created, now tell the camera where to draw the preview.
|
||||||
|
try {
|
||||||
|
mCamera.setPreviewDisplay(holder);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d("DBG", "Error setting camera preview: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
// Camera preview released in activity
|
||||||
|
}
|
||||||
|
|
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||||
|
/*
|
||||||
|
* If your preview can change or rotate, take care of those events here.
|
||||||
|
* Make sure to stop the preview before resizing or reformatting it.
|
||||||
|
*/
|
||||||
|
if (mHolder.getSurface() == null){
|
||||||
|
// preview surface does not exist
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop preview before making changes
|
||||||
|
try {
|
||||||
|
mCamera.stopPreview();
|
||||||
|
} catch (Exception e){
|
||||||
|
// ignore: tried to stop a non-existent preview
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Hard code camera surface rotation 90 degs to match Activity view in portrait
|
||||||
|
mCamera.setDisplayOrientation(90);
|
||||||
|
|
||||||
|
mCamera.setPreviewDisplay(mHolder);
|
||||||
|
mCamera.setPreviewCallback(previewCallback);
|
||||||
|
mCamera.startPreview();
|
||||||
|
mCamera.autoFocus(autoFocusCallback);
|
||||||
|
} catch (Exception e){
|
||||||
|
Log.d("DBG", "Error starting camera preview: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/rootLayout"
|
android:id="@+id/rootLayout"
|
||||||
android:background="@android:color/white"
|
android:background="@android:color/white"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<SurfaceView android:id="@+id/cameraPreview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
<TextView android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="Asdf"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
15
checker.iml
15
checker.iml
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="FLUTTER_MODULE_TYPE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/packages" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
|
||||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/android">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Flutter for Android" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Reference in New Issue
Block a user