From c2b69500e1d1761bb1657c589d8d09ac79ea2e50 Mon Sep 17 00:00:00 2001 From: Bene0202 <131483360+Bene0202@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:40:44 +0100 Subject: [PATCH] Changes apllied --- app/build.gradle | 10 +----- app/src/main/AndroidManifest.xml | 1 + .../nlinterface/activities/MainActivity.kt | 8 +++-- .../viewmodels/BarcodeProductinfoViewModel.kt | 31 ++++++++++++------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 477d96c..0094416 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,7 @@ android { defaultConfig { applicationId "com.nlinterface" minSdk 24 - //noinspection EditedTargetSdkVersion - targetSdk 34 + targetSdk 33 versionCode 1 versionName '0.0.1' @@ -76,13 +75,6 @@ dependencies { //it.jsoup implementation "org.jsoup:jsoup:1.14.3" - - //androix.compose - implementation(platform('androidx.compose:compose-bom:2023.08.00')) - androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00")) - debugImplementation 'androidx.compose.ui:ui-tooling' - - //camera implementation ("androidx.camera:camera-camera2:1.3.1") implementation("androidx.camera:camera-core:1.3.1") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c2ff521..f2bdeb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ + for (barcode in barcodes) { + Log.println(Log.INFO, "Scanner", "Barcode " + barcode.rawValue + " was detected") val urlAddOn = barcode.rawValue ?: "default" Thread { handleBarcodeResult(urlAddOn) @@ -83,15 +84,16 @@ class Scanner( /** * Function to handle the Barcode Result. + * Initiates a vibration to give feedback to the user, that a barcode was scanned * It creates an object BrowserSearch to use its function searchUrl * * @param urlAddOn: the Barcode as a String to use for web-search */ private fun handleBarcodeResult(urlAddOn: String) { - // Handle the barcode result logic here + vibrator.vibrate(200) val eanSearch = BrowserSearch() + Log.println(Log.INFO, "Scraping", "Waiting for Scraping result") eanSearch.searchUrl(viewModel, urlAddOn) - } } @@ -142,7 +144,7 @@ class ScanningProcess{ * * TODO: Change selector to other camera */ - fun activateScanning(viewModel: MainViewModel, context: Context) { + fun activateScanning(viewModel: MainViewModel, vibrator: Vibrator, context: Context) { val selector = CameraSelector.Builder() .requireLensFacing(CameraSelector.LENS_FACING_BACK) @@ -152,7 +154,7 @@ class ScanningProcess{ .build() imageAnalysis.setAnalyzer( ContextCompat.getMainExecutor(context), - Scanner(viewModel) + Scanner(viewModel, vibrator) ) val cameraProvider = ProcessCameraProvider.getInstance(context).get() try { @@ -161,8 +163,10 @@ class ScanningProcess{ selector, imageAnalysis ) + Log.println(Log.INFO, "Camera", "Camera binding successful") + } catch (e: Exception) { - e.printStackTrace() + e.printStackTrace().toString() } } } @@ -187,7 +191,7 @@ class ConstantScanning: Service() { /** * Function that manages the Service, once initialized. * It creates a viewModel object to be passed on, so the say method can be used later on. - * It also creates a Scanner object and starts the Scanning process. + * It also creates a Vibrator and Scanner object and starts the Scanning process. * Returns Start-Sticky to ensure it will try to start again, * if it is destroyed for whatever reason * @@ -197,11 +201,16 @@ class ConstantScanning: Service() { */ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + + + val application = application val viewModel = MainViewModel(application) viewModel.initTTS() + val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator val scanner = ScanningProcess() - scanner.activateScanning(viewModel, this) + scanner.activateScanning(viewModel, vibrator, this) + Log.println(Log.INFO, "Scanner","Barcode Scanning Service is Active") return START_STICKY }