Skip to content

Commit cd1d5b6

Browse files
author
Maximilian Häming
authored
Merge pull request #10 from StudyProject-NLI/docs-setup
doc update + barcode scanner
2 parents 37895b8 + 69f49ce commit cd1d5b6

41 files changed

Lines changed: 971 additions & 73 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ google-services.json
3131
*.hprof
3232

3333
site
34+
.gradle
35+
build/

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,10 @@ This is the code repository for the Android app developed in the studyproject Se
2020
commit id: "Prepare for codebase transfer"
2121
```
2222

23-
# Documentation
24-
25-
## Running locally
26-
- Install Python
27-
- `pip install -r docs/requirements.txt`
28-
29-
Run the documentation server via
30-
```bash
31-
$ mkdocs serve
32-
```
33-
3423

3524
# Building the app locally
3625
Requirements:
37-
- At least Java 8 JDK installed
26+
- At least Java 17 JDK installed
3827
- Create a `local.properties` file at the root of this repository with the following content
3928

4029
```bash
@@ -56,3 +45,15 @@ The resulting installable application can be found under
5645
`app/build/outputs/apk/debug/app-debug.apk`
5746

5847
which you can copy and install on your device.
48+
49+
# Documentation
50+
51+
## Running locally
52+
- Install Python
53+
- `pip install -r docs/requirements.txt`
54+
55+
Run the documentation server via
56+
```bash
57+
$ mkdocs serve
58+
```
59+

app/build.gradle

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ plugins {
33
id 'org.jetbrains.kotlin.android'
44
id 'kotlin-parcelize'
55
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
6-
76
}
87

98
android {
@@ -15,7 +14,7 @@ android {
1514
minSdk 24
1615
targetSdk 33
1716
versionCode 1
18-
versionName '0.0.1'
17+
versionName '0.0.3'
1918

2019
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2120
}
@@ -49,36 +48,44 @@ dependencies {
4948

5049
implementation 'androidx.core:core-ktx:1.12.0'
5150
implementation 'androidx.appcompat:appcompat:1.6.1'
52-
implementation 'com.google.android.material:material:1.5.0-alpha04'
51+
implementation 'com.google.android.material:material:1.11.0'
5352
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
54-
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
55-
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
53+
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
54+
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
5655
implementation 'androidx.lifecycle:lifecycle-process:2.7.0'
5756
testImplementation 'junit:junit:4.13.2'
5857
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
5958
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
6059

6160
// Set up the location feature dependency
62-
implementation 'com.google.android.gms:play-services-location:21.0.1'
61+
implementation 'com.google.android.gms:play-services-location:21.1.0'
6362

6463
// GSON dependency
65-
implementation 'com.google.code.gson:gson:2.8.5'
64+
implementation 'com.google.code.gson:gson:2.10'
6665

6766
// Places API
68-
implementation 'com.google.android.libraries.places:places:3.2.0'
67+
implementation 'com.google.android.libraries.places:places:3.3.0'
68+
69+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1")
70+
71+
// Camera + Tensorflow
72+
implementation("androidx.camera:camera-core:1.3.1")
73+
implementation("androidx.camera:camera-camera2:1.3.1")
74+
implementation("androidx.camera:camera-lifecycle:1.3.1")
75+
implementation("androidx.camera:camera-video:1.3.1")
76+
77+
implementation("androidx.camera:camera-view:1.3.1")
78+
implementation("androidx.camera:camera-extensions:1.3.1")
6979

70-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
80+
implementation("org.tensorflow:tensorflow-lite-task-vision:0.4.0")
81+
implementation("org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.0")
82+
implementation("org.tensorflow:tensorflow-lite-gpu:2.9.0")
7183

84+
// Camera UI
85+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
7286
//mlkit
7387
implementation 'com.google.mlkit:barcode-scanning:17.2.0'
7488

7589
//it.jsoup
7690
implementation "org.jsoup:jsoup:1.14.3"
77-
78-
//camera
79-
implementation ("androidx.camera:camera-camera2:1.3.1")
80-
implementation("androidx.camera:camera-core:1.3.1")
81-
implementation("androidx.camera:camera-lifecycle:1.3.1")
82-
implementation("androidx.camera:camera-view:1.3.1")
83-
84-
}
91+
}

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
88
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
9-
10-
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
119
<uses-permission android:name="android.permission.VIBRATE" />
12-
10+
<uses-feature
11+
android:name="android.hardware.camera"
12+
android:required="false" />
13+
<uses-permission android:name="android.permission.CAMERA" />
1314
<application
1415
android:allowBackup="true"
1516
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -46,9 +47,11 @@
4647
android:name=".activities.PlaceDetailsActivity" />
4748
<activity
4849
android:name=".activities.SettingsActivity"/>
50+
<activity
51+
android:name=".activities.ClassificationActivity"/>
4952
<service
5053
android:name=".viewmodels.ConstantScanning"
5154
android:exported="false" />
5255
</application>
5356

