Files
ZXingLite/zxing-lite/src/main/java/com/king/zxing/BarcodeCameraScanFragment.java
2024-07-16 23:36:33 +08:00

62 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.king.zxing;
import android.view.View;
import com.google.zxing.Result;
import com.king.camera.scan.BaseCameraScanFragment;
import com.king.camera.scan.analyze.Analyzer;
import com.king.view.viewfinderview.ViewfinderView;
import com.king.zxing.analyze.MultiFormatAnalyzer;
import androidx.annotation.Nullable;
/**
* 基于zxing实现的扫码识别 - 相机扫描基类
* <p>
* 通过继承 {@link BarcodeCameraScanActivity}或{@link BarcodeCameraScanFragment}可快速实现扫码识别
*
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
* <p>
* <a href="https://github.com/jenly1314">Follow me</a>
*/
public abstract class BarcodeCameraScanFragment extends BaseCameraScanFragment<Result> {
protected ViewfinderView viewfinderView;
@Override
public void initUI() {
int viewfinderViewId = getViewfinderViewId();
if (viewfinderViewId != View.NO_ID && viewfinderViewId != 0) {
viewfinderView = getRootView().findViewById(viewfinderViewId);
}
super.initUI();
}
@Nullable
@Override
public Analyzer<Result> createAnalyzer() {
return new MultiFormatAnalyzer();
}
/**
* 布局ID通过覆写此方法可以自定义布局
*
* @return 布局ID
*/
@Override
public int getLayoutId() {
return R.layout.zxl_camera_scan;
}
/**
* {@link #viewfinderView} 的 ID
*
* @return 默认返回{@code R.id.viewfinderView}, 如果不需要扫码框可以返回{@link View#NO_ID}
*/
public int getViewfinderViewId() {
return R.id.viewfinderView;
}
}