TomTom Routing
This commit is contained in:
@@ -14,8 +14,8 @@ android {
|
||||
applicationId = "com.kouros.navigation"
|
||||
minSdk = 33
|
||||
targetSdk = 36
|
||||
versionCode = 36
|
||||
versionName = "0.2.0.36"
|
||||
versionCode = 38
|
||||
versionName = "0.2.0.38"
|
||||
base.archivesName = "navi-$versionName"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
val routeModel = RouteModel()
|
||||
var tilt = 50.0
|
||||
val useMock = true
|
||||
val type = 1 // simulate 2 test 3 gpx
|
||||
val useMock = false
|
||||
val type = 3 // simulate 2 test 3 gpx 4 testSingle
|
||||
|
||||
var currentIndex = 0
|
||||
val stepData: MutableLiveData<StepData> by lazy {
|
||||
@@ -109,14 +109,15 @@ class MainActivity : ComponentActivity() {
|
||||
3 -> gpx(
|
||||
context = applicationContext
|
||||
)
|
||||
|
||||
4 -> testSingle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val cameraPosition = MutableLiveData(
|
||||
CameraPosition(
|
||||
zoom = 15.0,
|
||||
target = Position(latitude = 48.1857475, longitude = 11.5793627)
|
||||
zoom = 15.0, target = Position(latitude = 48.1857475, longitude = 11.5793627)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -140,17 +141,15 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
|
||||
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
||||
fusedLocationClient.lastLocation
|
||||
.addOnSuccessListener { _: android.location.Location? ->
|
||||
if (useMock) {
|
||||
mock = MockLocation(locationManager)
|
||||
mock.setMockLocation(
|
||||
homeVogelhart.latitude,
|
||||
homeVogelhart.longitude
|
||||
)
|
||||
navigationViewModel.route.observe(this, observer)
|
||||
}
|
||||
fusedLocationClient.lastLocation.addOnSuccessListener { _: android.location.Location? ->
|
||||
if (useMock) {
|
||||
mock = MockLocation(locationManager)
|
||||
mock.setMockLocation(
|
||||
homeVogelhart.latitude, homeVogelhart.longitude
|
||||
)
|
||||
navigationViewModel.route.observe(this, observer)
|
||||
}
|
||||
}
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
CheckPermissionScreen()
|
||||
@@ -196,8 +195,7 @@ class MainActivity : ComponentActivity() {
|
||||
val sheetPeekHeightState = remember { mutableStateOf(256.dp) }
|
||||
|
||||
val locationProvider = rememberDefaultLocationProvider(
|
||||
updateInterval = 0.5.seconds,
|
||||
desiredAccuracy = DesiredAccuracy.Highest
|
||||
updateInterval = 0.5.seconds, desiredAccuracy = DesiredAccuracy.Highest
|
||||
)
|
||||
val userLocationState = rememberUserLocationState(locationProvider)
|
||||
val locationState = locationProvider.location.collectAsState()
|
||||
@@ -263,12 +261,10 @@ class MainActivity : ComponentActivity() {
|
||||
@Composable
|
||||
fun Settings(navController: NavController, modifier: Modifier = Modifier) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
FloatingActionButton(
|
||||
modifier = Modifier
|
||||
.padding(start = 10.dp, top = 40.dp),
|
||||
modifier = Modifier.padding(start = 10.dp, top = 40.dp),
|
||||
onClick = {
|
||||
navController.navigate("settings")
|
||||
},
|
||||
@@ -284,44 +280,35 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
@Composable
|
||||
fun SheetContent(
|
||||
locationState: Double,
|
||||
step: StepData?,
|
||||
nextStep: StepData?,
|
||||
closeSheet: () -> Unit
|
||||
locationState: Double, step: StepData?, nextStep: StepData?, closeSheet: () -> Unit
|
||||
) {
|
||||
if (!routeModel.isNavigating()) {
|
||||
SearchSheet(applicationContext, navigationViewModel, lastLocation) { closeSheet() }
|
||||
} else {
|
||||
NavigationSheet(
|
||||
applicationContext,
|
||||
routeModel, step!!, nextStep!!,
|
||||
routeModel,
|
||||
step!!,
|
||||
nextStep!!,
|
||||
{ stopNavigation { closeSheet() } },
|
||||
{ simulateNavigation() }
|
||||
)
|
||||
{ simulateNavigation() })
|
||||
}
|
||||
// For recomposition!
|
||||
Text("$locationState", fontSize = 12.sp)
|
||||
}
|
||||
|
||||
fun updateLocation(location: Location?) {
|
||||
if (location != null
|
||||
&& lastLocation.latitude != location.position.latitude
|
||||
&& lastLocation.longitude != location.position.longitude
|
||||
) {
|
||||
if (location != null && lastLocation.latitude != location.position.latitude && lastLocation.longitude != location.position.longitude) {
|
||||
val currentLocation = location(location.position.longitude, location.position.latitude)
|
||||
val bearing = bearing(lastLocation, currentLocation, cameraPosition.value!!.bearing)
|
||||
with(routeModel) {
|
||||
if (isNavigating()) {
|
||||
updateLocation(currentLocation, navigationViewModel)
|
||||
stepData.value = currentStep()
|
||||
if (route.currentStepIndex + 1 <= curLeg.steps.size) {
|
||||
nextStepData.value = nextStep()
|
||||
}
|
||||
if (maneuverType in 39..42
|
||||
&& routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
|
||||
) {
|
||||
nextStepData.value = nextStep()
|
||||
if (navState.maneuverType in 39..42 && routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE) {
|
||||
// stopNavigation()
|
||||
arrived = true
|
||||
navState.copy(arrived = true)
|
||||
routeData.value = ""
|
||||
}
|
||||
}
|
||||
@@ -329,9 +316,7 @@ class MainActivity : ComponentActivity() {
|
||||
val zoom = calculateZoom(location.speed)
|
||||
cameraPosition.postValue(
|
||||
cameraPosition.value!!.copy(
|
||||
zoom = zoom,
|
||||
target = location.position,
|
||||
bearing = bearing
|
||||
zoom = zoom, target = location.position, bearing = bearing
|
||||
),
|
||||
)
|
||||
lastLocation = currentLocation
|
||||
@@ -351,7 +336,7 @@ class MainActivity : ComponentActivity() {
|
||||
mock.setMockLocation(latitude, longitude)
|
||||
}
|
||||
routeData.value = ""
|
||||
stepData.value = StepData("", 0.0, 0, 0, 0, 0.0)
|
||||
stepData.value = StepData("", 0.0, 0, 0, 0, 0.0)
|
||||
}
|
||||
|
||||
fun simulateNavigation() {
|
||||
@@ -361,14 +346,10 @@ class MainActivity : ComponentActivity() {
|
||||
private fun checkMockLocationEnabled() {
|
||||
try {
|
||||
// Check if mock location is enabled for this app
|
||||
val appOpsManager =
|
||||
getSystemService(APP_OPS_SERVICE) as AppOpsManager
|
||||
val mode =
|
||||
appOpsManager.checkOp(
|
||||
AppOpsManager.OPSTR_MOCK_LOCATION,
|
||||
Process.myUid(),
|
||||
packageName
|
||||
)
|
||||
val appOpsManager = getSystemService(APP_OPS_SERVICE) as AppOpsManager
|
||||
val mode = appOpsManager.checkOp(
|
||||
AppOpsManager.OPSTR_MOCK_LOCATION, Process.myUid(), packageName
|
||||
)
|
||||
|
||||
if (mode != AppOpsManager.MODE_ALLOWED) {
|
||||
Toast.makeText(
|
||||
@@ -389,7 +370,7 @@ class MainActivity : ComponentActivity() {
|
||||
val deviation = 0.0
|
||||
if (index in 0..routeModel.curRoute.waypoints.size) {
|
||||
mock.setMockLocation(waypoint[1], waypoint[0])
|
||||
delay(500L) //
|
||||
Thread.sleep(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -399,26 +380,36 @@ class MainActivity : ComponentActivity() {
|
||||
fun test() {
|
||||
for ((index, step) in routeModel.curLeg.steps.withIndex()) {
|
||||
//if (index in 3..3) {
|
||||
for ((windex, waypoint) in step.maneuver.waypoints.withIndex()) {
|
||||
routeModel.updateLocation(
|
||||
location(waypoint[0], waypoint[1]),
|
||||
navigationViewModel
|
||||
)
|
||||
val step = routeModel.currentStep()
|
||||
println("Step: ${step.instruction} ${step.leftStepDistance}")
|
||||
if (index + 1 <= routeModel.curLeg.steps.size) {
|
||||
//nextStepData.value = routeModel.nextStep()
|
||||
}
|
||||
}
|
||||
for ((windex, waypoint) in step.maneuver.waypoints.withIndex()) {
|
||||
routeModel.updateLocation(
|
||||
location(waypoint[0], waypoint[1]), navigationViewModel
|
||||
)
|
||||
val step = routeModel.currentStep()
|
||||
val nextStep = routeModel.nextStep()
|
||||
println("Step: ${step.instruction} ${step.leftStepDistance} ${nextStep.currentManeuverType}")
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
// Balanstr.
|
||||
mock.setMockLocation(48.119357, 11.599130)
|
||||
fun testSingle() {
|
||||
testSingleUpdate(48.185976, 11.578463) // Silcherstr. 23-13
|
||||
testSingleUpdate(48.186712, 11.578574) // Silcherstr. 27-33
|
||||
testSingleUpdate(48.186899, 11.580480) // Schmalkadenerstr. 24-28
|
||||
}
|
||||
|
||||
fun testSingleUpdate(latitude: Double, longitude: Double) {
|
||||
if (1 == 1) {
|
||||
mock.setMockLocation(latitude, longitude)
|
||||
} else {
|
||||
routeModel.updateLocation(
|
||||
location(longitude, latitude), navigationViewModel
|
||||
)
|
||||
}
|
||||
val step = routeModel.currentStep()
|
||||
val nextStep = routeModel.nextStep()
|
||||
println("Step: ${step.instruction} ${step.leftStepDistance} ${nextStep.currentManeuverType}")
|
||||
Thread.sleep(1_000)
|
||||
}
|
||||
|
||||
fun gpx(context: Context) {
|
||||
|
||||
@@ -34,7 +34,7 @@ fun NavigationSheet(
|
||||
val distance = (step.leftDistance / 1000).round(1)
|
||||
|
||||
if (step.lane.isNotEmpty()) {
|
||||
routeModel.iconMapper.addLanes( step)
|
||||
routeModel.navState.iconMapper.addLanes( step)
|
||||
}
|
||||
|
||||
Column {
|
||||
|
||||
Reference in New Issue
Block a user