-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d668429
commit c2d49b7
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
[![Release](https://jitpack.io/v/kroegerama/barcode-kaiteki.svg)](https://jitpack.io/#com.kroegerama/barcode-kaiteki) | ||
[![Build Status](https://travis-ci.org/kroegerama/barcode-kaiteki.svg?branch=master)](https://travis-ci.org/kroegerama/barcode-kaiteki) | ||
|
||
## Barcode-Kaiteki | ||
|
||
<img width="200" src="art/qr-code.png"> | ||
|
||
An easy to use library for barcode detection. Based on the new **AndroidX** **Camera2** api. Uses the **zxing** barcode detection library. | ||
|
||
Comes with a **BarcodeView**, which combines a camera preview and an automatic overlay for detected barcodes. | ||
|
||
#### Also contains three differend ready to use dialogs: | ||
|
||
* **BarcodeDialog** *(DialogFragment)* | ||
* **BarcodeBottomSheet** *(BottomSheetDialogFragment)* | ||
* **BarcodeAlertDialog** *(AlertDialog)* | ||
|
||
<img width="200" src="art/screen-dialogfragment.png"> <img width="200" src="art/screen-bottomsheet.png"> <img width="200" src="art/screen-alertdialog.png"> | ||
|
||
#### Features | ||
|
||
* camera permission handling | ||
* customize the displayed result points | ||
* customize the barcode type (can be a list) | ||
|
||
#### Add library dependency | ||
|
||
Add jitpack to your toplevel gradle file (if not already present): | ||
|
||
```gradle | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
|
||
Add barcode-kaiteki as dependency: | ||
|
||
```gradle | ||
dependencies { | ||
implementation 'com.kroegerama:barcode-kaiteki:<version>' | ||
} | ||
``` | ||
|
||
#### Usage | ||
|
||
##### BarcodeDialog | ||
|
||
Just let your Activity/Fragment implement **BarcodeResultListener**. | ||
|
||
```kotlin | ||
class MainActivity : AppCompatActivity(), BarcodeResultListener { | ||
|
||
//... | ||
|
||
override fun onBarcodeResult(result: Result): Boolean { | ||
Log.d(TAG, "Result: $result") | ||
|
||
//return false to not automatically close the dialog | ||
return false | ||
} | ||
} | ||
|
||
``` | ||
|
||
Then it is as easy as showing one of the provided dialogs. | ||
|
||
```kotlin | ||
//show a Barcode FragmentDialog (with swipe to dismiss) | ||
BarcodeDialog.show(supportFragmentManager, listOf(BarcodeFormat.QR_CODE)) | ||
|
||
//show a Barcode BottomSheet | ||
BarcodeBottomSheet.show(supportFragmentManager, listOf(BarcodeFormat.QR_CODE)) | ||
|
||
//or show an AlertDialog | ||
showBarcodeAlertDialog(this, this, listOf(BarcodeFormat.QR_CODE)) | ||
``` | ||
|
||
##### BarcodeView | ||
|
||
You can also use the **BarcodeView** directly in your Layout. | ||
|
||
```xml | ||
<com.kroegerama.kaiteki.bcode.views.BarcodeView | ||
android:id="@+id/bcode" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:resultPointColor="#09E85E" | ||
app:resultPointSize="8dp" | ||
app:showResultPoints="true" /> | ||
``` | ||
|
||
Then add in your *onCreate/onViewCreated*: ```bcode.bindToLifecycle(this)``` and in your *onStop*: ```bcode.unbind()```. | ||
|
||
```kotlin | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
bcode.setFormats(listOf(BarcodeFormat.QR_CODE, BarcodeFormat.AZTEC)) | ||
bcode.setBarcodeResultListener(this) | ||
bcode.bindToLifecycle(this) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
bcode.unbind() | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.