From 3ac6fa47c271c72c94d4cc566748262da8d5adad Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 28 Nov 2023 12:38:15 +0100 Subject: [PATCH] Replace me.dm7.barcodescanner with camerax --- pretixscan/app/build.gradle | 1 - .../pretixscan/droid/ui/MainActivity.kt | 14 ++++----- .../pretix/pretixscan/droid/ui/ScannerView.kt | 30 ------------------- .../pretixscan/droid/ui/SetupActivity.kt | 9 ++---- .../app/src/main/res/layout/activity_main.xml | 2 +- .../src/main/res/layout/activity_setup.xml | 2 +- pretixscan/libpretixui-repo | 2 +- 7 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/ScannerView.kt diff --git a/pretixscan/app/build.gradle b/pretixscan/app/build.gradle index 6f92abcb..64dcbe0d 100644 --- a/pretixscan/app/build.gradle +++ b/pretixscan/app/build.gradle @@ -128,7 +128,6 @@ dependencies { implementation 'com.louiscad.splitties:splitties-toast:3.0.0' implementation 'com.github.traex.rippleeffect:library:1.3' - implementation 'me.dm7.barcodescanner:zxing:1.9.8' implementation 'com.github.kizitonwose:CalendarView:1.0.4' implementation 'com.squareup.okhttp3:okhttp:4.9.3' diff --git a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/MainActivity.kt b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/MainActivity.kt index 7c325f83..3cb7e240 100644 --- a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/MainActivity.kt +++ b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/MainActivity.kt @@ -54,7 +54,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.module.SimpleModule import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar -import com.google.zxing.Result import eu.pretix.libpretixsync.api.PretixApi import eu.pretix.libpretixsync.check.CheckException import eu.pretix.libpretixsync.check.OnlineCheckProvider @@ -71,6 +70,7 @@ import eu.pretix.libpretixui.android.covid.SAMPLE_SETTINGS import eu.pretix.libpretixui.android.questions.QuestionsDialogInterface import eu.pretix.libpretixui.android.scanning.HardwareScanner import eu.pretix.libpretixui.android.scanning.ScanReceiver +import eu.pretix.libpretixui.android.scanning.ScannerView import eu.pretix.pretixscan.droid.* import eu.pretix.pretixscan.droid.connectivity.ConnectivityChangedListener import eu.pretix.pretixscan.droid.databinding.ActivityMainBinding @@ -80,7 +80,6 @@ import io.sentry.Sentry import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import me.dm7.barcodescanner.zxing.ZXingScannerView import org.json.JSONArray import org.json.JSONObject import splitties.toast.toast @@ -91,7 +90,6 @@ import java.security.MessageDigest import java.text.SimpleDateFormat import java.time.ZoneId import java.util.* -import splitties.toast.toast interface ReloadableActivity { @@ -146,7 +144,7 @@ class ViewDataHolder(private val ctx: Context) { } } -class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.ResultHandler, MediaPlayer.OnCompletionListener, ConnectivityChangedListener { +class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.ResultHandler, MediaPlayer.OnCompletionListener, ConnectivityChangedListener { private val REQ_EVENT = 1 @@ -857,13 +855,13 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.R fun reloadCameraState() { try { - binding.scannerView.flash = conf.scanFlash + binding.scannerView.torch = conf.scanFlash if (conf.scanFlash) { binding.fabFlash.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.pretix_brand_green)) } else { binding.fabFlash.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.fab_disable)) } - binding.scannerView.setAutoFocus(conf.scanFocus) + binding.scannerView.autofocus = conf.scanFocus if (conf.scanFocus) { binding.fabFocus.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.pretix_brand_green)) } else { @@ -1270,9 +1268,7 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.R } - override fun handleResult(rawResult: Result) { - binding.scannerView.resumeCameraPreview(this@MainActivity) - + override fun handleResult(rawResult: ScannerView.Result) { if ((dialog != null && dialog!!.isShowing()) || view_data.resultState.get() == LOADING) { return } diff --git a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/ScannerView.kt b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/ScannerView.kt deleted file mode 100644 index c1af7fdc..00000000 --- a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/ScannerView.kt +++ /dev/null @@ -1,30 +0,0 @@ -package eu.pretix.pretixscan.droid.ui - -import android.content.Context -import android.graphics.Rect -import android.util.AttributeSet -import me.dm7.barcodescanner.zxing.ZXingScannerView - - -class ScannerView : ZXingScannerView { - private var mFramingRectInPreview: Rect? = null - - constructor(context: Context) : super(context) {} - - constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) {} - - @Synchronized - override fun getFramingRectInPreview(previewWidth: Int, previewHeight: Int): Rect { - if (this.mFramingRectInPreview == null) { - val rect = Rect() - rect.left = 0 - rect.top = 0 - rect.right = previewWidth - rect.bottom = previewHeight - - this.mFramingRectInPreview = rect - } - - return this.mFramingRectInPreview!! - } -} \ No newline at end of file diff --git a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt index a6b1d2d0..ec2ae36b 100644 --- a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt +++ b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt @@ -16,24 +16,23 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.google.zxing.Result import eu.pretix.libpretixsync.setup.* import eu.pretix.libpretixui.android.scanning.HardwareScanner import eu.pretix.libpretixui.android.scanning.ScanReceiver +import eu.pretix.libpretixui.android.scanning.ScannerView import eu.pretix.pretixscan.droid.* import eu.pretix.pretixscan.droid.databinding.ActivitySetupBinding import io.sentry.Sentry import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import me.dm7.barcodescanner.zxing.ZXingScannerView import org.json.JSONException import org.json.JSONObject import java.io.IOException import java.lang.Exception import javax.net.ssl.SSLException -class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler { +class SetupActivity : AppCompatActivity(), ScannerView.ResultHandler { lateinit var binding: ActivitySetupBinding val bgScope = CoroutineScope(Dispatchers.IO) var lastScanTime = 0L @@ -137,8 +136,7 @@ class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler { } } - override fun handleResult(rawResult: Result) { - binding.scannerView.resumeCameraPreview(this) + override fun handleResult(rawResult: ScannerView.Result) { if (lastScanValue == rawResult.text && lastScanTime > System.currentTimeMillis() - 3000) { return } @@ -190,7 +188,6 @@ class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler { fun resume() { pdialog.dismiss() - binding.scannerView.resumeCameraPreview(this) ongoing_setup = false } diff --git a/pretixscan/app/src/main/res/layout/activity_main.xml b/pretixscan/app/src/main/res/layout/activity_main.xml index 671a4a7c..baccebf4 100644 --- a/pretixscan/app/src/main/res/layout/activity_main.xml +++ b/pretixscan/app/src/main/res/layout/activity_main.xml @@ -67,7 +67,7 @@ android:layout_width="match_parent" android:layout_height="fill_parent"> - - diff --git a/pretixscan/libpretixui-repo b/pretixscan/libpretixui-repo index 342472b3..6e1d84a7 160000 --- a/pretixscan/libpretixui-repo +++ b/pretixscan/libpretixui-repo @@ -1 +1 @@ -Subproject commit 342472b35d0f4b9ca8cd042c4ffb5a694d229a3d +Subproject commit 6e1d84a76886451170636587a0fb62c47af9e3c3