Giter Club home page Giter Club logo

barcode-kaiteki's Introduction

Release Build Status

Barcode-Kaiteki

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)
  • BarcodeFragment (Fragment)

โ€ƒโ€ƒ

Features

  • camera permission handling
  • customize the displayed result points
  • customize the barcode type (can be a list)
  • allows scanning of inverted barcodes (white barcode on black background)

Add library dependency

Add jitpack to your toplevel gradle file (if not already present):

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add barcode-kaiteki as dependency:

dependencies {
    implementation 'com.kroegerama:barcode-kaiteki:<version>'
}

Usage

BarcodeDialog

Just let your Activity/Fragment implement BarcodeResultListener.

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.

//show a Barcode FragmentDialog (with swipe to dismiss)
BarcodeDialog.show(
    childFragmentManager,
    formats = listOf(BarcodeFormat.QR_CODE),
    barcodeInverted = false
)

//show a Barcode BottomSheet
BarcodeBottomSheet.show(
    childFragmentManager,
    formats = listOf(BarcodeFormat.QR_CODE),
    barcodeInverted = false
)

//show an AlertDialog from activity
showBarcodeAlertDialog(
    owner = this,
    listener = this,
    formats = listOf(BarcodeFormat.QR_CODE),
    barcodeInverted = false
)
//or from a Fragment
requireContext().showBarcodeAlertDialog(
    owner = this,
    listener = this,
    formats = listOf(BarcodeFormat.QR_CODE),
    barcodeInverted = false
)

//show a Barcode Fragment
val barcodeFragment = BarcodeFragment.makeInstance(
    formats = listOf(BarcodeFormat.QR_CODE),
    barcodeInverted = false
)
supportFragmentManager.beginTransaction()
    .replace(R.id.container, barcodeFragment)
    .commit()
BarcodeView

You can also use the BarcodeView directly in your Layout.

<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().

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()
}

barcode-kaiteki's People

Contributors

kroegerama avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.