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.
The project contains the following two modules:
App: This Module is a demo, see DemoActivity can achieve rapid development.
Zxing: This Module is the source of the Zxing Support 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
Licensed under the Apache License, Version 2.0 (the "License") Copyright 2017 Yeamy. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copy the code