Add navigation lib and test navigation + TTS for nav

This commit is contained in:
clement
2024-07-16 19:53:24 +02:00
parent 7a8c574454
commit fd3ecdc255
19 changed files with 135 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android) alias(libs.plugins.jetbrains.kotlin.android)
@@ -8,7 +9,7 @@ android {
compileSdk = 35 compileSdk = 35
defaultConfig { defaultConfig {
applicationId = "com.clement.busroute" applicationId = "com.example.busroute"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 1 versionCode = 1
@@ -50,7 +51,6 @@ android {
} }
dependencies { dependencies {
implementation(libs.androidx.core.ktx) implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose) implementation(libs.androidx.activity.compose)
@@ -69,5 +69,9 @@ dependencies {
debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest) debugImplementation(libs.androidx.ui.test.manifest)
implementation(libs.osmdroid.android) implementation(libs.osmdroid.android)
implementation(files("./libs/osmbonuspack_6.9.0.aar"))
implementation(libs.commons.lang3)
implementation(libs.gson)
implementation(libs.okhttp)
implementation(libs.play.services.location) implementation(libs.play.services.location)
} }

Binary file not shown.

View File

@@ -9,6 +9,8 @@ import android.location.Location
import android.location.LocationManager import android.location.LocationManager
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.speech.tts.TextToSpeech
import android.speech.tts.Voice
import android.view.WindowManager import android.view.WindowManager
import android.widget.Button import android.widget.Button
import android.widget.TextView import android.widget.TextView
@@ -17,9 +19,12 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.example.busroute.DataClass.BusStop import com.example.busroute.DataClass.BusStop
import com.example.busroute.Database.DbHelper import com.example.busroute.Database.DbHelper
import com.google.android.gms.common.Feature
import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationRequest
import org.osmdroid.api.IMapController import org.osmdroid.api.IMapController
import org.osmdroid.bonuspack.routing.OSRMRoadManager
import org.osmdroid.bonuspack.routing.RoadManager
import org.osmdroid.config.Configuration.getInstance import org.osmdroid.config.Configuration.getInstance
import org.osmdroid.tileprovider.tilesource.TileSourceFactory import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.util.GeoPoint import org.osmdroid.util.GeoPoint
@@ -31,6 +36,7 @@ import org.osmdroid.views.overlay.gestures.RotationGestureOverlay
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider
import org.osmdroid.views.overlay.mylocation.IMyLocationProvider import org.osmdroid.views.overlay.mylocation.IMyLocationProvider
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
import java.util.Locale
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@@ -55,6 +61,11 @@ class MainActivity : ComponentActivity() {
isLocationPermissionGranted() isLocationPermissionGranted()
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
val dbHelper = DbHelper(this) val dbHelper = DbHelper(this)
val tts = TextToSpeech(this, TextToSpeech.OnInitListener{})
tts.setVoice(Voice("French",
Locale.FRENCH, Voice.QUALITY_HIGH,
Voice.LATENCY_LOW, true, null))
tts.setSpeechRate(0.8f)
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this)) getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
@@ -108,6 +119,7 @@ class MainActivity : ComponentActivity() {
startActivity(intent) startActivity(intent)
} }
val rotationGestureOverlay = RotationGestureOverlay(map) val rotationGestureOverlay = RotationGestureOverlay(map)
rotationGestureOverlay.isEnabled rotationGestureOverlay.isEnabled
map.setMultiTouchControls(true) map.setMultiTouchControls(true)
@@ -137,6 +149,12 @@ class MainActivity : ComponentActivity() {
locationOverlay.enableMyLocation() locationOverlay.enableMyLocation()
locationOverlay.enableFollowLocation() locationOverlay.enableFollowLocation()
map.overlays.add(locationOverlay) map.overlays.add(locationOverlay)
val roadButton = findViewById<Button>(R.id.road)
roadButton.setOnClickListener {
tts.speak("Dans 500 mètres, tourner à droite", TextToSpeech.QUEUE_FLUSH, null,"")
locationOverlay.disableMyLocation()
RetrieveRoad(map, latitude,longitude, roadButton.context).execute()
}
// val locationClient = LocationServices.getFusedLocationProviderClient(this) // val locationClient = LocationServices.getFusedLocationProviderClient(this)

View File

@@ -0,0 +1,91 @@
package com.example.busroute
import android.R
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.AsyncTask
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import org.osmdroid.bonuspack.routing.OSRMRoadManager
import org.osmdroid.bonuspack.routing.Road
import org.osmdroid.bonuspack.routing.RoadManager
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.Marker
@SuppressLint("StaticFieldLeak")
class RetrieveRoad(private var map: MapView,
private var latitude: Double,
private var longitude: Double,
private var context: Context
) :
AsyncTask<String, Void, Void>() {
val icons = intArrayOf(
com.example.busroute.R.drawable.ic_continue,
com.example.busroute.R.drawable.ic_slight_right,
com.example.busroute.R.drawable.ic_turn_right,
com.example.busroute.R.drawable.ic_sharp_right,
0,
com.example.busroute.R.drawable.ic_sharp_left,
com.example.busroute.R.drawable.ic_turn_left,
com.example.busroute.R.drawable.ic_slight_left,
com.example.busroute.R.drawable.ic_u_turn,
com.example.busroute.R.drawable.ic_u_turn,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
com.example.busroute.R.drawable.ic_roundabout,
com.example.busroute.R.drawable.ic_roundabout,
com.example.busroute.R.drawable.ic_roundabout,
com.example.busroute.R.drawable.ic_roundabout,
com.example.busroute.R.drawable.ic_roundabout,
com.example.busroute.R.drawable.ic_roundabout
)
override fun doInBackground(vararg p0: String): Void? {
val roadManager: RoadManager = OSRMRoadManager(context, "me")
val waypoints = ArrayList<GeoPoint>()
waypoints.add(GeoPoint(latitude, longitude))
val middlePoint = GeoPoint(45.59, 6.45)
waypoints.add(middlePoint)
val endPoint = GeoPoint(45.48, 6.52)
waypoints.add(endPoint)
val road = roadManager.getRoad(waypoints)
val roadOverlay = RoadManager.buildRoadOverlay(road, Color.Blue.toArgb(), 20f)
roadOverlay.width = 15f
map.overlays.add(roadOverlay)
map.invalidate()
val nodeIcon: Drawable? = context.getDrawable(com.example.busroute.R.drawable.marker_node)
for (i in road.mNodes.indices) {
val node = road.mNodes[i]
val nodeMarker = Marker(map)
nodeMarker.position = node.mLocation
nodeMarker.icon = nodeIcon
nodeMarker.title = "Step $i"
nodeMarker.snippet = node.mInstructions
nodeMarker.subDescription = Road.getLengthDurationText(context, node.mLength, node.mDuration)
val id = icons[node.mManeuverType]
if (id != 0){
val icon: Drawable? = context.getDrawable(id)
nodeMarker.image = icon
map.overlays.add(nodeMarker)
}
}
return null
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

View File

@@ -48,6 +48,15 @@
android:textColor="@color/black" android:textColor="@color/black"
android:clickable="true" android:clickable="true"
android:text="Load path" /> android:text="Load path" />
<Button
android:id="@+id/road"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:focusable="true"
android:textColor="@color/black"
android:clickable="true"
android:text="Test Road Manager" />
<TextView <TextView
android:layout_width="150dp" android:layout_width="150dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -1,5 +1,7 @@
[versions] [versions]
agp = "8.5.0" agp = "8.5.0"
commonsLang3 = "3.8.1"
gson = "2.10.1"
kotlin = "1.9.0" kotlin = "1.9.0"
coreKtx = "1.13.1" coreKtx = "1.13.1"
junit = "4.13.2" junit = "4.13.2"
@@ -8,12 +10,16 @@ espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.8.2" lifecycleRuntimeKtx = "2.8.2"
activityCompose = "1.9.0" activityCompose = "1.9.0"
composeBom = "2024.06.00" composeBom = "2024.06.00"
okhttp = "4.7.2"
osmbonuspack = "6.9.0"
osmdroidAndroid = "6.1.18" osmdroidAndroid = "6.1.18"
playServicesLocation = "21.3.0" playServicesLocation = "21.3.0"
appcompat = "1.7.0" appcompat = "1.7.0"
[libraries] [libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commonsLang3" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
@@ -27,6 +33,8 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
osmbonuspack = { module = "com.github.MKergall:osmbonuspack", version.ref = "osmbonuspack" }
osmdroid-android = { module = "org.osmdroid:osmdroid-android", version.ref = "osmdroidAndroid" } osmdroid-android = { module = "org.osmdroid:osmdroid-android", version.ref = "osmdroidAndroid" }
play-services-location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "playServicesLocation" } play-services-location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "playServicesLocation" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }

View File

@@ -8,6 +8,9 @@ pluginManagement {
} }
} }
mavenCentral() mavenCentral()
flatDir {
dirs("libs")
}
gradlePluginPortal() gradlePluginPortal()
} }
} }