@@ -15,6 +15,8 @@ import com.google.mlkit.vision.common.InputImage
1515import androidx.core.content.ContextCompat
1616import android.content.Intent
1717import android.os.IBinder
18+ import android.os.Vibrator
19+ import android.util.Log
1820import androidx.lifecycle.ProcessLifecycleOwner
1921import org.jsoup.Jsoup
2022import org.jsoup.nodes.Document
@@ -34,7 +36,8 @@ import org.jsoup.nodes.Document
3436 * @param viewModel: viewModel allows the use of the say function
3537 */
3638class Scanner (
37- private val viewModel : MainViewModel
39+ private val viewModel : MainViewModel ,
40+ private val vibrator : Vibrator
3841) : ImageAnalysis.Analyzer {
3942
4043 /* *
@@ -54,9 +57,6 @@ class Scanner(
5457 *
5558 * @param image: uses the camera image without passing an argument directly
5659 *
57- * TODO: potentially add sound feedback on scanned barcode,
58- * TODO: hence the scraping and verbal feedback is a bit delayed
59- *
6060 */
6161 @ExperimentalGetImage
6262 override fun analyze (image : ImageProxy ) {
@@ -67,6 +67,7 @@ class Scanner(
6767 barcodeScanner.process(scannerInput)
6868 .addOnSuccessListener { barcodes ->
6969 for (barcode in barcodes) {
70+ Log .println (Log .INFO , " Scanner" , " Barcode " + barcode.rawValue + " was detected" )
7071 val urlAddOn = barcode.rawValue ? : " default"
7172 Thread {
7273 handleBarcodeResult(urlAddOn)
@@ -83,15 +84,16 @@ class Scanner(
8384
8485 /* *
8586 * Function to handle the Barcode Result.
87+ * Initiates a vibration to give feedback to the user, that a barcode was scanned
8688 * It creates an object BrowserSearch to use its function searchUrl
8789 *
8890 * @param urlAddOn: the Barcode as a String to use for web-search
8991 */
9092 private fun handleBarcodeResult (urlAddOn : String ) {
91- // Handle the barcode result logic here
93+ vibrator.vibrate( 200 )
9294 val eanSearch = BrowserSearch ()
95+ Log .println (Log .INFO , " Scraping" , " Waiting for Scraping result" )
9396 eanSearch.searchUrl(viewModel, urlAddOn)
94-
9597 }
9698}
9799
@@ -142,7 +144,7 @@ class ScanningProcess{
142144 *
143145 * TODO: Change selector to other camera
144146 */
145- fun activateScanning (viewModel : MainViewModel , context : Context ) {
147+ fun activateScanning (viewModel : MainViewModel , vibrator : Vibrator , context : Context ) {
146148
147149 val selector = CameraSelector .Builder ()
148150 .requireLensFacing(CameraSelector .LENS_FACING_BACK )
@@ -152,7 +154,7 @@ class ScanningProcess{
152154 .build()
153155 imageAnalysis.setAnalyzer(
154156 ContextCompat .getMainExecutor(context),
155- Scanner (viewModel)
157+ Scanner (viewModel, vibrator )
156158 )
157159 val cameraProvider = ProcessCameraProvider .getInstance(context).get()
158160 try {
@@ -161,8 +163,10 @@ class ScanningProcess{
161163 selector,
162164 imageAnalysis
163165 )
166+ Log .println (Log .INFO , " Camera" , " Camera binding successful" )
167+
164168 } catch (e: Exception ) {
165- e.printStackTrace()
169+ e.printStackTrace().toString()
166170 }
167171 }
168172}
@@ -187,7 +191,7 @@ class ConstantScanning: Service() {
187191 /* *
188192 * Function that manages the Service, once initialized.
189193 * It creates a viewModel object to be passed on, so the say method can be used later on.
190- * It also creates a Scanner object and starts the Scanning process.
194+ * It also creates a Vibrator and Scanner object and starts the Scanning process.
191195 * Returns Start-Sticky to ensure it will try to start again,
192196 * if it is destroyed for whatever reason
193197 *
@@ -197,11 +201,16 @@ class ConstantScanning: Service() {
197201 */
198202
199203 override fun onStartCommand (intent : Intent ? , flags : Int , startId : Int ): Int {
204+
205+
206+
200207 val application = application
201208 val viewModel = MainViewModel (application)
202209 viewModel.initTTS()
210+ val vibrator = getSystemService(Context .VIBRATOR_SERVICE ) as Vibrator
203211 val scanner = ScanningProcess ()
204- scanner.activateScanning(viewModel, this )
212+ scanner.activateScanning(viewModel, vibrator, this )
213+ Log .println (Log .INFO , " Scanner" ," Barcode Scanning Service is Active" )
205214
206215 return START_STICKY
207216 }
0 commit comments