* 更新CameraX至v1.0.0-rc03
* 优化一些默认配置
This commit is contained in:
12
README.md
12
README.md
@@ -3,7 +3,7 @@
|
||||

|
||||
|
||||
[](https://raw.githubusercontent.com/jenly1314/ZXingLite/master/app/release/app-release.apk)
|
||||
[](https://bintray.com/beta/#/jenly/maven/zxing-lite)
|
||||
[](https://bintray.com/beta/#/jenly/maven/zxing-lite)
|
||||
[](https://jitpack.io/#jenly1314/ZXingLite)
|
||||
[](https://travis-ci.org/jenly1314/ZXingLite)
|
||||
[](https://circleci.com/gh/jenly1314/ZXingLite)
|
||||
@@ -59,16 +59,16 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
|
||||
最新版本
|
||||
```gradle
|
||||
//AndroidX 版本
|
||||
implementation 'com.king.zxing:zxing-lite:2.0.2'
|
||||
implementation 'com.king.zxing:zxing-lite:2.0.3'
|
||||
|
||||
```
|
||||
|
||||
以前 **v1.x** 旧版本
|
||||
**v1.x** 旧版本
|
||||
```gradle
|
||||
//AndroidX 版本
|
||||
implementation 'com.king.zxing:zxing-lite:1.1.9-androidx'
|
||||
|
||||
//Android 版本
|
||||
//Android Support 版本
|
||||
implementation 'com.king.zxing:zxing-lite:1.1.9'
|
||||
```
|
||||
|
||||
@@ -240,6 +240,10 @@ compileOptions {
|
||||
|
||||
## 版本记录
|
||||
|
||||
#### v2.0.3:2021-3-26
|
||||
* 更新CameraX至v1.0.0-rc03
|
||||
* 优化一些默认配置
|
||||
|
||||
#### v2.0.2:2021-1-14
|
||||
* **ViewfinderView** 新增 **labelTextWidth** 属性
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":29,"versionName":"2.0.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":30,"versionName":"2.0.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
|
||||
@@ -97,7 +97,16 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
if(isContinuousScan){
|
||||
showToast(result.getText());
|
||||
}
|
||||
//如果支持连扫,返回true即可
|
||||
/*
|
||||
* 因为setAnalyzeImage方法能动态控制是否继续分析图像。
|
||||
*
|
||||
* 1. 因为分析图像默认为true,如果想支持连扫,返回true即可。
|
||||
* 当连扫的处理逻辑比较复杂时,请在处理逻辑前调用getCameraScan().setAnalyzeImage(false),
|
||||
* 来停止分析图像,等逻辑处理完后再调用getCameraScan().setAnalyzeImage(true)来继续分析图像。
|
||||
*
|
||||
* 2. 如果只是想拦截扫码结果回调自己处理逻辑,但并不想继续分析图像(即不想连扫),可通过
|
||||
* 调用getCameraScan().setAnalyzeImage(false)来停止分析图像。
|
||||
*/
|
||||
return isContinuousScan;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.king.zxing.analyze.AreaRectAnalyzer;
|
||||
import com.king.zxing.analyze.BarcodeFormatAnalyzer;
|
||||
import com.king.zxing.analyze.ImageAnalyzer;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
@@ -82,12 +83,22 @@ public abstract class CameraScan implements ICamera,ICameraControl {
|
||||
|
||||
/**
|
||||
* 设置是否分析图像,通过此方法可以动态控制是否分析图像,常用于中断扫码识别。如:连扫时,扫到结果,然后停止分析图像
|
||||
*
|
||||
* 1. 因为分析图像默认为true,如果想支持连扫,在{@link OnScanResultCallback#onScanResultCallback(Result)}返回true拦截即可。
|
||||
* 当连扫的处理逻辑比较复杂时,请在处理逻辑前通过调用setAnalyzeImage(false)来停止分析图像,
|
||||
* 等逻辑处理完后再调用getCameraScan().setAnalyzeImage(true)来继续分析图像。
|
||||
*
|
||||
* 2. 如果只是想拦截扫码结果回调自己处理逻辑,但并不想继续分析图像(即不想连扫),可通过
|
||||
* 调用getCameraScan().setAnalyzeImage(false)来停止分析图像。
|
||||
* @param analyze
|
||||
*/
|
||||
public abstract CameraScan setAnalyzeImage(boolean analyze);
|
||||
|
||||
/**
|
||||
* 设置分析器,内置了一些{@link Analyzer}的实现类如下
|
||||
* 设置分析器,如果内置的一些分析器不满足您的需求,你也可以自定义{@link Analyzer},
|
||||
* 自定义时,切记需在{@link #startCamera()}之前调用才有效。
|
||||
*
|
||||
* 内置了一些{@link Analyzer}的实现类如下:
|
||||
* @see {@link MultiFormatAnalyzer}
|
||||
* @see {@link AreaRectAnalyzer}
|
||||
* @see {@link ImageAnalyzer}
|
||||
@@ -147,9 +158,21 @@ public abstract class CameraScan implements ICamera,ICameraControl {
|
||||
*
|
||||
*/
|
||||
boolean onScanResultCallback(Result result);
|
||||
|
||||
/**
|
||||
* 扫码结果识别失败时触发此回调方法
|
||||
*/
|
||||
default void onScanResultFailure(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析扫码结果
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public static String parseScanResult(Intent data){
|
||||
if(data != null){
|
||||
|
||||
@@ -301,7 +301,7 @@ public class DecodeConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 识别区域垂直方向偏移量
|
||||
* 识别区域垂直方向偏移量,支持负数,大于0时,居中心向下偏移,小于0时,居中心向上偏移
|
||||
* @return
|
||||
*/
|
||||
public int getAreaRectVerticalOffset() {
|
||||
@@ -309,7 +309,7 @@ public class DecodeConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置识别区域垂直方向偏移量
|
||||
* 设置识别区域垂直方向偏移量,支持负数,大于0时,居中心向下偏移,小于0时,居中心向上偏移
|
||||
* @param areaRectVerticalOffset
|
||||
* @return
|
||||
*/
|
||||
@@ -319,7 +319,7 @@ public class DecodeConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 识别区域水平方向偏移量
|
||||
* 识别区域水平方向偏移量,支持负数,大于0时,居中心向右偏移,小于0时,居中心向左偏移
|
||||
* @return
|
||||
*/
|
||||
public int getAreaRectHorizontalOffset() {
|
||||
@@ -327,7 +327,7 @@ public class DecodeConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置识别区域水平方向偏移量
|
||||
* 设置识别区域水平方向偏移量,支持负数,大于0时,居中心向右偏移,小于0时,居中心向左偏移
|
||||
* @param areaRectHorizontalOffset
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Size;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.view.View;
|
||||
@@ -20,6 +21,7 @@ import com.king.zxing.util.LogUtils;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.Camera;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
@@ -94,8 +96,9 @@ public class DefaultCameraScan extends CameraScan {
|
||||
private boolean isClickTap;
|
||||
private float mDownX;
|
||||
private float mDownY;
|
||||
private Size mTargetSize;
|
||||
|
||||
public DefaultCameraScan(FragmentActivity activity, PreviewView previewView){
|
||||
public DefaultCameraScan(@NonNull FragmentActivity activity,@NonNull PreviewView previewView){
|
||||
this.mFragmentActivity = activity;
|
||||
this.mLifecycleOwner = activity;
|
||||
this.mContext = activity;
|
||||
@@ -103,7 +106,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
initData();
|
||||
}
|
||||
|
||||
public DefaultCameraScan(Fragment fragment, PreviewView previewView){
|
||||
public DefaultCameraScan(@NonNull Fragment fragment,@NonNull PreviewView previewView){
|
||||
this.mFragmentActivity = fragment.getActivity();
|
||||
this.mLifecycleOwner = fragment;
|
||||
this.mContext = fragment.getContext();
|
||||
@@ -127,10 +130,15 @@ public class DefaultCameraScan extends CameraScan {
|
||||
private void initData(){
|
||||
mResultLiveData = new MutableLiveData<>();
|
||||
mResultLiveData.observe(mLifecycleOwner, result -> {
|
||||
if(result != null){
|
||||
handleAnalyzeResult(result);
|
||||
}else if(mOnScanResultCallback != null){
|
||||
mOnScanResultCallback.onScanResultFailure();
|
||||
}
|
||||
});
|
||||
|
||||
mOrientation = mContext.getResources().getConfiguration().orientation;
|
||||
|
||||
ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
|
||||
mPreviewView.setOnTouchListener((v, event) -> {
|
||||
handlePreviewViewClickTap(event);
|
||||
@@ -143,6 +151,15 @@ public class DefaultCameraScan extends CameraScan {
|
||||
DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
|
||||
mScreenWidth = displayMetrics.widthPixels;
|
||||
mScreenHeight = displayMetrics.heightPixels;
|
||||
|
||||
LogUtils.d(String.format("screenSize: %d * %d",mScreenWidth,mScreenHeight));
|
||||
//因为为了保持流畅性和性能,限制在1080p,在此前提下尽可能的找到屏幕接近的分辨率
|
||||
if(mScreenWidth < mScreenHeight){
|
||||
mTargetSize = new Size(mScreenWidth,mScreenWidth / 9 * 16);
|
||||
}else{
|
||||
mTargetSize = new Size(mScreenHeight / 9 * 16, mScreenHeight);
|
||||
}
|
||||
|
||||
mBeepManager = new BeepManager(mContext);
|
||||
mAmbientLightManager = new AmbientLightManager(mContext);
|
||||
if(mAmbientLightManager != null){
|
||||
@@ -223,21 +240,19 @@ public class DefaultCameraScan extends CameraScan {
|
||||
Preview preview = mCameraConfig.options(new Preview.Builder());
|
||||
|
||||
//相机选择器
|
||||
CameraSelector cameraSelector = mCameraConfig.options(new CameraSelector.Builder()
|
||||
.requireLensFacing(LENS_FACING_BACK));
|
||||
CameraSelector cameraSelector = mCameraConfig.options(new CameraSelector.Builder());
|
||||
//设置SurfaceProvider
|
||||
preview.setSurfaceProvider(mPreviewView.getSurfaceProvider());
|
||||
|
||||
//图像分析
|
||||
ImageAnalysis imageAnalysis = mCameraConfig.options(new ImageAnalysis.Builder()
|
||||
.setTargetResolution(mTargetSize)
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST));
|
||||
imageAnalysis.setAnalyzer(Executors.newSingleThreadExecutor(), image -> {
|
||||
if(isAnalyze && !isAnalyzeResult && mAnalyzer != null){
|
||||
Result result = mAnalyzer.analyze(image,mOrientation);
|
||||
if(result != null){
|
||||
mResultLiveData.postValue(result);
|
||||
}
|
||||
}
|
||||
image.close();
|
||||
});
|
||||
if(mCamera != null){
|
||||
@@ -257,6 +272,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
* @param result
|
||||
*/
|
||||
private synchronized void handleAnalyzeResult(Result result){
|
||||
|
||||
if(isAnalyzeResult || !isAnalyze){
|
||||
return;
|
||||
}
|
||||
@@ -332,11 +348,6 @@ public class DefaultCameraScan extends CameraScan {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分析器,如果内置的一些分析器不满足您的需求,你也可以自定义{@link Analyzer},
|
||||
* 自定义时,切记需在{@link #startCamera()}之前调用才有效
|
||||
* @param analyzer
|
||||
*/
|
||||
@Override
|
||||
public CameraScan setAnalyzer(Analyzer analyzer) {
|
||||
mAnalyzer = analyzer;
|
||||
|
||||
@@ -86,10 +86,6 @@ public class ViewfinderView extends View {
|
||||
* 扫码框四角颜色
|
||||
*/
|
||||
private int cornerColor;
|
||||
// /**
|
||||
// * 结果点颜色
|
||||
// */
|
||||
// private int resultPointColor;
|
||||
|
||||
/**
|
||||
* 提示文本与扫码框的边距
|
||||
@@ -124,10 +120,6 @@ public class ViewfinderView extends View {
|
||||
* 扫描线结束位置
|
||||
*/
|
||||
public int scannerEnd = 0;
|
||||
/**
|
||||
* 是否显示结果点
|
||||
*/
|
||||
private boolean isShowResultPoint;
|
||||
|
||||
/**
|
||||
* 扫码框宽
|
||||
@@ -286,7 +278,6 @@ public class ViewfinderView extends View {
|
||||
frameColor = array.getColor(R.styleable.ViewfinderView_frameColor, ContextCompat.getColor(context,R.color.viewfinder_frame));
|
||||
cornerColor = array.getColor(R.styleable.ViewfinderView_cornerColor, ContextCompat.getColor(context,R.color.viewfinder_corner));
|
||||
laserColor = array.getColor(R.styleable.ViewfinderView_laserColor, ContextCompat.getColor(context,R.color.viewfinder_laser));
|
||||
// resultPointColor = array.getColor(R.styleable.ViewfinderView_resultPointColor, ContextCompat.getColor(context,R.color.viewfinder_result_point_color));
|
||||
|
||||
labelText = array.getString(R.styleable.ViewfinderView_labelText);
|
||||
labelTextColor = array.getColor(R.styleable.ViewfinderView_labelTextColor, ContextCompat.getColor(context,R.color.viewfinder_text_color));
|
||||
@@ -295,8 +286,6 @@ public class ViewfinderView extends View {
|
||||
labelTextWidth = array.getDimensionPixelSize(R.styleable.ViewfinderView_labelTextWidth,0);
|
||||
labelTextLocation = TextLocation.getFromInt(array.getInt(R.styleable.ViewfinderView_labelTextLocation,0));
|
||||
|
||||
// isShowResultPoint = array.getBoolean(R.styleable.ViewfinderView_showResultPoint,false);
|
||||
|
||||
frameWidth = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameWidth,0);
|
||||
frameHeight = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameHeight,0);
|
||||
|
||||
@@ -589,21 +578,10 @@ public class ViewfinderView extends View {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public boolean isShowResultPoint() {
|
||||
return isShowResultPoint;
|
||||
}
|
||||
|
||||
public void setLaserStyle(LaserStyle laserStyle) {
|
||||
this.laserStyle = laserStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示结果点
|
||||
* @param showResultPoint 是否显示结果点
|
||||
*/
|
||||
public void setShowResultPoint(boolean showResultPoint) {
|
||||
isShowResultPoint = showResultPoint;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,6 +41,7 @@ public abstract class AreaRectAnalyzer extends ImageAnalyzer {
|
||||
@Nullable
|
||||
@Override
|
||||
public Result analyze(byte[] data, int width, int height) {
|
||||
LogUtils.d(String.format("width:%d, height:%d",width,height));
|
||||
if(mDecodeConfig != null){
|
||||
if(mDecodeConfig.isFullAreaScan()){
|
||||
//mDecodeConfig为空或者支持全区域扫码识别时,直接使用全区域进行扫码识别
|
||||
|
||||
@@ -185,7 +185,7 @@ public final class CodeUtils {
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
} catch (WriterException e) {
|
||||
} catch (Exception e) {
|
||||
LogUtils.w(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -224,8 +224,9 @@ public final class CodeUtils {
|
||||
|
||||
//logo大小为二维码整体大小
|
||||
float scaleFactor = srcWidth * ratio / logoWidth;
|
||||
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
|
||||
Bitmap bitmap;
|
||||
try {
|
||||
bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(src, 0, 0, null);
|
||||
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
## 版本记录
|
||||
|
||||
#### v2.0.3:2021-3-26
|
||||
* 更新CameraX至v1.0.0-rc03
|
||||
* 优化一些默认配置
|
||||
|
||||
#### v2.0.2:2021-1-14
|
||||
* **ViewfinderView** 新增 **labelTextWidth** 属性
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//App
|
||||
def app_version = [:]
|
||||
app_version.versionCode = 29
|
||||
app_version.versionName = "2.0.2"
|
||||
app_version.versionCode = 30
|
||||
app_version.versionName = "2.0.3"
|
||||
ext.app_version = app_version
|
||||
|
||||
//build version
|
||||
@@ -35,7 +35,7 @@ versions.coreKtx = "1.3.2"
|
||||
//zxing
|
||||
versions.zxing = "3.3.3"
|
||||
|
||||
versions.camerax = "1.0.0-rc01"
|
||||
versions.camerax = "1.0.0-rc03"
|
||||
|
||||
versions.easypermissions = "3.0.0"
|
||||
|
||||
@@ -68,7 +68,7 @@ deps.zxing = "com.google.zxing:core:$versions.zxing"
|
||||
deps.camera_core = "androidx.camera:camera-core:$versions.camerax"
|
||||
deps.camera_camera2 = "androidx.camera:camera-camera2:$versions.camerax"
|
||||
deps.camera_lifecycle = "androidx.camera:camera-lifecycle:$versions.camerax"
|
||||
deps.camera_view = "androidx.camera:camera-view:1.0.0-alpha19"
|
||||
deps.camera_view = "androidx.camera:camera-view:1.0.0-alpha20"
|
||||
|
||||
|
||||
//permission
|
||||
|
||||
Reference in New Issue
Block a user