1
0

android: replace qr code scanning library

Replaces the unmaintained and unreliable
`me.dm7.barcodescanner:zxing:1.9.8` qr code scanning library used only
on android with the `com.github.markusfisch:BarcodeScannerView:1.6.0`
(https://github.com/markusfisch/BarcodeScannerView) library which seems
more actively maintained.
The `BarcodeScannerView` library is incredibly fast and scanning qr
codes is now fun again :)

wip: still looking into ways to pin the library.
This commit is contained in:
f321x
2025-06-24 17:38:03 +02:00
parent 26e6c0900b
commit 0a05674f2f
2 changed files with 19 additions and 17 deletions

View File

@@ -160,9 +160,13 @@ android.add_jars = .buildozer/android/platform/*/build/libs_collections/Electrum
# directory containing the files)
android.add_src = electrum/gui/qml/java_classes/
# (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies}
# e.g. android.gradle_repositories = maven { url "https://repo.spring.io/release" }
android.add_gradle_repositories = maven { url "https://jitpack.io" }
android.gradle_dependencies =
com.android.support:support-compat:28.0.0,
me.dm7.barcodescanner:zxing:1.9.8
com.github.markusfisch:BarcodeScannerView:1.6.0
android.add_activities = org.electrum.qr.SimpleScannerActivity

View File

@@ -20,17 +20,15 @@ import androidx.core.app.ActivityCompat;
import java.util.Arrays;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
import de.markusfisch.android.barcodescannerview.widget.BarcodeScannerView;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
import org.electrum.electrum.res.R; // package set in build.gradle
public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
public class SimpleScannerActivity extends Activity {
private static final int MY_PERMISSIONS_CAMERA = 1002;
private ZXingScannerView mScannerView = null;
private BarcodeScannerView mScannerView = null;
final String TAG = "org.electrum.SimpleScannerActivity";
private boolean mAlreadyRequestedPermissions = false;
@@ -85,23 +83,23 @@ public class SimpleScannerActivity extends Activity implements ZXingScannerView.
public void onPause() {
super.onPause();
if (null != mScannerView) {
mScannerView.stopCamera(); // Stop camera on pause
mScannerView.close(); // Stop camera on pause
}
}
private void startCamera() {
mScannerView = new ZXingScannerView(this);
mScannerView.setFormats(Arrays.asList(BarcodeFormat.QR_CODE));
mScannerView = new BarcodeScannerView(this);
mScannerView.setCropRatio(0.75f); // Set crop ratio to 75% (this defines the square area shown in the scanner view)
// by default only Format.QR_CODE is set
ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
contentFrame.addView(mScannerView);
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
@Override
public void handleResult(Result rawResult) {
//resultIntent.putExtra("format", rawResult.getBarcodeFormat().toString());
this.setResultAndClose(rawResult.getText());
mScannerView.setOnBarcodeListener(result -> {
// Handle the scan result
this.setResultAndClose(result.getText());
// Return false to stop scanning after first result
return false;
});
mScannerView.openAsync(); // Start camera on resume
}
private void setResultAndClose(String resultText) {