Because the company is using the scan code library is ZXing, but in the use of some problems found, so we want to analyze the source code, find out the principles and steps of ZXing analysis of two-dimensional code, and then further some optimization of ZXing.

Download the source code

ZXing library is open source, you can download the source code directly from Github, the source address is here, you can clone the source code locally with git command, as shown in the figure

The module describe
core Image decoding library and test code
javase JavaSE client code
android Android client source
android-integration Simplifies integration of IntEnts with Android clients
android-core Configuring an Android Camera
zxingorg Online analysis of TWO-DIMENSIONAL code
zxing.appspot.com Online generation of TWO-DIMENSIONAL code
docs Documentation for the ZXing project

Run the source code

After downloading the source code, the job is to import it into Android Studio to see the effect of the source code. From the downloaded module, the code should be in Android, Android Core and Core module. Here android module Android client source, but to successfully run the source code, but also need to Android, AndroidCore as its dependency library. The specific operation method is as follows

  1. File – > New – > ImportModule willandroidModule imports the project.
  2. File–>New–>NewModule in the pop-up interface selectAndroidLibrary, change the name and clickFinishCan generate aModlueLibraryAnd then, the generatedLibraryDelete files from Java directory, copy files from Java directory under core folder in Zxing, and finally, set this module toandroidModule dependencies.
  3. Import using the same method as in Step 2androidcoreThe module.

Once the above is done, the structure of the project should look like the following figure

There are a few more issues that need to be resolved before the code can run, as follows

  1. willandroidUnder the module ofAndroidManifest.xmlIn the
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="22"/>
Copy the code

This line of code is deleted.

  1. willHistoryItemAdapter.javaThe code in the constructor of
HistoryItemAdapter(Context activity) {
    super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
    this.activity = activity;
  }
Copy the code
  1. willRSSExpandedReader.java
ps = checkRows(new ArrayList<>(), 0);
Copy the code

Modified to

ps = checkRows(new ArrayList<ExpandedRow>(), 0);
Copy the code

By making these changes, projects should run, but on the advantage that they run in landscape, and you can switch to portrait by modifying the following configuration on AndroidManifest. XML.

conclusion

This article mainly describes how to download and run the project, only the project to run, in order to facilitate debugging, through debugging to a good understanding of the principle and the steps of parsing source code. It can be found that there are many functions of the project running now are redundant for us. In the next chapter, we will remove the redundant functions and start to analyze the source code to understand the whole decoding steps.

This article has been published by the public id AndroidShared

Scan the code to pay attention to the public number, reply “get information” have surprise