Skip to content

Commit c2b6950

Browse files
committed
Changes apllied
1 parent ff6dab5 commit c2b6950

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ android {
1313
defaultConfig {
1414
applicationId "com.nlinterface"
1515
minSdk 24
16-
//noinspection EditedTargetSdkVersion
17-
targetSdk 34
16+
targetSdk 33
1817
versionCode 1
1918
versionName '0.0.1'
2019

@@ -76,13 +75,6 @@ dependencies {
7675
//it.jsoup
7776
implementation "org.jsoup:jsoup:1.14.3"
7877

79-
80-
//androix.compose
81-
implementation(platform('androidx.compose:compose-bom:2023.08.00'))
82-
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
83-
debugImplementation 'androidx.compose.ui:ui-tooling'
84-
85-
8678
//camera
8779
implementation ("androidx.camera:camera-camera2:1.3.1")
8880
implementation("androidx.camera:camera-core:1.3.1")

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
99

1010
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
11+
<uses-permission android:name="android.permission.VIBRATE" />
1112

1213
<application
1314
android:allowBackup="true"

app/src/main/java/com/nlinterface/activities/MainActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ class MainActivity : AppCompatActivity() {
6767
configureSTT()
6868

6969
verifyCameraPermissions()
70-
val serviceIntent = Intent(this, ConstantScanning()::class.java)
71-
startService(serviceIntent)
70+
if (checkCallingOrSelfPermission(
71+
Manifest.permission.CAMERA
72+
) == PackageManager.PERMISSION_GRANTED) {
73+
val serviceIntent = Intent(this, ConstantScanning()::class.java)
74+
startService(serviceIntent)
75+
}
7276
}
7377

7478
/**

app/src/main/java/com/nlinterface/viewmodels/BarcodeProductinfoViewModel.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import com.google.mlkit.vision.common.InputImage
1515
import androidx.core.content.ContextCompat
1616
import android.content.Intent
1717
import android.os.IBinder
18+
import android.os.Vibrator
19+
import android.util.Log
1820
import androidx.lifecycle.ProcessLifecycleOwner
1921
import org.jsoup.Jsoup
2022
import 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
*/
3638
class 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

Comments
 (0)