qreader icon indicating copy to clipboard operation
qreader copied to clipboard

Customize BarcodeDetector

Open punksta opened this issue 7 years ago • 4 comments

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.

punksta avatar Jul 16 '16 19:07 punksta

@punksta I donot fully understand what you are proposing here. Can you provide me with more details.

nisrulz avatar Jul 17 '16 09:07 nisrulz

@nisrulz added samples;

punksta avatar Jul 18 '16 07:07 punksta

@punksta I think using Singleton would be a nice change as cases of having multiple instances of the same QREader class are very less.

However I would not want to extend QREader to start supporting other reading capability just because I made it specifically to read QRCodes. However there is no harm in providing a config function that open ups the functionality if its desired. The way of implementation should be in such a way that it does not alienate the api to deviate from its core cause of reading QRCodes.

Would love to hear your thoughts on this too.

nisrulz avatar Jul 18 '16 09:07 nisrulz

@nisrulz I agree. Where is another case of supporting external BarcodeDetector: using one instance for scanning of locally images and using in your reader.

punksta avatar Jul 18 '16 09:07 punksta