Skip to content

Customize BarcodeDetector #20

Description

@punksta

What do you think about features:

  • Use com.google.android.gms.vision.barcode.BarcodeDetector as singleton by default instead of creating new instance inside init() function. Do we really need different detectors in different readers?
class BarcodeDetectorHolder {
  private static  BarcodeDetector detector;

  static BarcodeDetector getBarcodeDetector(Context context) {
    if (detector == null)
      detector = new BarcodeDetector.Builder(context.getApplicationContext()).setBarcodeFormats(Barcode.QR_CODE).build();
    return detector;
  }
}

  public QREader(final Builder builder) {
    if (barcodeDetector == null)
      barcodeDetector = BarcodeDetectorHolder.getBarcodeDetector(builder.context);
   ...
   }
  • Allow to set external BarcodeDetector to Builder. It can be useful, if someone will want to scan not only qr codes.
BarcodeDetector myDetector = ...; //set few barcode formats.
QRReader r = QREader.Builder(MainActivity.this, surfaceView, listener).setDetector(myDetector)

I already made it in my project and can make PR. But I'm not sure about first case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions