Skip to content

Commit

Permalink
Removed Google Barcode.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Jan 27, 2025
1 parent 6f29788 commit 827495f
Showing 1 changed file with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import androidx.annotation.NonNull;

import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;
// import com.google.android.gms.vision.Frame;
// import com.google.android.gms.vision.barcode.Barcode;
// import com.google.android.gms.vision.barcode.BarcodeDetector;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.MessagesController;
Expand All @@ -35,7 +35,7 @@

public class QRScanner {

private final AtomicReference<BarcodeDetector> detector = new AtomicReference<>();
// private final AtomicReference<BarcodeDetector> detector = new AtomicReference<>();
private final AtomicBoolean paused = new AtomicBoolean(false);

private final Utilities.Callback<Detected> listener;
Expand All @@ -46,7 +46,7 @@ public QRScanner(Context context, Utilities.Callback<Detected> whenScanned) {
this.listener = whenScanned;
this.prefix = MessagesController.getInstance(UserConfig.selectedAccount).linkPrefix;
Utilities.globalQueue.postRunnable(() -> {
detector.set(new BarcodeDetector.Builder(context).setBarcodeFormats(Barcode.QR_CODE).build());
// detector.set(new BarcodeDetector.Builder(context).setBarcodeFormats(Barcode.QR_CODE).build());
attach(cameraView);
});
}
Expand All @@ -64,12 +64,13 @@ public void destroy() {

public void attach(CameraView cameraView) {
this.cameraView = cameraView;
if (detector.get() == null) return;
if (true) return;
// if (detector.get() == null) return;

if (!paused.get()) {
Utilities.globalQueue.cancelRunnable(this.process);
Utilities.globalQueue.postRunnable(this.process, getTimeout());
}
// if (!paused.get()) {
// Utilities.globalQueue.cancelRunnable(this.process);
// Utilities.globalQueue.postRunnable(this.process, getTimeout());
// }
}

public void setPaused(boolean pause) {
Expand All @@ -93,7 +94,8 @@ public boolean isPaused() {

private Bitmap cacheBitmap;
private final Runnable process = () -> {
if (detector.get() == null || cameraView == null || paused.get()) {
if (true) {
// if (detector.get() == null || cameraView == null || paused.get()) {
return;
}

Expand Down Expand Up @@ -131,30 +133,31 @@ private Detected detect(Bitmap bitmap) {
return null;
}

final BarcodeDetector detector = this.detector.get();
if (detector == null || !detector.isOperational()) {
// final BarcodeDetector detector = this.detector.get();
// if (detector == null || !detector.isOperational()) {
if (true) {
return null;
}

final int w = bitmap.getWidth();
final int h = bitmap.getHeight();
final Frame frame = new Frame.Builder().setBitmap(bitmap).build();
final SparseArray<Barcode> codes = detector.detect(frame);

for (int i = 0; i < codes.size(); ++i) {
final Barcode code = codes.valueAt(i);
String link = code.rawValue;
if (link == null) continue;
link = link.trim();
if (!link.startsWith(prefix) && !link.startsWith("https://" + prefix) && !link.startsWith("http://" + prefix)) continue;

final PointF[] cornerPoints = new PointF[code.cornerPoints.length];
for (int j = 0; j < code.cornerPoints.length; ++j) {
cornerPoints[j] = new PointF((float) code.cornerPoints[j].x / w, (float) code.cornerPoints[j].y / h);
}
// final Frame frame = new Frame.Builder().setBitmap(bitmap).build();
// final SparseArray<Barcode> codes = detector.detect(frame);

return new Detected(link, cornerPoints);
}
// for (int i = 0; i < codes.size(); ++i) {
// final Barcode code = codes.valueAt(i);
// String link = code.rawValue;
// if (link == null) continue;
// link = link.trim();
// if (!link.startsWith(prefix) && !link.startsWith("https://" + prefix) && !link.startsWith("http://" + prefix)) continue;

// final PointF[] cornerPoints = new PointF[code.cornerPoints.length];
// for (int j = 0; j < code.cornerPoints.length; ++j) {
// cornerPoints[j] = new PointF((float) code.cornerPoints[j].x / w, (float) code.cornerPoints[j].y / h);
// }

// return new Detected(link, cornerPoints);
// }

return null;
}
Expand All @@ -179,10 +182,10 @@ public long getTimeout() {
}

public void detach() {
BarcodeDetector detector = this.detector.getAndSet(null);
if (detector != null) {
detector.release();
}
// BarcodeDetector detector = this.detector.getAndSet(null);
// if (detector != null) {
// detector.release();
// }
}

public static final class Detected {
Expand Down

0 comments on commit 827495f

Please sign in to comment.