Skip to content

Commit 81dfc95

Browse files
committed
Attempted to remove Google Barcode.
1 parent 50122ce commit 81dfc95

1 file changed

Lines changed: 36 additions & 33 deletions

File tree

  • TMessagesProj/src/main/java/org/telegram/ui/Stories/recorder

TMessagesProj/src/main/java/org/telegram/ui/Stories/recorder/QRScanner.java

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import androidx.annotation.NonNull;
1919

20-
import com.google.android.gms.vision.Frame;
21-
import com.google.android.gms.vision.barcode.Barcode;
22-
import com.google.android.gms.vision.barcode.BarcodeDetector;
20+
// import com.google.android.gms.vision.Frame;
21+
// import com.google.android.gms.vision.barcode.Barcode;
22+
// import com.google.android.gms.vision.barcode.BarcodeDetector;
2323

2424
import org.telegram.messenger.AndroidUtilities;
2525
import org.telegram.messenger.MessagesController;
@@ -35,7 +35,7 @@
3535

3636
public class QRScanner {
3737

38-
private final AtomicReference<BarcodeDetector> detector = new AtomicReference<>();
38+
// private final AtomicReference<BarcodeDetector> detector = new AtomicReference<>();
3939
private final AtomicBoolean paused = new AtomicBoolean(false);
4040

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

6565
public void attach(CameraView cameraView) {
6666
this.cameraView = cameraView;
67-
if (detector.get() == null) return;
67+
if (true) return;
68+
// if (detector.get() == null) return;
6869

69-
if (!paused.get()) {
70-
Utilities.globalQueue.cancelRunnable(this.process);
71-
Utilities.globalQueue.postRunnable(this.process, getTimeout());
72-
}
70+
// if (!paused.get()) {
71+
// Utilities.globalQueue.cancelRunnable(this.process);
72+
// Utilities.globalQueue.postRunnable(this.process, getTimeout());
73+
// }
7374
}
7475

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

9495
private Bitmap cacheBitmap;
9596
private final Runnable process = () -> {
96-
if (detector.get() == null || cameraView == null || paused.get()) {
97+
if (true) {
98+
// if (detector.get() == null || cameraView == null || paused.get()) {
9799
return;
98100
}
99101

@@ -131,30 +133,31 @@ private Detected detect(Bitmap bitmap) {
131133
return null;
132134
}
133135

134-
final BarcodeDetector detector = this.detector.get();
135-
if (detector == null || !detector.isOperational()) {
136+
// final BarcodeDetector detector = this.detector.get();
137+
// if (detector == null || !detector.isOperational()) {
138+
if (true) {
136139
return null;
137140
}
138141

139142
final int w = bitmap.getWidth();
140143
final int h = bitmap.getHeight();
141-
final Frame frame = new Frame.Builder().setBitmap(bitmap).build();
142-
final SparseArray<Barcode> codes = detector.detect(frame);
143-
144-
for (int i = 0; i < codes.size(); ++i) {
145-
final Barcode code = codes.valueAt(i);
146-
String link = code.rawValue;
147-
if (link == null) continue;
148-
link = link.trim();
149-
if (!link.startsWith(prefix) && !link.startsWith("https://" + prefix) && !link.startsWith("http://" + prefix)) continue;
150-
151-
final PointF[] cornerPoints = new PointF[code.cornerPoints.length];
152-
for (int j = 0; j < code.cornerPoints.length; ++j) {
153-
cornerPoints[j] = new PointF((float) code.cornerPoints[j].x / w, (float) code.cornerPoints[j].y / h);
154-
}
144+
// final Frame frame = new Frame.Builder().setBitmap(bitmap).build();
145+
// final SparseArray<Barcode> codes = detector.detect(frame);
155146

156-
return new Detected(link, cornerPoints);
157-
}
147+
// for (int i = 0; i < codes.size(); ++i) {
148+
// final Barcode code = codes.valueAt(i);
149+
// String link = code.rawValue;
150+
// if (link == null) continue;
151+
// link = link.trim();
152+
// if (!link.startsWith(prefix) && !link.startsWith("https://" + prefix) && !link.startsWith("http://" + prefix)) continue;
153+
154+
// final PointF[] cornerPoints = new PointF[code.cornerPoints.length];
155+
// for (int j = 0; j < code.cornerPoints.length; ++j) {
156+
// cornerPoints[j] = new PointF((float) code.cornerPoints[j].x / w, (float) code.cornerPoints[j].y / h);
157+
// }
158+
159+
// return new Detected(link, cornerPoints);
160+
// }
158161

159162
return null;
160163
}
@@ -179,10 +182,10 @@ public long getTimeout() {
179182
}
180183

181184
public void detach() {
182-
BarcodeDetector detector = this.detector.getAndSet(null);
183-
if (detector != null) {
184-
detector.release();
185-
}
185+
// BarcodeDetector detector = this.detector.getAndSet(null);
186+
// if (detector != null) {
187+
// detector.release();
188+
// }
186189
}
187190

188191
public static final class Detected {

0 commit comments

Comments
 (0)