54-
</manifest>
57+
</manifest>
3.99 MB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.nlinterface.activities
2+
3+
import android.content.pm.PackageManager
4+
import android.os.Bundle
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.content.ContextCompat
7+
import android.Manifest
8+
import android.content.ContentValues.TAG
9+
import android.util.Log
10+
import androidx.camera.core.AspectRatio
11+
import androidx.camera.core.CameraSelector
12+
import androidx.camera.core.ImageAnalysis
13+
import androidx.camera.core.Preview
14+
import androidx.camera.lifecycle.ProcessCameraProvider
15+
import androidx.core.app.ActivityCompat
16+
import com.nlinterface.databinding.ActivityClassificationBinding
17+
import com.nlinterface.databinding.FragmentCameraBinding
18+
import com.nlinterface.utility.ObjectDetectorHelper
19+
20+
class ClassificationActivity: AppCompatActivity() {
21+
22+
private lateinit var viewBinding: ActivityClassificationBinding
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
if(!hasCameraPermission()) {
26+
ActivityCompat.requestPermissions(
27+
this, arrayOf(Manifest.permission.CAMERA), 0
28+
)
29+
}
30+
31+
viewBinding = ActivityClassificationBinding.inflate(layoutInflater)
32+
setContentView(viewBinding.root)
33+
}
34+
35+
private fun hasCameraPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
36+
37+
38+
}

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ class MainActivity : AppCompatActivity() {
6565
configureUI()
6666
configureTTS()
6767
configureSTT()
68-
69-
verifyCameraPermissions()
70-
if (checkCallingOrSelfPermission(
71-
Manifest.permission.CAMERA
72-
) == PackageManager.PERMISSION_GRANTED) {
73-
val serviceIntent = Intent(this, ConstantScanning()::class.java)
74-
startService(serviceIntent)
75-
}
7668
}
7769

7870
/**
@@ -94,6 +86,17 @@ class MainActivity : AppCompatActivity() {
9486

9587
// process theme settings
9688
GlobalParameters.instance!!.updateTheme()
89+
90+
val serviceIntent = Intent(this, ConstantScanning()::class.java)
91+
if (GlobalParameters.instance!!.barcodeServiceMode == GlobalParameters.BarcodeServiceMode.ON) {
92+
verifyCameraPermissions()
93+
if (checkCallingOrSelfPermission( Manifest.permission.CAMERA ) == PackageManager.PERMISSION_GRANTED) {
94+
startService(serviceIntent)
95+
}
96+
} else {
97+
stopService(serviceIntent)
98+
Log.println(Log.INFO, "Scanner", "Stopping the Barcode Scanning Service")
99+
}
97100
}
98101

99102
/**
@@ -220,6 +223,12 @@ class MainActivity : AppCompatActivity() {
220223
navToActivity(this, ActivityType.PLACEDETAILS)
221224
}
222225

226+
// set up button to navigate to ClassificationActivity
227+
val classificationButton: Button = findViewById<View>(R.id.classification_bt) as Button
228+
classificationButton.setOnClickListener { _ ->
229+
navToActivity(this, ActivityType.CLASSIFICATION)
230+
}
231+
223232
// set up button to navigate to SettingsActivity
224233
val settingsActivityButton: Button = findViewById<View>(R.id.settings_bt) as Button
225234
settingsActivityButton.setOnClickListener { _ ->

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.nlinterface.utility.ActivityType
1414
import com.nlinterface.utility.GlobalParameters
1515
import com.nlinterface.utility.GlobalParameters.ThemeChoice
1616
import com.nlinterface.utility.GlobalParameters.KeepScreenOn
17+
import com.nlinterface.utility.GlobalParameters.BarcodeServiceMode
1718
import com.nlinterface.utility.STTInputType
1819
import com.nlinterface.utility.navToActivity
1920
import com.nlinterface.utility.setViewRelativeSize
@@ -53,6 +54,9 @@ class SettingsActivity : AppCompatActivity() {
5354
private lateinit var themeOptions: MutableList<String>
5455
private lateinit var themeButton: Button
5556

57+
private lateinit var barcodeServiceOptions: MutableList<String>
58+
private lateinit var barcodeServiceButton : Button
59+
5660
private lateinit var voiceActivationButton: ImageButton
5761

5862
private lateinit var lastCommand: String
@@ -83,6 +87,11 @@ class SettingsActivity : AppCompatActivity() {
8387
themeOptions.add(option)
8488
}
8589

90+
barcodeServiceOptions = mutableListOf()
91+
resources.getStringArray(R.array.barcode_mode_options).forEach { option ->
92+
barcodeServiceOptions.add(option)
93+
}
94+
8695
configureUI()
8796
configureTTS()
8897
configureSTT()
@@ -107,6 +116,9 @@ class SettingsActivity : AppCompatActivity() {
107116
keepScreenOnButton.setOnClickListener { onKeepScreenOnButtonClick() }
108117
keepScreenOnButton.text = keepScreenOnOptions[globalParameters.keepScreenOn.ordinal]
109118

119+
barcodeServiceButton = findViewById(R.id.settings_barcode_mode)
120+
barcodeServiceButton.setOnClickListener { onBarcodeServiceButtonClick() }
121+
barcodeServiceButton.text = barcodeServiceOptions[globalParameters.barcodeServiceMode.ordinal]
110122
}
111123

112124
/**
@@ -145,6 +157,19 @@ class SettingsActivity : AppCompatActivity() {
145157
viewModel.say(resources.getString(R.string.new_screen_setting, keepScreenOnButton.text))
146158
}
147159

160+
private fun onBarcodeServiceButtonClick() {
161+
if (globalParameters.barcodeServiceMode.ordinal == BarcodeServiceMode.values().size - 1) {
162+
globalParameters.barcodeServiceMode = BarcodeServiceMode.values()[0]
163+
} else {
164+
globalParameters.barcodeServiceMode = BarcodeServiceMode.values()[globalParameters.barcodeServiceMode.ordinal + 1]
165+
}
166+
167+
barcodeServiceButton.text = barcodeServiceOptions[globalParameters.barcodeServiceMode.ordinal]
168+
169+
// TODO: Add voice commands for Barcode Service
170+
}
171+
172+
148173
/**
149174
* If the activity is paused, save the current preferences to SharedPreferences.
150175
*/

0 commit comments

Comments
 (0)