Giter Club home page Giter Club logo

qrather_base's Introduction

QRather_base

Pixel True Mockup high

https://youtu.be/7GtfUSF7Mgg

Note: At Google I/O 2022 the Google code scanner was announced. You should consider using it instead of qrather. If you want to support devices without Play Services or like to ship the latest ML Kit model - use qrather.

Quick Start

View-based

To use the QR scanner simply register the ScanQRCode() ActivityResultContract together with a callback during init or onCreate() lifecycle of your Activity/Fragment and use the returned ActivityResultLauncher to launch the QR scanner Activity.

val scanQrCodeLauncher = registerForActivityResult(ScanQRCode()) { result ->
    // handle QRResult
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    โ€ฆ
    binding.button.setOnClickListener { scanQrCodeLauncher.launch(null) }
}

Check out the sample inside this repo or visit the official Activity Result API documentation for more information.

Jetpack Compose

Use the rememberLauncherForActivityResult() API to register the ScanQRCode() ActivityResultContract together with a callback in your composable:

@Composable
fun GetQRCodeExample() {
    val scanQrCodeLauncher = rememberLauncherForActivityResult(ScanQRCode()) { result ->
        // handle QRResult
    }
    
    Button(onClick = { scanQrCodeLauncher.launch(null) }) {
    โ€ฆ
}

Check out the official Compose Activity Result documentation for more information.

Responses

The activity result is a subclass of the sealed QRResult class:

  1. QRSuccess when ML Kit successfully detected a QR code
    • wraps a QRContent object
  2. QRUserCanceled when the Activity got canceled by the user
  3. QRMissingPermission when the user didn't accept the camera permission
  4. QRError when CameraX or ML Kit threw an exception
    • wraps the exception

Content

The content type of the QR code detected by ML Kit is wrapped inside a subclass of the sealed QRContent class which always provides a rawValue.

Currently, supported subtypes are: Plain, Wifi, Url, Sms, GeoPoint, Email, Phone, ContactInfo, CalendarEvent

See the ML Kit Barcode documentation for further details.

Customization

Use the ScanCustomCode() ActivityResultContract to create a configurable barcode scan. When launching the ActivityResultLauncher pass in a ScannerConfig object:

BarcodeFormat options
BarcodeFormat.FORMAT_ALL_FORMATS
BarcodeFormat.FORMAT_CODE_128
BarcodeFormat.FORMAT_CODE_39
BarcodeFormat.FORMAT_CODE_93
BarcodeFormat.FORMAT_CODABAR
BarcodeFormat.FORMAT_DATA_MATRIX
BarcodeFormat.FORMAT_EAN_13
BarcodeFormat.FORMAT_EAN_8
BarcodeFormat.FORMAT_ITF
BarcodeFormat.FORMAT_QR_CODE
BarcodeFormat.FORMAT_UPC_A
BarcodeFormat.FORMAT_UPC_E
BarcodeFormat.FORMAT_PDF417
BarcodeFormat.FORMAT_AZTEC
val scanCustomCode = registerForActivityResult(ScanCustomCode(), ::handleResult)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    โ€ฆ
    binding.button.setOnClickListener {
      scanCustomCode.launch(
        ScannerConfig.build {
          setBarcodeFormats(listOf(BarcodeFormat.FORMAT_CODE_128)) // set interested barcode formats
          setOverlayStringRes(R.string.scan_barcode) // string resource used for the scanner overlay
          setOverlayDrawableRes(R.drawable.ic_scan_barcode) // drawable resource used for the scanner overlay
          setHapticSuccessFeedback(false) // enable (default) or disable haptic feedback when a barcode was detected
          setShowTorchToggle(true) // show or hide (default) torch/flashlight toggle button
          setHorizontalFrameRatio(2.2f) // set the horizontal overlay ratio (default is 1 / square frame)
          setUseFrontCamera(true) // use the front camera
        }
      )
    }
}

fun handleResult(result: QRResult) {
    โ€ฆ

๐Ÿ’ก You can optionally pass in an ActivityOptionsCompat object when launching the ActivityResultLauncher to control the scanner launch animation.

Screenshots / Sample App

image

Libraries Used

. BarCodeScanner

. Room Database

. Google Material Design

. Stetho

qrather_base's People

Contributors

th3kumar avatar

Stargazers

 avatar  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.