From 369041d594b794dc1a01e82b3edd67e0f9689df8 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 2 Dec 2024 22:27:11 +0530 Subject: [PATCH 1/4] camera: Restrict all activity recreation --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 525732197..e2b6ec20e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,7 +45,7 @@ Date: Mon, 2 Dec 2024 22:27:23 +0530 Subject: [PATCH 2/4] camera: Rotate camera ui on tablet --- .../java/net/sourceforge/opencamera/DeviceSettings.java | 6 ++++++ app/src/main/java/net/sourceforge/opencamera/ui/MainUI.java | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java b/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java index b76e9fcb3..515d420ae 100644 --- a/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java +++ b/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java @@ -16,6 +16,7 @@ package net.sourceforge.opencamera; +import android.content.Context; import android.os.Build; import java.util.Locale; @@ -42,4 +43,9 @@ public class DeviceSettings { public static boolean isMurenaTwo() { return Build.DEVICE.toLowerCase(Locale.US).contains("two"); } + + public static boolean isTablet(Context context) { + int smallestScreenWidth = context.getResources().getConfiguration().smallestScreenWidthDp; + return smallestScreenWidth >= 600; + } } diff --git a/app/src/main/java/net/sourceforge/opencamera/ui/MainUI.java b/app/src/main/java/net/sourceforge/opencamera/ui/MainUI.java index 21cb642ee..c4ce6b680 100644 --- a/app/src/main/java/net/sourceforge/opencamera/ui/MainUI.java +++ b/app/src/main/java/net/sourceforge/opencamera/ui/MainUI.java @@ -1,5 +1,6 @@ package net.sourceforge.opencamera.ui; +import net.sourceforge.opencamera.DeviceSettings; import net.sourceforge.opencamera.MyApplicationInterface; import net.sourceforge.opencamera.ScaleUtils; import net.sourceforge.opencamera.cameracontroller.CameraController; @@ -221,7 +222,8 @@ public class MainUI { MainActivity.SystemOrientation system_orientation = main_activity.getSystemOrientation(); boolean system_orientation_portrait = system_orientation == MainActivity.SystemOrientation.PORTRAIT; - boolean system_orientation_reversed_landscape = system_orientation == MainActivity.SystemOrientation.REVERSE_LANDSCAPE; + boolean system_orientation_reversed_landscape = !DeviceSettings.isTablet(main_activity) && + system_orientation == MainActivity.SystemOrientation.REVERSE_LANDSCAPE; if( MyDebug.LOG ) { Log.d(TAG, " system_orientation = " + system_orientation); Log.d(TAG, " system_orientation_portrait? " + system_orientation_portrait); -- GitLab From d69beac86969aa6c5ce9a8566228ff2886127129 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 2 Dec 2024 22:27:32 +0530 Subject: [PATCH 3/4] camera: Fix camera id related crash on tablet --- .../net/sourceforge/opencamera/MainActivity.java | 4 ---- .../sourceforge/opencamera/preview/Preview.java | 14 +++++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index a1abbff88..044d3d32c 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -2831,10 +2831,6 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen int best_qrcode_camera = -1; if( MyDebug.LOG ) Log.d(TAG, "getBetterQRCodeCameraID"); - if( !isMultiCamEnabled() ) { - Log.e(TAG, "getBetterQRCodeCameraID switch multi camera icon shouldn't have been visible"); - return best_qrcode_camera; - } if( preview.isOpeningCamera() ) { if( MyDebug.LOG ) Log.d(TAG, "getBetterQRCodeCameraID already opening camera in background thread"); diff --git a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java index 46a383603..bf987fc2a 100644 --- a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +++ b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java @@ -8870,9 +8870,17 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu if (enabled) { this.functionalMode = FunctionalMode.QRCODE; rootLayout.addView(overlayQRCodeView); - int qrcodeCamId = ((MainActivity)getContext()).getBetterQRCodeCameraID(); - if (qrcodeCamId >= 0) { - applicationInterface.setCameraIdPref(qrcodeCamId); + MainActivity mainActivity = (MainActivity) this.getContext(); + int qrcodeCamId = 0; + if (mainActivity.isMultiCamEnabled()) { + int betterQrcodeCamId = mainActivity.getBetterQRCodeCameraID(); + if (qrcodeCamId >= 0) { + qrcodeCamId = betterQrcodeCamId; + } + } + applicationInterface.setCameraIdPref(qrcodeCamId); + if (MyDebug.LOG) { + Log.d(TAG, "Using qrcodeCamId: " + qrcodeCamId); } } else if (overlayQRCodeView.getParent() != null) { rootLayout.removeView(overlayQRCodeView); -- GitLab From 40b9ed0ed1258f66358c518286553c027d6dca6d Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 2 Dec 2024 22:54:38 +0530 Subject: [PATCH 4/4] camera: Keep bottom sheet expanded in landscape --- .../java/net/sourceforge/opencamera/qr/QrImageAnalyzer.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/qr/QrImageAnalyzer.kt b/app/src/main/java/net/sourceforge/opencamera/qr/QrImageAnalyzer.kt index 1d95a9d1d..cdb610ab1 100644 --- a/app/src/main/java/net/sourceforge/opencamera/qr/QrImageAnalyzer.kt +++ b/app/src/main/java/net/sourceforge/opencamera/qr/QrImageAnalyzer.kt @@ -12,7 +12,6 @@ import android.content.ClipData import android.content.ClipDescription import android.content.ClipboardManager import android.content.Intent -import android.content.pm.ActivityInfo import android.graphics.Bitmap import android.graphics.Rect import android.os.Build @@ -32,6 +31,7 @@ import androidx.camera.core.ImageAnalysis import androidx.camera.core.ImageProxy import androidx.cardview.widget.CardView import androidx.core.graphics.drawable.DrawableCompat +import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.button.MaterialButton import com.google.zxing.BarcodeFormat @@ -52,6 +52,7 @@ class QrImageAnalyzer(private val activity: Activity, private val scope: Corouti private val bottomSheetDialog by lazy { BottomSheetDialog(activity).apply { setContentView(R.layout.qr_bottom_sheet_dialog) + behavior.state = BottomSheetBehavior.STATE_EXPANDED } } private val bottomSheetDialogCardView by lazy { @@ -273,11 +274,8 @@ class QrImageAnalyzer(private val activity: Activity, private val scope: Corouti } // Show dialog - activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT bottomSheetDialog.show() - bottomSheetDialog.setOnDismissListener { - activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED - } + isAboutToShow = false } } -- GitLab