From 14413b1c8526b213adbd7637ef264a993751bf14 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 23 Apr 2024 11:56:53 +0530 Subject: [PATCH] Camera: add qr scanner activity --- app/src/main/AndroidManifest.xml | 12 +++++ .../opencamera/preview/Preview.java | 48 ++++++++++--------- .../opencamera/qr/QrScannerActivity.kt | 11 +++++ 3 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/net/sourceforge/opencamera/qr/QrScannerActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75a70dc68..57b47934b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -100,6 +100,18 @@ android:exported="false" > + + + + = 0) { - applicationInterface.setCameraIdPref(qrcodeCamId); - //userSwitchToCamera(qrcodeCamId, true); - } + setQRCode(true); } else if (this.is_qrcode()) { this.functionalMode = FunctionalMode.PHOTO; - final Activity activity = (Activity) Preview.this.getContext(); - final FrameLayout rootLayout = activity.findViewById(android.R.id.content); - if (overlayQRCodeView.getParent() != null) { - rootLayout.removeView(overlayQRCodeView); - } + setQRCode(false); } else if (this.is_photo()) { if (this.isOnTimer()) { cancelTimer(); @@ -8654,6 +8641,21 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu } } + public void setQRCode(boolean enabled) { + final Activity activity = (Activity) Preview.this.getContext(); + final FrameLayout rootLayout = activity.findViewById(android.R.id.content); + if (enabled) { + this.functionalMode = FunctionalMode.QRCODE; + rootLayout.addView(overlayQRCodeView); + int qrcodeCamId = ((MainActivity)getContext()).getBetterQRCodeCameraID(); + if (qrcodeCamId >= 0) { + applicationInterface.setCameraIdPref(qrcodeCamId); + } + } else if (overlayQRCodeView.getParent() != null) { + rootLayout.removeView(overlayQRCodeView); + } + } + public boolean isQRCode() { return functionalMode == FunctionalMode.QRCODE; } diff --git a/app/src/main/java/net/sourceforge/opencamera/qr/QrScannerActivity.kt b/app/src/main/java/net/sourceforge/opencamera/qr/QrScannerActivity.kt new file mode 100644 index 000000000..94a501b74 --- /dev/null +++ b/app/src/main/java/net/sourceforge/opencamera/qr/QrScannerActivity.kt @@ -0,0 +1,11 @@ +package net.sourceforge.opencamera.qr + +import android.os.Bundle +import net.sourceforge.opencamera.MainActivity + +class QrScannerActivity : MainActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + preview.setQRCode(true) + } +} -- GitLab