Duration Map

This commit is contained in:
Dimitris
2026-03-27 07:17:53 +01:00
parent 263b5b576d
commit 2348d3b633
8 changed files with 51 additions and 97 deletions

View File

@@ -67,7 +67,7 @@ class DeviceLocationManager(
* @param minDistanceM Minimum distance between updates in meters (default: 5m)
*/
@SuppressLint("MissingPermission")
fun startLocationUpdates(minTimeMs: Long = 500, minDistanceM: Float = 5f) {
fun startLocationUpdates(minTimeMs: Long = 1000, minDistanceM: Float = 5f) {
if (isListening) return
// Get and deliver last known location first

View File

@@ -1,13 +1,9 @@
package com.kouros.navigation.car
import android.Manifest.permission
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.location.Location
import android.os.IBinder
import android.util.Log
import androidx.car.app.CarContext
import androidx.car.app.CarToast
@@ -15,13 +11,11 @@ import androidx.car.app.Screen
import androidx.car.app.ScreenManager
import androidx.car.app.Session
import androidx.car.app.connection.CarConnection
import androidx.car.app.model.CarIcon
import androidx.car.app.model.Distance
import androidx.car.app.navigation.NavigationManager
import androidx.car.app.navigation.NavigationManagerCallback
import androidx.car.app.navigation.model.Destination
import androidx.car.app.navigation.model.Step
import androidx.car.app.navigation.model.TravelEstimate
import androidx.car.app.navigation.model.Trip
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleObserver
@@ -114,11 +108,13 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
private var showTraffic = false;
private var distanceMode = 0
var lastCameraSearch = 0
var speedCameras = listOf<Elements>()
var lastRouteDate: LocalDateTime = LocalDateTime.now()
var navigationManagerStarted = false
/**
@@ -170,6 +166,10 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
repository.trafficFlow.asLiveData().observe(this, Observer {
showTraffic = it
})
repository.distanceModeFlow.asLiveData().observe(this, Observer {
distanceMode = it
})
}
/**
@@ -441,24 +441,33 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
* Snaps location to route and checks for deviation requiring reroute.
*/
private fun handleNavigationLocation(location: Location) {
routeModel.updateLocation(location, navigationViewModel)
if (routeModel.navState.arrived) return
if (guidanceAudio == 1) {
handleGuidanceAudio()
}
val streetName = routeModel.currentStep().street
val currentDate = LocalDateTime.now(ZoneOffset.UTC)
checkTraffic(currentDate, location)
updateSpeedCamera(location)
checkRoute(currentDate, location)
routeModel.updateLocation(location, navigationViewModel)
checkArrival()
updateNavigationScreen()
updateTripNavigationScreen(location)
snapLocation(location, streetName)
}
if (routeModel.navState.arrived) return
/**
* Updates the surface renderer with snapped location and street name.
* Checks if maximal route deviation is exceeded and reroutes if needed.
*/
private fun snapLocation(location: Location, streetName: String) {
val snappedLocation = snapLocation(location, routeModel.route.maneuverLocations())
val distance = location.distanceTo(snappedLocation)
when {
distance > MAXIMAL_ROUTE_DEVIATION -> {
stopNavigation()
navigationScreen.calculateNewRoute(routeModel.navState.destination)
}
@@ -472,19 +481,20 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
}
}
fun updateTripNavigationScreen(location: Location) {
val travelEstimateTrip = routeModel.travelEstimateTrip(carContext, 0)
val travelEstimateStep = routeModel.travelEstimateStep(carContext, 0)
val steps = mutableListOf<Step>()
val street = if (routeModel.navState.destination.street != null) {
routeModel.navState.destination.street!!
} else {
// routeModel.navState.destination.name!!
"Street"
/**
* Updates the navigation screen with new trip information.
*/
fun updateNavigationScreen() {
if (routeModel.navState.destination.name.isEmpty()
&& routeModel.navState.destination.street.isEmpty()) {
return
}
val travelEstimateTrip = routeModel.travelEstimateTrip(carContext, distanceMode)
val travelEstimateStep = routeModel.travelEstimateStep(carContext, distanceMode)
val steps = mutableListOf<Step>()
val destination = Destination.Builder()
.setName(street)
.setAddress(street)
.setName(routeModel.navState.destination.name)
.setAddress(routeModel.navState.destination.street)
.build()
val distance =
formattedDistance(0, routeModel.routeCalculator.leftStepDistance())
@@ -501,7 +511,7 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
stepTravelEstimate = travelEstimateStep,
destinations = mutableListOf(destination),
steps = steps,
nextStepRemainingDistance = Distance.create(distance.first, distance.second),
stepRemainingDistance = Distance.create(distance.first, distance.second),
shouldShowNextStep = false,
shouldShowLanes = true,
junctionImage = null,
@@ -603,7 +613,7 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
} else {
prepareRoute(route)
}
updateTripNavigationScreen(surfaceRenderer.lastLocation)
updateNavigationScreen()
}
}
@@ -618,8 +628,7 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
}
surfaceRenderer.setRouteData(routeModel.curRoute.routeGeoJson)
startNavigation()
updateTripNavigationScreen(surfaceRenderer.lastLocation)
//navigationScreen.updateTrip(surfaceRenderer.lastLocation)
updateNavigationScreen()
}
/**
@@ -630,8 +639,7 @@ class NavigationSession : Session(), NavigationListener, NavigationObserverCallb
newRouteModel.navState = routeModel.navState.copy(routingEngine = routingEngine)
newRouteModel.startNavigation(route)
routeModel.curRoute.summary.trafficDelay = newRouteModel.curRoute.summary.trafficDelay
//navigationScreen.updateTrip(surfaceRenderer.lastLocation)
updateTripNavigationScreen(surfaceRenderer.lastLocation)
updateNavigationScreen()
}

View File

@@ -115,8 +115,9 @@ class Simulation {
updateLocation(fakeLocation)
// Wait before moving to the next point (e.g., every 1 second)
if (duration > 100) {
delay(duration / 4)
// delay(duration / 4)
}
delay(1000)
lastTime = p.time
lastLocation = fakeLocation
}

View File

@@ -65,8 +65,6 @@ open class NavigationScreen(
val settingsViewModel = getSettingsViewModel(carContext)
private var distanceMode = 0
private var tripSuggestion = false
private var tripSuggestionCalled = false
@@ -76,25 +74,15 @@ open class NavigationScreen(
private var isNavigating = false
private var isRerouting = false
private var hasArrived = false
private lateinit var destinations: MutableList<Destination>
private lateinit var stepRemainingDistance: Distance
private lateinit var destinationTravelEstimate: TravelEstimate
private lateinit var stepTravelEstimate: TravelEstimate
private var shouldShowNextStep = false
private var shouldShowLanes = false
private lateinit var steps: MutableList<Step>
var junctionImage: CarIcon? = null
var backGroundColor = CarColor.BLUE
private var junctionImage: CarIcon? = null
private var backGroundColor = CarColor.BLUE
val observerRecentPlaces = Observer<List<Place>> { newPlaces ->
recentPlaces.addAll(newPlaces)
if (newPlaces.isNotEmpty() && !tripSuggestionCalled) {
@@ -108,9 +96,6 @@ open class NavigationScreen(
lifecycleScope.launch {
settingsViewModel.tripSuggestion.first()
}
repository.distanceModeFlow.asLiveData().observe(this, Observer {
distanceMode = it
})
repository.tripSuggestionFlow.asLiveData().observe(this, Observer {
navigationViewModel.recentPlaces.observe(this, observerRecentPlaces)
@@ -481,7 +466,6 @@ open class NavigationScreen(
* Initiates recalculation for a new route to the destination.
*/
fun calculateNewRoute(destination: Place) {
stopNavigation()
navigationType = NavigationType.REROUTE
invalidate()
val mainThreadHandler = Handler(carContext.mainLooper)
@@ -511,7 +495,6 @@ open class NavigationScreen(
)
}
/**
* Updates navigation state with the current location, checks for arrival, and traffic updates.
*/
@@ -523,7 +506,7 @@ open class NavigationScreen(
steps: MutableList<Step>,
destinationTravelEstimate: TravelEstimate,
stepTravelEstimate: TravelEstimate,
nextStepRemainingDistance: Distance,
stepRemainingDistance: Distance,
shouldShowNextStep: Boolean,
shouldShowLanes: Boolean,
junctionImage: CarIcon?,
@@ -534,7 +517,7 @@ open class NavigationScreen(
this.hasArrived = hasArrived
this.destinations = destinations
this.steps = steps
stepRemainingDistance = nextStepRemainingDistance
this.stepRemainingDistance = stepRemainingDistance
this.destinationTravelEstimate = destinationTravelEstimate
this.stepTravelEstimate = stepTravelEstimate
this.shouldShowNextStep = shouldShowNextStep