nisrulz / qreader

:white_square_button: [Android Library] Read QR codes using google's mobile vision api, but without the hassle
http://nisrulz.github.io/qreader
Apache License 2.0
369 stars 108 forks source link

Customize BarcodeDetector #20

Open punksta opened 8 years ago

punksta commented 8 years ago

What do you think about features:

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);
   ...
   }
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.

nisrulz commented 8 years ago

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

punksta commented 8 years ago

@nisrulz added samples;

nisrulz commented 8 years ago

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

punksta commented 8 years ago

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