Add navigation lib and test navigation + TTS for nav
@@ -1,3 +1,4 @@
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.jetbrains.kotlin.android)
|
||||
@@ -8,7 +9,7 @@ android {
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.clement.busroute"
|
||||
applicationId = "com.example.busroute"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 1
|
||||
@@ -50,7 +51,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
@@ -69,5 +69,9 @@ dependencies {
|
||||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
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)
|
||||
}
|
||||
BIN
app/libs/osmbonuspack_6.9.0.aar
Normal file
@@ -9,6 +9,8 @@ import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.speech.tts.Voice
|
||||
import android.view.WindowManager
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
@@ -17,9 +19,12 @@ import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.example.busroute.DataClass.BusStop
|
||||
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.LocationRequest
|
||||
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.tileprovider.tilesource.TileSourceFactory
|
||||
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.IMyLocationProvider
|
||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -55,6 +61,11 @@ class MainActivity : ComponentActivity() {
|
||||
isLocationPermissionGranted()
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
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
|
||||
getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
|
||||
@@ -108,6 +119,7 @@ class MainActivity : ComponentActivity() {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
val rotationGestureOverlay = RotationGestureOverlay(map)
|
||||
rotationGestureOverlay.isEnabled
|
||||
map.setMultiTouchControls(true)
|
||||
@@ -137,6 +149,12 @@ class MainActivity : ComponentActivity() {
|
||||
locationOverlay.enableMyLocation()
|
||||
locationOverlay.enableFollowLocation()
|
||||
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)
|
||||
|
||||
91
app/src/main/java/com/example/busroute/RetrieveRoad.kt
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
BIN
app/src/main/res/drawable/ic_arrived.png
Normal file
|
After Width: | Height: | Size: 489 B |
BIN
app/src/main/res/drawable/ic_continue.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
app/src/main/res/drawable/ic_empty.png
Normal file
|
After Width: | Height: | Size: 240 B |
BIN
app/src/main/res/drawable/ic_roundabout.png
Normal file
|
After Width: | Height: | Size: 716 B |
BIN
app/src/main/res/drawable/ic_sharp_left.png
Normal file
|
After Width: | Height: | Size: 530 B |
BIN
app/src/main/res/drawable/ic_sharp_right.png
Normal file
|
After Width: | Height: | Size: 746 B |
BIN
app/src/main/res/drawable/ic_slight_left.png
Normal file
|
After Width: | Height: | Size: 635 B |
BIN
app/src/main/res/drawable/ic_slight_right.png
Normal file
|
After Width: | Height: | Size: 607 B |
BIN
app/src/main/res/drawable/ic_turn_left.png
Normal file
|
After Width: | Height: | Size: 676 B |
BIN
app/src/main/res/drawable/ic_turn_right.png
Normal file
|
After Width: | Height: | Size: 656 B |
BIN
app/src/main/res/drawable/ic_u_turn.png
Normal file
|
After Width: | Height: | Size: 778 B |
BIN
app/src/main/res/drawable/marker_node.png
Normal file
|
After Width: | Height: | Size: 611 B |
@@ -48,6 +48,15 @@
|
||||
android:textColor="@color/black"
|
||||
android:clickable="true"
|
||||
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
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||