Skip to content

Commit 6fb2b9f

Browse files
committed
Initial commit
0 parents  commit 6fb2b9f

File tree

73 files changed

+2361
-0
lines changed

Some content is hidden

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

73 files changed

+2361
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Tracking-BLE
2+

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.example.tracking_ble"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
applicationId = "com.example.tracking_ble"
12+
minSdk = 24
13+
targetSdk = 34
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = false
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro"
26+
)
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility = JavaVersion.VERSION_1_8
31+
targetCompatibility = JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = "1.8"
35+
}
36+
buildFeatures {
37+
viewBinding = true
38+
}
39+
}
40+
41+
dependencies {
42+
43+
implementation("androidx.core:core-ktx:1.9.0")
44+
implementation("androidx.appcompat:appcompat:1.6.1")
45+
implementation("com.google.android.material:material:1.11.0")
46+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
47+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")
48+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
49+
implementation("androidx.navigation:navigation-fragment-ktx:2.7.6")
50+
implementation("androidx.navigation:navigation-ui-ktx:2.7.6")
51+
implementation("org.altbeacon:android-beacon-library:2.20")
52+
53+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
54+
implementation("androidx.activity:activity-compose:1.8.2")
55+
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
56+
implementation("androidx.compose.ui:ui")
57+
implementation("androidx.compose.ui:ui-graphics")
58+
implementation("androidx.compose.ui:ui-tooling-preview")
59+
implementation("androidx.compose.material3:material3")
60+
implementation("org.altbeacon:android-beacon-library:2.20")
61+
implementation("com.afollestad.material-dialogs:core:3.2.1")
62+
implementation("com.android.volley:volley:1.2.1")
63+
implementation("androidx.datastore:datastore-preferences:1.0.0-alpha01")
64+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.2.0")
65+
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
66+
implementation("androidx.lifecycle:lifecycle-common-java8:2.2.0")
67+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
68+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10")
69+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
70+
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1")
71+
72+
implementation("com.google.android.gms:play-services-location:17.0.0")
73+
74+
testImplementation("junit:junit:4.13.2")
75+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
76+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
77+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.tracking_ble
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.tracking_ble", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
5+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
8+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
9+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
10+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
11+
<uses-permission android:name="android.permission.INTERNET" />
12+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
13+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
14+
15+
<application
16+
android:allowBackup="true"
17+
android:dataExtractionRules="@xml/data_extraction_rules"
18+
android:fullBackupContent="@xml/backup_rules"
19+
android:icon="@mipmap/ic_launcher_bnblogo"
20+
android:label="@string/app_name"
21+
android:roundIcon="@mipmap/ic_launcher_bnblogo_round"
22+
android:supportsRtl="true"
23+
android:theme="@style/Theme.TrackingBLE"
24+
tools:targetApi="31">
25+
<activity
26+
android:name=".MainActivity"
27+
android:exported="true"
28+
android:label="@string/app_name"
29+
android:theme="@style/Theme.TrackingBLE.NoActionBar">
30+
<intent-filter>
31+
<action android:name="android.intent.action.MAIN" />
32+
33+
<category android:name="android.intent.category.LAUNCHER" />
34+
</intent-filter>
35+
</activity>
36+
</application>
37+
38+
</manifest>
38.3 KB
Loading
37.7 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.example.tracking_ble
2+
3+
import android.app.IntentService
4+
import android.content.Intent
5+
import android.location.Address
6+
import android.location.Geocoder
7+
import android.location.Location
8+
import android.os.Bundle
9+
import android.os.ResultReceiver
10+
import android.util.Log
11+
import java.util.*
12+
13+
// Service d'intention pour obtenir une adresse à partir de coordonnées géographiques
14+
class GetAddressIntentService : IntentService(IDENTIFIER) {
15+
private var addressResultReceiver: ResultReceiver? = null
16+
17+
// Méthode appelée lors de la réception d'une intention
18+
override fun onHandleIntent(intent: Intent?) {
19+
val msg: String
20+
// Récupérer le destinataire des résultats de l'adresse depuis l'intention
21+
addressResultReceiver = Objects.requireNonNull(intent)!!.getParcelableExtra("add_receiver")
22+
23+
// Vérifier si le destinataire des résultats est null
24+
if (addressResultReceiver == null) {
25+
Log.e("GetAddressIntentService", "Aucun destinataire, la demande ne peut pas être traitée")
26+
return
27+
}
28+
29+
// Récupérer les coordonnées géographiques depuis l'intention
30+
val location = intent!!.getParcelableExtra<Location>("add_location")
31+
32+
// Vérifier si les coordonnées géographiques sont null
33+
if (location == null) {
34+
msg = "Aucune localisation, impossible de continuer sans localisation"
35+
sendResultsToReceiver(0, msg)
36+
return
37+
}
38+
39+
// Géocodeur pour obtenir l'adresse à partir des coordonnées
40+
val geoCoder = Geocoder(this, Locale.getDefault())
41+
var addresses: List<Address>? = null
42+
try {
43+
addresses = geoCoder.getFromLocation(location.latitude, location.longitude, 1)
44+
} catch (ioException: Exception) {
45+
Log.e("", "Erreur lors de l'obtention de l'adresse pour la localisation")
46+
}
47+
48+
// Vérifier si aucune adresse n'a été trouvée
49+
if (addresses == null || addresses.isEmpty()) {
50+
msg = "Aucune adresse trouvée pour la localisation"
51+
sendResultsToReceiver(1, msg)
52+
} else {
53+
val address = addresses[0]
54+
// Détails de l'adresse formatés
55+
val addressDetails = """
56+
${address.featureName}
57+
${address.thoroughfare}
58+
Localité: ${address.locality}
59+
Comté: ${address.subAdminArea}
60+
État: ${address.adminArea}
61+
Pays: ${address.countryName}
62+
Code postal: ${address.postalCode}
63+
""".trimIndent()
64+
sendResultsToReceiver(2, addressDetails)
65+
}
66+
}
67+
68+
// Méthode pour envoyer les résultats au destinataire
69+
private fun sendResultsToReceiver(resultCode: Int, message: String) {
70+
val bundle = Bundle()
71+
bundle.putString("address_result", message)
72+
addressResultReceiver!!.send(resultCode, bundle)
73+
}
74+
75+
// Objet compagnon pour l'identifiant du service
76+
companion object {
77+
private const val IDENTIFIER = "GetAddressIntentService"
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.example.tracking_ble
2+
3+
import android.os.Bundle
4+
import android.view.Menu
5+
import com.google.android.material.navigation.NavigationView
6+
import androidx.navigation.findNavController
7+
import androidx.navigation.ui.AppBarConfiguration
8+
import androidx.navigation.ui.navigateUp
9+
import androidx.navigation.ui.setupActionBarWithNavController
10+
import androidx.navigation.ui.setupWithNavController
11+
import androidx.drawerlayout.widget.DrawerLayout
12+
import androidx.appcompat.app.AppCompatActivity
13+
import androidx.core.view.MenuCompat
14+
import com.example.tracking_ble.databinding.ActivityMainBinding
15+
16+
class MainActivity : AppCompatActivity() {
17+
18+
// Configuration de la barre d'application
19+
private lateinit var appBarConfiguration: AppBarConfiguration
20+
21+
// Liaison de l'activité principale
22+
private lateinit var binding: ActivityMainBinding
23+
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
27+
// Initialisation de la liaison avec le layout
28+
binding = ActivityMainBinding.inflate(layoutInflater)
29+
setContentView(binding.root)
30+
31+
// Définir la barre d'outils en tant que barre d'action
32+
setSupportActionBar(binding.appBarMain.toolbar)
33+
34+
// Initialisation du tiroir de navigation et de la vue de navigation
35+
val drawerLayout: DrawerLayout = binding.drawerLayout
36+
val navView: NavigationView = binding.navView
37+
val navController = findNavController(R.id.nav_host_fragment_content_main)
38+
39+
// Configuration de la barre d'application avec les destinations de navigation
40+
appBarConfiguration = AppBarConfiguration(
41+
setOf(
42+
R.id.nav_entrepot, R.id.nav_camion, R.id.nav_parametres
43+
), drawerLayout
44+
)
45+
46+
// Configurer la barre d'action avec le contrôleur de navigation
47+
setupActionBarWithNavController(navController, appBarConfiguration)
48+
// Configurer la vue de navigation avec le contrôleur de navigation
49+
navView.setupWithNavController(navController)
50+
}
51+
52+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
53+
// Gonfler le menu; cela ajoute des éléments à la barre d'action si elle est présente
54+
menuInflater.inflate(R.menu.main, menu)
55+
56+
// Activer le séparateur de groupe dans le menu
57+
MenuCompat.setGroupDividerEnabled(menu, true)
58+
59+
return true
60+
}
61+
62+
override fun onSupportNavigateUp(): Boolean {
63+
// Gestion de la navigation de retour avec le contrôleur de navigation
64+
val navController = findNavController(R.id.nav_host_fragment_content_main)
65+
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.example.tracking_ble
2+
3+
import android.content.Context
4+
import androidx.datastore.preferences.createDataStore
5+
import androidx.datastore.preferences.edit
6+
import androidx.datastore.preferences.preferencesKey
7+
import kotlinx.coroutines.flow.Flow
8+
import kotlinx.coroutines.flow.map
9+
10+
class UserManager(context: Context) {
11+
// Création d'une instance de DataStore
12+
private val dataStore = context.createDataStore(name = "user_prefs")
13+
14+
companion object {
15+
// Clés pour stocker les données de l'utilisateur
16+
val IMMAT_KEY = preferencesKey<String>("IMMAT_KEY") // Clé pour l'immatriculation de l'utilisateur
17+
val ADRESSE_KEY = preferencesKey<String>("ADRESSE_KEY") // Clé pour l'adresse de l'utilisateur
18+
}
19+
20+
// Fonction pour stocker l'immatriculation de l'utilisateur
21+
suspend fun storeUserImmat(immat: String) {
22+
dataStore.edit {
23+
it[IMMAT_KEY] = immat
24+
}
25+
}
26+
27+
// Fonction pour stocker l'adresse de l'utilisateur
28+
suspend fun storeUserAdresse(adresse: String) {
29+
dataStore.edit {
30+
it[ADRESSE_KEY] = adresse
31+
}
32+
}
33+
34+
// Flux de données pour récupérer l'immatriculation de l'utilisateur
35+
val userImmatFlow: Flow<String> = dataStore.data.map {
36+
it[IMMAT_KEY] ?: "" // Si la clé n'existe pas, retourne une chaîne vide
37+
}
38+
39+
// Flux de données pour récupérer l'adresse de l'utilisateur
40+
val userAdresseFlow: Flow<String> = dataStore.data.map {
41+
it[ADRESSE_KEY] ?: "" // Si la clé n'existe pas, retourne une chaîne vide
42+
}
43+
}

0 commit comments

Comments
 (0)