Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding reding area limit #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2016 Nishant Srivastava
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package github.nisrulz.qreader;

import com.google.android.gms.vision.barcode.Barcode;

/**
*The interface to get the Barcode
*/
public interface QRBarcodeListener {

/**
* On detected.
*
* @param data
* the barcode object
*/
//Changed the data from String to Barcode object
public void onDetected(Barcode data);


}
55 changes: 45 additions & 10 deletions qreader/src/main/java/github/nisrulz/qreader/QRDataListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,52 @@

package github.nisrulz.qreader;

import android.graphics.Rect;

import com.google.android.gms.vision.barcode.Barcode;

/**
* The interface Qr data listener.
*/
public interface QRDataListener {

/**
* On detected.
*
* @param data
* the data
*/
// Called from not main thread. Be careful
void onDetected(final String data);
public abstract class QRDataListener implements QRBarcodeListener {

//Added Rect to limit the reading area
private Rect readingArea;
//Added Rect that allows to get the read data area
private Rect readData;

/**
* On detected.
*
* @param data
* the data
*/
// Called from not main thread. Be careful
public abstract void onDetected(final String data);

@Override
public void onDetected(Barcode data) {
readData = data.getBoundingBox();
if(readingArea == null) {
onDetected(data.displayValue);
}
else {
if(readingArea.contains(readData)) {
onDetected(data.displayValue);
}
}


}

//readData is readOnly
public Rect getReadData() {
return readData;
}

//readingData is set only

public void setReadingArea(Rect readingArea) {
this.readingArea = readingArea;
}
}
12 changes: 8 additions & 4 deletions qreader/src/main/java/github/nisrulz/qreader/QREader.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class QREader {
private final int width;
private final int height;
private final int facing;
private final QRDataListener qrDataListener;
//Changed the qrDataListener from QRDataListenr to QrBarcodeListener
private final QRBarcodeListener qrDataListener;
private final Context context;
private final SurfaceView surfaceView;
private boolean autoFocusEnabled;
Expand Down Expand Up @@ -173,7 +174,8 @@ public void release() {
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() != 0 && qrDataListener != null) {
qrDataListener.onDetected(barcodes.valueAt(0).displayValue);
//Instead of just sending the string, the complete Barcode object is sent
qrDataListener.onDetected(barcodes.valueAt(0));
}
}
});
Expand Down Expand Up @@ -274,7 +276,8 @@ public static class Builder {
private int width;
private int height;
private int facing;
private final QRDataListener qrDataListener;
//Changed the qrDataListener from QRDataListenr to QrBarcodeListener
private final QRBarcodeListener qrDataListener;
private final Context context;
private final SurfaceView surfaceView;
private BarcodeDetector barcodeDetector;
Expand All @@ -289,7 +292,8 @@ public static class Builder {
* @param qrDataListener
* the qr data listener
*/
public Builder(Context context, SurfaceView surfaceView, QRDataListener qrDataListener) {
//Changed the qrDataListener from QRDataListenr to QrBarcodeListener
public Builder(Context context, SurfaceView surfaceView, QRBarcodeListener qrDataListener) {
this.autofocusEnabled = true;
this.width = 800;
this.height = 800;
Expand Down