- This repo has been deprecated *
This library provides Android wrappers for the Zebra Crossing (zxing) Library. If you only need to scan barcodes and are only distributing on Google Play enabled devices, check out the new Google Mobile Vision libraries. The scanning component works fine, but was more or less included because it had already been built for other purposes.
- BarcodeDemo - Project that demonstrates usage of barcode scanning and generation.
- Generation
- BarcodeView - Extends ImageView and will attempt to fill itself with the barcode type specified
- Required Custom Attributes:
- barcode_format - Enumeration of supported barcode formats e.g. "qr_code". Must be either specified in layout or provided via setBarcodeFormat method on the view instance.
- barcode_text - Value to be encoded. Must be either specified in layout or provided via setBarcodeText.
- Optional Custom Attributes
- barcode_character_set - If unspecified will default to "UTF-8".
- barcode_foreground_color - Android color value for the "black" part of the barcode.
- barcode_background_color - Android color value for the "white" part of the barcode.
- Required Custom Attributes:
- BarcodeRequest - Create an object that specifies a desired barcode image size/format/text/etc created with the BarcodeRequestBuilder inside it.
- BarcodeBitmapGenerator - Create a barcode bitmap synchronously from a BarcodeRequest
- AsyncBarcodeBitmapGenerator - Create a barcode bitmap asynchronously with a weak reference to the callback.
- Constructor can be set to either single operation mode or multiple operation mode. In single operation mode any currently running request will be cancelled before the next is started.
- BarcodeView - Extends ImageView and will attempt to fill itself with the barcode type specified
- Detection
- ZXingFacade - Provides an easier to manage interface to ZXing's camera based barcode scanning operations. Check out the BarcodeDemo ScanningActivity. You provide it with a SurfaceView for the preview, a callback listener for detected barcodes and pass it onCreate/Pause/Resume Activity lifecycle events.
Include the library in your project with the compile directive in your dependencies section of your build.gradle.
...
dependencies {
...
compile ('com.bottlerocketstudios:barcode:1.0.3@aar') {
transitive = true;
}
}
Add the app XML namespace to the root element of your layout.
xmlns:app="http://schemas.android.com/apk/res-auto"
Now add the BarcodeView somewhere in your layout.
<com.bottlerocketstudios.barcode.generation.ui.BarcodeView
android:id="@+id/generation_barcode_image"
app:barcode_format="qr_code"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="20dp"/>
The layout width and height cannot be wrap_content as that doesn't have a real meaning for a barcode. There is no intrinsic size of most barcodes and the ImageView's bitmap has not been set to be measured until the barcode is created.
The BarcodeDemo project's ScanningActivity is the best source for an example implementation. Clone this repo or browse the source to look at that Activity. Be sure to pay attention to the manifest permissions.
This project must be built with gradle.
- Version Numbering - The version name should end with "-SNAPSHOT" for non release builds. This will cause the resulting binary, source, and javadoc files to be uploaded to the snapshot repository in Maven as a snapshot build. Removing snapshot from the version name will publish the build on jcenter. If that version is already published, it will not overwrite it.
- Execution - To build this libarary, associated tasks are dynamically generated by Android build tools in conjunction with Gradle. Example command for the production flavor of the release build type:
- Build and upload:
./gradlew --refresh-dependencies clean lint uploadToMaven
- Build only:
./gradlew --refresh-dependencies clean lint assembleRelease
- Build and upload: