QR scanning changes
This commit is contained in:
@@ -144,7 +144,7 @@ dependencies {
|
|||||||
implementation Deps.AndroidX.PAGING
|
implementation Deps.AndroidX.PAGING
|
||||||
implementation Deps.AndroidX.RECYCLER
|
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-core:${camerax_version}"
|
||||||
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||||
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||||
|
|||||||
@@ -111,17 +111,14 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() {
|
|||||||
private fun bindCameraUseCases() {
|
private fun bindCameraUseCases() {
|
||||||
|
|
||||||
// Get screen metrics used to setup camera for full screen resolution
|
// Get screen metrics used to setup camera for full screen resolution
|
||||||
/*
|
val windowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity())
|
||||||
val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity()).bounds
|
Log.d(TAG, "Screen metrics: ${windowMetrics.bounds.width()} x ${windowMetrics.bounds.height()}")
|
||||||
Log.d("SilentDragon", "Screen metrics: ${metrics.width()} x ${metrics.height()}")
|
|
||||||
val screenAspectRatio = aspectRatio(metrics.width(), metrics.height())
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Hardcode to square for now otherwise scanning doesn't work
|
val screenAspectRatio = aspectRatio(windowMetrics.bounds.width(), windowMetrics.bounds.height())
|
||||||
val screenAspectRatio = aspectRatio(1, 1)
|
Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")
|
||||||
Log.d("SilentDragon", "Preview aspect ratio: $screenAspectRatio")
|
|
||||||
|
|
||||||
val rotation = fragmentCameraBinding.viewFinder.display.rotation
|
val rotation = fragmentCameraBinding.viewFinder.display.rotation
|
||||||
|
Log.d(TAG, "Rotation: $rotation")
|
||||||
|
|
||||||
// CameraProvider
|
// CameraProvider
|
||||||
val cameraProvider = cameraProvider
|
val cameraProvider = cameraProvider
|
||||||
@@ -298,7 +295,8 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() {
|
|||||||
* @return suitable aspect ratio
|
* @return suitable aspect ratio
|
||||||
*/
|
*/
|
||||||
private fun aspectRatio(width: Int, height: Int): Int {
|
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)) {
|
if (abs(previewRatio - RATIO_4_3_VALUE) <= abs(previewRatio - RATIO_16_9_VALUE)) {
|
||||||
return AspectRatio.RATIO_4_3
|
return AspectRatio.RATIO_4_3
|
||||||
}
|
}
|
||||||
@@ -323,7 +321,6 @@ class ScanFragment : BaseFragment<FragmentScanBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onQrScanned(qrContent: String, image: ImageProxy) {
|
private fun onQrScanned(qrContent: String, image: ImageProxy) {
|
||||||
//Log.d("SilentDragon", "QR scanned: $qrContent")
|
|
||||||
resumedScope.launch {
|
resumedScope.launch {
|
||||||
val parsed = viewModel.parse(qrContent)
|
val parsed = viewModel.parse(qrContent)
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user