Coder Social home page Coder Social logo

shubh261096 / camerax Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 165 KB

This Sample uses my custom camerax library where BarCode Analyzer and ImageCapture is used

Kotlin 100.00%
camerax android zxing-qrcode imagecapture kotlin barcode-analyzer camera camerax-library zbar firebase-mlkit

camerax's Introduction

CameraX Library

This Sample uses my custom camerax library where BarCode Analyzer and ImageCapture is used. This project will directly run the application.

Feature Update

Now you can use QRCode/Barcode Scanning via four of the libraries added. You just have to uncomment lines in my library.

  1. ZXing
  2. ZBar
  3. Firebase MLKit Vision
  4. Google Vision

Usage

If someone wants to use my camerax library. Follow these steps given below:

  1. Add camerax as a library in your project to use it as a library.

  2. To use Barcode Scanning:

    a. Add these lines in your activity.xml file

    <com.pb.camerax.BarCodeReaderView
          android:id="@+id/barCodeView"
          android:layout_width="500dp"
          android:layout_height="500dp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" />
    

    b. For using in you activity or fragment:

    i. Initialize the barCodeReaderListener in onCreate()

    barCodeView.barCodeReaderListener = barCodeReaderListener
    

    ii. Init the camera in onCreate

    barCodeView.initCamera(this,null,this,BarCodeCameraConfiguration("FRONT"))
    

    iii. Override the onRequestPermissionsResult method

    override fun onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String?>,grantResults: IntArray) {
          barCodeView.onRequestPermissionsResult(this, permissions, grantResults, requestCode)
    }
    

    iv. Implement the barCodeReaderListener

    private var barCodeReaderListener: BarCodeReaderListener = object : BarCodeReaderListener {
          override fun onSuccess(qrCode: String, status: BarCodeStatus) {
              Toast.makeText(this@BarCodeScannerActivity,"Code : $qrCode",Toast.LENGTH_SHORT).show()
          }
    
          override fun onFailure(status: BarCodeStatus) {
              Log.i(TAG, status.name)
          }
    
          override fun onInitFailure(isAlwaysDenied: Boolean) {
              Toast.makeText(this@BarCodeScannerActivity,"Permission denied always : $isAlwaysDenied",Toast.LENGTH_SHORT).show()
              Log.i(TAG, "$isAlwaysDenied")
          }
    }
    
  3. To implement Image Capture:

    a. Add these lines in your activity.xml file

    <com.pb.camerax.ImageCaptureView
          android:id="@+id/barCodeView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" />
    

    b. For using in you activity or fragment:

    i. Initialize the imageCaptureListener in onCreate()

    imageCaptureView.imageCaptureListener = imageCaptureListener
    

    ii. Init the camera in onCreate

    imageCaptureView.initCamera(this,null,this,BarCodeCameraConfiguration("FRONT")) // USE "BACK for Back Camera"
    

    iii. Override the onRequestPermissionsResult method

    override fun onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String?>,grantResults: IntArray) {
          imageCaptureView.onRequestPermissionsResult(this, permissions, grantResults, requestCode)
    }
    

    iv. Implement the imageCaptureListener

    private var imageCaptureListener: ImageCaptureListener = object : ImageCaptureListener {
    
      override fun onCaptureSuccess(path: String, imageCodeStatus: ImageCodeStatus) {
          Log.i(TAG, path)
      }
    
      override fun onInitFailure(isAlwaysDenied: Boolean, imageCodeStatus: ImageCodeStatus) {
          Log.i(TAG, imageCodeStatus.name)
      }
    
      override fun onInitSuccess(imageCodeStatus: ImageCodeStatus) {
          /** This method #captureImage is called after successful initialization. You can use this method on click of a button */
          Handler().postDelayed({
              imageCaptureView.captureImage(this@ImageCaptureActivity)
          }, 5000)
      }
    
      override fun onCaptureFailure(error: String, imageCodeStatus: ImageCodeStatus) {
          Log.i(TAG, error)
      }
    }
    

camerax's People

Contributors

shubh261096 avatar

Stargazers

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