-
Notifications
You must be signed in to change notification settings - Fork 17
Sample
In order to run the sample app, you will need to config it to your Firebase account.
See Firebase documentation for help on this.
Note: The Google Services plugin and relevant Firebase SDK's have already been added to the appropriate build.gradle files.
In the sample app we have provided, we have 4 different implementations of the library.
XmlActivity
In XmlActivity we have done a simple implementation, using the xml method. We have handled runtime permissions and are observing barcodes to receive multiple results.
XmlJavaActivity
XmlJavaActivity is identical to XmlActivity except it is written in Java.
ProgrammaticActivity
In ProgrammaticActivity we have implemented BarcodeView programmatically, including setting options.
In ViewfinderFragment we have implemented the library in a more realistic way. We have used a Fragment with a ViewModel as many code bases use these as standard. In the layout fragment_viewfinder.xml we have added the BarcodeView, as expected, but also added an ImageView to act as a viewfinder, ProgressBar and a full screen alpha overlay as a scrim.
In the ViewModel we fake some processing of the barcode, for example sending it to an api. The ViewModel exposes this through a LiveData<Resource<Barcode>>. This allows the ViewModel to communicate state. Whilst there is loading we pause the BarcodeView to stop more results coming in. We then display a Toast to the user once we have a success and resume the BarcodeView.
Also within the sample app we have included an example of using the CameraX library (with MLKit) to implement similar functionality. We wrote this library before CameraX had reached a stable point. Now that it has, we wanted to add this as an example as consumers of this library should be comparing KBarcode against using CameraX with MLKit.
https://developer.android.com/training/camerax
CameraX was built to help you make camera app development easier. It provides a consistent and easy-to-use API surface that works across most Android devices, with backward-compatibility to Android 5.0 (API level 21). While CameraX leverages the capabilities of camera2, it uses a simpler approach that is lifecycle-aware and is based on use cases.
In essence it makes writing against the Camera2 APIs easier. So how does it stack up against KBarcode?
- Implementing KBarcode requires fewer lines of code.
- KBarcode handles all the MLKit integration, whereas you have to do this yourself with CameraX.
- CameraX is written and maintained by Google.
- CameraX is likely to have fewer device specific bugs over time.
- CameraX provides more camera flexibility to consumer.
You will have to make your own mind up as to which you'd like to use. If you do opt for CameraX, we hope our sample implementation is helpful to you.
We are exploring the option of migrating KBarcode to use CameraX under the hood. It could mean KBarcode has to handle less of the complex Camera2 APIs, and can focus on providing the specific barcode scanning use case. However there are a few considerations with this:
- Would KBarcode be providing enough value on top?
- Would it be reducing the complexity for the consumer?
- Is CameraX stable enough yet?
- Would it completely reshape the API surface of KBarcode?
We have not made any decisions on this yet.
Please do raise issues for suggesting improvements to this wiki.