Browse Source

QR scanning changes

pull/15/head
fekt 1 year ago
parent
commit
b2e0f8d717
  1. 2
      app/build.gradle
  2. 17
      app/src/main/java/cash/z/ecc/android/ui/scan/ScanFragment.kt

2
app/build.gradle

@ -144,7 +144,7 @@ dependencies {
implementation Deps.AndroidX.PAGING
implementation Deps.AndroidX.RECYCLER
def camerax_version = "1.2.0-rc01"
def camerax_version = "1.1.0"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"

17
app/src/main/java/cash/z/ecc/android/ui/scan/ScanFragment.kt

@ -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) {

Loading…
Cancel
Save