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:
@@ -160,9 +160,13 @@ android.add_jars = .buildozer/android/platform/*/build/libs_collections/Electrum
|
|||||||
# directory containing the files)
|
# directory containing the files)
|
||||||
android.add_src = electrum/gui/qml/java_classes/
|
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 =
|
android.gradle_dependencies =
|
||||||
com.android.support:support-compat:28.0.0,
|
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
|
android.add_activities = org.electrum.qr.SimpleScannerActivity
|
||||||
|
|
||||||
|
|||||||
@@ -20,17 +20,15 @@ import androidx.core.app.ActivityCompat;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
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
|
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 static final int MY_PERMISSIONS_CAMERA = 1002;
|
||||||
|
|
||||||
private ZXingScannerView mScannerView = null;
|
private BarcodeScannerView mScannerView = null;
|
||||||
final String TAG = "org.electrum.SimpleScannerActivity";
|
final String TAG = "org.electrum.SimpleScannerActivity";
|
||||||
|
|
||||||
private boolean mAlreadyRequestedPermissions = false;
|
private boolean mAlreadyRequestedPermissions = false;
|
||||||
@@ -85,23 +83,23 @@ public class SimpleScannerActivity extends Activity implements ZXingScannerView.
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (null != mScannerView) {
|
if (null != mScannerView) {
|
||||||
mScannerView.stopCamera(); // Stop camera on pause
|
mScannerView.close(); // Stop camera on pause
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCamera() {
|
private void startCamera() {
|
||||||
mScannerView = new ZXingScannerView(this);
|
mScannerView = new BarcodeScannerView(this);
|
||||||
mScannerView.setFormats(Arrays.asList(BarcodeFormat.QR_CODE));
|
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);
|
ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
|
||||||
contentFrame.addView(mScannerView);
|
contentFrame.addView(mScannerView);
|
||||||
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
|
mScannerView.setOnBarcodeListener(result -> {
|
||||||
mScannerView.startCamera(); // Start camera on resume
|
// Handle the scan result
|
||||||
}
|
this.setResultAndClose(result.getText());
|
||||||
|
// Return false to stop scanning after first result
|
||||||
@Override
|
return false;
|
||||||
public void handleResult(Result rawResult) {
|
});
|
||||||
//resultIntent.putExtra("format", rawResult.getBarcodeFormat().toString());
|
mScannerView.openAsync(); // Start camera on resume
|
||||||
this.setResultAndClose(rawResult.getText());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setResultAndClose(String resultText) {
|
private void setResultAndClose(String resultText) {
|
||||||
|
|||||||
Reference in New Issue
Block a user