|
|
@ -111,17 +111,14 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() { |
|
|
|
private fun bindCameraUseCases() { |
|
|
|
|
|
|
|
// Get screen metrics used to setup camera for full screen resolution |
|
|
|
/* |
|
|
|
val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity()).bounds |
|
|
|
Log.d("SilentDragon", "Screen metrics: ${metrics.width()} x ${metrics.height()}") |
|
|
|
val screenAspectRatio = aspectRatio(metrics.width(), metrics.height()) |
|
|
|
*/ |
|
|
|
val windowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity()) |
|
|
|
Log.d(TAG, "Screen metrics: ${windowMetrics.bounds.width()} x ${windowMetrics.bounds.height()}") |
|
|
|
|
|
|
|
// Hardcode to square for now otherwise scanning doesn't work |
|
|
|
val screenAspectRatio = aspectRatio(1, 1) |
|
|
|
Log.d("SilentDragon", "Preview aspect ratio: $screenAspectRatio") |
|
|
|
val screenAspectRatio = aspectRatio(windowMetrics.bounds.width(), windowMetrics.bounds.height()) |
|
|
|
Log.d(TAG, "Preview aspect ratio: $screenAspectRatio") |
|
|
|
|
|
|
|
val rotation = fragmentCameraBinding.viewFinder.display.rotation |
|
|
|
Log.d(TAG, "Rotation: $rotation") |
|
|
|
|
|
|
|
// CameraProvider |
|
|
|
val cameraProvider = cameraProvider |
|
|
@ -298,7 +295,8 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() { |
|
|
|
* @return suitable aspect ratio |
|
|
|
*/ |
|
|
|
private fun aspectRatio(width: Int, height: Int): Int { |
|
|
|
val previewRatio = max(width, height).toDouble() / min(width, height) |
|
|
|
val previewRatio = width.toDouble() / height |
|
|
|
Log.d(TAG, "previewRatio: $previewRatio") |
|
|
|
if (abs(previewRatio - RATIO_4_3_VALUE) <= abs(previewRatio - RATIO_16_9_VALUE)) { |
|
|
|
return AspectRatio.RATIO_4_3 |
|
|
|
} |
|
|
@ -323,7 +321,6 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() { |
|
|
|
} |
|
|
|
|
|
|
|
private fun onQrScanned(qrContent: String, image: ImageProxy) { |
|
|
|
//Log.d("SilentDragon", "QR scanned: $qrContent") |
|
|
|
resumedScope.launch { |
|
|
|
val parsed = viewModel.parse(qrContent) |
|
|
|
if (parsed == null) { |
|
|
|