dm77 / barcodescanner

Barcode Scanner Libraries for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scan area full screen

Grontag opened this issue · comments

I am using ZXingScannerView in my Activity. Id like to set the scan area to the whole extension of the screen. Is there any way to do it?

Thanks!

<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="@+id/scanview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/backbutton"/>

Hey dude, I was looking for the same and saw your post today. I found the solution to be even more simple than messing with reflection or something similiar.

First disable the drawings in the layout (laser and stuff) then just extend a class fromZXingScanneriew, override getFramingRectInPreview() and return a new Rect using 0,0 as top and left and the width and height parameters the method provides. use that View in you XML and thats it, you can now scan the whole screen (or view size).

public class QRScannerView extends ZXingScannerView {

 public QRScannerView(Context context) {
     super(context);
 }

 public QRScannerView(Context context, AttributeSet attributeSet) {
     super(context, attributeSet);
 }

 @Override
 public synchronized Rect getFramingRectInPreview(int previewWidth, int previewHeight) {
     try {
         return new Rect(0, 0, previewWidth, previewHeight);
     } catch (Exception e) {
         //if something fails, we still can call the super to at least scan in the original small rect.
         return super.getFramingRectInPreview(previewWidth, previewHeight);
     }
 }
}
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.