preface


At present, TWO-DIMENSIONAL code scanning is very common. Zxing secondary development is basically used on the Android platform, but it is difficult to use the original Zxing library. This project is for the convenience of developers to use it quickly.

The purpose of this project is to facilitate developers to use Zxing. The project started in 2015 and was modified according to the source code of Zxing official project, only introducing Zxing Core parsing library.

In 2015, I basically completed the arrangement of all functional modules. I planned to improve the interface call after finishing Camera2, but it was shelved for two years due to work reasons. Recently IT occurred to me that Camera2 was shelved for a while as I took the project out to fix some bugs, improve the interface and encapsulate it into an easy-to-call library.

Quick start


Step 1: Initialization

DecodeRequest request = new DecodeRequest(a);//Select the default type
zxing = new ZxingSupport(this, request);
zxing.setViewfinderView((ViewfinderView) findViewById(R.id.preview_view));//Set the preview
zxing.setTorch((ToggleButton) findViewById(R.id.torch));//Set flash, optionalCopy the code

Step 2: Deal with the lifecycle

@Override
protected void onResume() {
    super.onResume();
    zxing.onResume();
    if (!zxing.isOpen()) {//The camera starts on onResume. Check whether the startup fails
        new OnFailDialog(this).show(); }}@Override
protected void onPause() {
    super.onPause();
    zxing.onPause();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    zxing.onDestroy();
}Copy the code

Step 3: Handle callbacks

@Override
public void onScanReady() {//Initialization completed
    zxing.requestScan();//Start scanning
}

@Override
public void onScanSuccess(ScanResult result) {//The scan is complete
    String scanResult = result.getRawText();//Native data obtained by scanning
}Copy the code

Optional:

BeepManager beep;//Play the beep sound
InactivityTimer timer;//Automatically shut down

//Custom scan overlay
Drawable draw = new ViewfinderView.FrameDrawable() {.}; //FrameDrawable supports custom borders
viewfinderView.setForeground(draw);Copy the code