GithubHelp home page GithubHelp logo

eaglescan's Introduction

Logo

EagleScan

EagleScan is Barcode scanning library that was born from our internal needs. It uses Firebase ML Kit internally to read barcode/QR codes. For list of supported formats look here.

Note: It bundles Firebase's Bundled ML Kit library that statically links ML model to the app at build time. Because of this, your app's size may grow by 2.4 MB. Supporting unbundled capability is not the priority right now. You may want to use Google's code-scanner If you want to go unbundled.

Screenshot

Recording.mp4

Instructions

Installation:

implementation('com.tarkalabs:eagle-scan:1.0.0')

Code Sample:

Library provides two way of integrations.

  1. BarcodeScannerActivity: This is the simplest way to integrate, Just register for activity result and launch the scanner Activity
  2. BarcodeScannerFragment: Use this fragment when using BarcodeScannerActivity is not possible due to any UI design constraints.

Using BarcodeScannerActivity:

val scanResultReceiver = registerForActivityResult(ScanBarcodeContract()) { result->
  handleBarcodeResult(result)
}

override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
  findViewById<Button>(R.id.btn_scan_activity).setOnClickListener {
    scanResultReceiver.launch(null)
  }
}

Using BarcodeScannerFragment:

class MainActivity : AppCompatActivity(), ScanResultListener {
  
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
  
    supportFragmentManager.commit {
      add(R.id.scanner_fragment_container, BarcodeScannerFragment.newInstance())
    }
  }
  
  override fun onScanResult(result: BarcodeResult) {
    handleBarcodeResult(result)
  }

BarcodeResult is a sealed class that represents Barcode scanning result. example:

fun handleBarcodeResult(result: BarcodeResult) {  
  when (result) {  
    is Error -> {
      // Error occured while scanning.
      result.exception.printStackTrace()
    }
    is Success -> {
      //Bacode scanned successfully.
      val barcode: BarcodeData = result.data
    }
    MissingPermission -> {
      // Camera scanning permission not availble.
      // Library asks for Camera permission, but if user denys it, It sends this Result.
    }
    UserCanceled -> {
      // Only BarcodeScannerActivity sends this result.
      // User cancelled barcode scanning by pressing back button in Barcode Scanner screen.
    }
  }  
}

BarcodeResult.Success exposes BarcodeData that contains actual barcode data. List of exposed Barcode types:

  • Plain
  • Isbn
  • WiFi
  • Url
  • Sms
  • GeoPoint
  • ContactInfo
  • Email
  • DriverLicense
  • CalendarEvent

Configuration: BarcodeScannerConfig lets to specify barcode format to be enabled and also lets you control visibility of flash button.

val scannerConfig = BarcodeScannerConfig.Builder()
  .barcodeFormats(Barcode.FORMAT_ALL_FORMATS)
  .showFlashButton(true)
  .build()

Check out the example inside this repo for complete integration steps.

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.