X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;ds=inline;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2FQR.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2FQR.java;h=9735a6fcb9c53efcbec9a3e1ed7b74188a8d1e8f;hb=1aa277a5209ad399fda1a687cf3de0c5192e6ec5;hp=0000000000000000000000000000000000000000;hpb=ac02090e6042d34afc00e2dde45e70f49e2dbedc;p=mobile-ledger-staging.git
diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/QR.java b/app/src/main/java/net/ktnx/mobileledger/ui/QR.java
new file mode 100644
index 00000000..9735a6fc
--- /dev/null
+++ b/app/src/main/java/net/ktnx/mobileledger/ui/QR.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see .
+ */
+
+package net.ktnx.mobileledger.ui;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+
+import androidx.activity.result.ActivityResultCaller;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContract;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+public class QR {
+ private static final String SCAN_APP_NAME = "com.google.zxing.client.android.SCAN";
+ public static ActivityResultLauncher registerLauncher(ActivityResultCaller activity,
+ QRScanResultReceiver resultReceiver) {
+ return activity.registerForActivityResult(new ActivityResultContract() {
+ @NonNull
+ @Override
+ public Intent createIntent(@NonNull Context context, Void input) {
+ final Intent intent = new Intent(SCAN_APP_NAME);
+ intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
+ return intent;
+ }
+ @Override
+ public String parseResult(int resultCode, @Nullable Intent intent) {
+ if (resultCode == Activity.RESULT_CANCELED || intent == null)
+ return null;
+ return intent.getStringExtra("SCAN_RESULT");
+ }
+ }, resultReceiver::onQRScanResult);
+ }
+ public interface QRScanResultReceiver {
+ void onQRScanResult(String scanned);
+ }
+}