Diverse Änderungen

This commit is contained in:
Dimitris
2025-11-28 11:42:41 +01:00
parent c79fd157e4
commit 5ca9e4b174
43 changed files with 217 additions and 581 deletions

View File

@@ -15,6 +15,8 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.vectorResource
@@ -45,7 +47,13 @@ import org.maplibre.spatialk.geojson.Position
@Composable
fun cameraState(width: Int, height: Int, position: CameraPosition?, tilt: Double, preview: Boolean): CameraState {
fun cameraState(
width: Int,
height: Int,
position: CameraPosition?,
tilt: Double,
preview: Boolean
): CameraState {
val padding = getPaddingValues(width, height, preview)
return rememberCameraState(
firstPosition =
@@ -118,12 +126,13 @@ fun DrawImage(location: Location) {
Box(
modifier = Modifier
.size(48.dp, 48.dp)
.padding(start = 450.dp - 30.dp, top = 350.dp - 30.dp)
.drawBehind {
with(painter) {
draw(
size = Size(60F, 60F),
colorFilter = tint
colorFilter = tint,
)
}
})
@@ -145,7 +154,6 @@ fun DrawImage(location: Location) {
drawText(measuredText)
}
}
.fillMaxSize()
)
}

View File

@@ -23,9 +23,11 @@ import com.kouros.navigation.car.screen.NavigationScreen
import com.kouros.navigation.car.screen.RequestPermissionScreen
import com.kouros.navigation.car.screen.SearchScreen
import com.kouros.navigation.data.Constants.MAXIMAL_ROUTE_DEVIATION
import com.kouros.navigation.data.Constants.MAXIMAL_SNAP_CORRECTION
import com.kouros.navigation.data.Constants.TAG
import com.kouros.navigation.data.ObjectBox
import com.kouros.navigation.utils.NavigationUtils.snapLocation
import com.kouros.navigation.utils.location
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -44,7 +46,7 @@ class NavigationSession : Session(), NavigationScreen.Listener {
var locationIndex = 0
val simulate = true
val simulate = false
var mLocationListener: LocationListenerCompat = LocationListenerCompat { location: Location? ->
updateLocation(location)
@@ -160,7 +162,7 @@ class NavigationSession : Session(), NavigationScreen.Listener {
updateLocation(location)
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
/* minTimeMs= */ 100,
/* minTimeMs= */ 500,
/* minDistanceM= */ 0f,
mLocationListener
)
@@ -179,18 +181,13 @@ class NavigationSession : Session(), NavigationScreen.Listener {
fun simulate(location: Location?) {
if (routeModel.isNavigating() && locationIndex < routeModel.route.waypoints.size) {
coroutineScope.launch {
delay(
100
)
if (locationIndex >= routeModel.route.waypoints.size) {
return@launch
}
val loc = routeModel.route.waypoints[locationIndex]
val curLocation = Location(LocationManager.GPS_PROVIDER)
if ( locationIndex == 1500) {
curLocation.longitude = loc[0] + 0.003
curLocation.latitude = loc[1] + 0.003
} else {
curLocation.longitude = loc[0]
curLocation.latitude = loc[1]
}
curLocation.longitude = loc[0]// + 0.00001 * locationIndex
curLocation.latitude = loc[1] //+ 0.00001 * locationIndex
curLocation.speed = 15F
update(curLocation)
locationIndex += 1
@@ -207,12 +204,22 @@ class NavigationSession : Session(), NavigationScreen.Listener {
fun update(location: Location) {
if (routeModel.isNavigating()) {
val snapedLocation = snapLocation(location, routeModel.route.maneuverLocations())
val distance = location.distanceTo(snapedLocation)
println(distance)
if (distance > MAXIMAL_ROUTE_DEVIATION) {
// navigationScreen.calculateNewRoute()
//return
}
routeModel.updateLocation(location)
navigationScreen.updateTrip()
}
val result = surfaceRenderer.updateLocation(location)
if (!result) {
navigationScreen.stopNavigation()
if (distance < MAXIMAL_SNAP_CORRECTION) {
surfaceRenderer.updateLocation(snapedLocation)
} else {
surfaceRenderer.updateLocation(location)
}
} else {
surfaceRenderer.updateLocation(location)
}
}

View File

@@ -26,6 +26,7 @@ import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.kouros.navigation.car.navigation.RouteCarModel
import com.kouros.navigation.data.Constants
import com.kouros.navigation.data.Constants.MAXIMAL_ROUTE_DEVIATION
import com.kouros.navigation.data.Constants.NEXT_STEP_THRESHOLD
import com.kouros.navigation.data.Constants.SHOW_THREED_BUILDING
import com.kouros.navigation.model.RouteModel
import com.kouros.navigation.utils.NavigationUtils.getBooleanKeyValue
@@ -189,7 +190,7 @@ class SurfaceRenderer(
@Composable
fun ShowPosition(cameraState: CameraState, position: CameraPosition?) {
var cameraDuration = duration(position)
val cameraDuration = duration(position)
var bearing = position!!.bearing
var zoom = position.zoom
var target = position.target
@@ -197,9 +198,8 @@ class SurfaceRenderer(
if (!preview) {
DrawImage(lastLocation)
} else {
cameraDuration = 3.seconds
bearing = 0.0
zoom = 11.0
zoom = previewZoom()
target = Position(centerLocation.longitude, centerLocation.latitude)
localTilt = 0.0
}
@@ -224,10 +224,13 @@ class SurfaceRenderer(
}
private fun duration(position: CameraPosition?): Duration {
if (preview) {
return 3.seconds
}
val cameraDuration = if ((lastBearing - position!!.bearing).absoluteValue > 20.0) {
0.4.seconds
2.seconds
} else {
1.seconds
2.seconds
}
return cameraDuration
}
@@ -250,31 +253,24 @@ class SurfaceRenderer(
}
}
fun updateLocation(location: Location) : Boolean {
fun updateLocation(location: Location) {
synchronized(this) {
if (!preview) {
var snapedLocation = location
var bearing: Double
bearing = cameraPosition.value!!.bearing
var bearing = cameraPosition.value!!.bearing
if (routeModel.isNavigating()) {
snapedLocation = snapLocation(location, routeModel.route.maneuverLocations())
bearing = routeModel.currentStep().bearing
if (snapedLocation.longitude == 0.0) {
//reRoute()
return false
}
}
val zoom = if (!panView) {
calculateZoom(snapedLocation.speed.toDouble())
calculateZoom(location.speed.toDouble())
} else {
cameraPosition.value!!.zoom
}
updateCameraPosition(bearing, zoom, Position(snapedLocation.longitude, snapedLocation.latitude))
updateCameraPosition(bearing, zoom, Position(location.longitude, location.latitude))
lastBearing = cameraPosition.value!!.bearing
lastLocation = snapedLocation
lastLocation = location
} else {
val bearing = 0.0
val zoom = 14.0
val zoom = previewZoom()
updateCameraPosition(
bearing,
zoom,
@@ -282,7 +278,6 @@ class SurfaceRenderer(
)
}
}
return true
}
private fun updateCameraPosition(bearing: Double, zoom: Double, target: Position) {
@@ -310,6 +305,23 @@ class SurfaceRenderer(
preview = true
}
private fun previewZoom(): Double {
if (routeModel.isNavigating()) {
when (routeModel.route.distance) {
in 0.0..10.0 -> {
return 14.0
}
in 10.0..20.0 -> {
return 12.0
}
in 20.0..30.0 -> {
return 11.0
}
}
}
return 10.0
}
companion
object {
private const val TAG = "MapRenderer"

View File

@@ -1,13 +1,7 @@
package com.kouros.navigation.car.navigation
import android.R
import android.app.Activity
import android.location.Location
import android.os.Bundle
import android.os.Environment
import android.view.Menu
import android.view.View
import android.widget.TextView
import org.xml.sax.SAXException
import java.io.File
import java.io.FileInputStream

View File

@@ -86,11 +86,7 @@ class RouteCarModel() : RouteModel() {
when (distanceLeft) {
in 0.0..NEXT_STEP_THRESHOLD -> {
return null
// if (maneuver.streetNames != null && maneuver.streetNames!!.isNotEmpty()) {
// text = maneuver.streetNames!![0]
// }
}
else -> {
if (maneuver.streetNames != null && maneuver.streetNames!!.isNotEmpty()) {
text = maneuver.streetNames!![0]
@@ -118,6 +114,7 @@ class RouteCarModel() : RouteModel() {
type = Maneuver.TYPE_STRAIGHT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_name_change)
}
ManeuverType.Destination.value,
ManeuverType.DestinationRight.value,
ManeuverType.DestinationLeft.value,
@@ -125,35 +122,51 @@ class RouteCarModel() : RouteModel() {
type = Maneuver.TYPE_DESTINATION
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_destination)
}
ManeuverType.Right.value -> {
type = Maneuver.TYPE_TURN_NORMAL_RIGHT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_normal_right)
}
ManeuverType.Left.value -> {
type = Maneuver.TYPE_TURN_NORMAL_LEFT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_normal_left)
}
ManeuverType.RampRight.value -> {
type = Maneuver.TYPE_OFF_RAMP_SLIGHT_RIGHT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_slight_right)
}
ManeuverType.RampLeft.value -> {
type = Maneuver.TYPE_TURN_NORMAL_LEFT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_normal_left)
}
ManeuverType.ExitRight.value -> {
type = Maneuver.TYPE_TURN_SLIGHT_RIGHT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_slight_right)
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_slight_right)
}
ManeuverType.StayRight.value -> {
type = Maneuver.TYPE_KEEP_RIGHT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_name_change)
}
ManeuverType.StayLeft.value -> {
type = Maneuver.TYPE_KEEP_LEFT
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_name_change)
}
ManeuverType.RoundaboutEnter.value -> {
type = Maneuver.TYPE_ROUNDABOUT_ENTER_CCW
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_roundabout_ccw)
}
ManeuverType.RoundaboutExit.value -> {
type = Maneuver.TYPE_ROUNDABOUT_EXIT_CCW
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_roundabout_ccw)
}
}
maneuverType = type
return Pair(type, currentTurnIcon)

View File

@@ -5,6 +5,8 @@ import android.content.Intent
import android.location.Location
import android.location.LocationManager
import android.os.CountDownTimer
import android.os.Handler
import android.os.Looper
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.model.Action
@@ -46,6 +48,8 @@ class NavigationScreen(
}
var currentNavigationLocation = Location(LocationManager.GPS_PROVIDER)
var calculateNewRoute = false
val vieModel = ViewModel(NavigationRepository())
val observer = Observer<String> { route ->
if (route.isNotEmpty()) {
@@ -80,7 +84,11 @@ class NavigationScreen(
.build()
)
return if (routeModel.isNavigating()) {
getNavigationTemplate(actionStripBuilder)
if (calculateNewRoute) {
getNavigationLoadingTemplate(actionStripBuilder)
} else {
getNavigationTemplate(actionStripBuilder)
}
} else {
getNavigationEndTemplate(actionStripBuilder)
}
@@ -155,6 +163,14 @@ class NavigationScreen(
}
}
fun getNavigationLoadingTemplate(actionStripBuilder: ActionStrip.Builder): NavigationTemplate {
return NavigationTemplate.Builder()
.setNavigationInfo(RoutingInfo.Builder().setLoading(true).build())
.setActionStrip(actionStripBuilder.build())
.setBackgroundColor(CarColor.SECONDARY)
.build()
}
fun getRoutingInfo(): RoutingInfo {
var currentDistance = routeModel.currentDistance
val displayUnit = if (currentDistance > 1000.0) {
@@ -281,6 +297,21 @@ class NavigationScreen(
invalidate()
}
fun calculateNewRoute() {
calculateNewRoute = true
invalidate()
val mainThreadhandler = Handler(carContext.mainLooper)
mainThreadhandler.post {
object : CountDownTimer(5000, 1000) {
override fun onTick(millisUntilFinished: Long) { }
override fun onFinish() {
calculateNewRoute = false
stopNavigation()
}
}.start()
}
}
fun reRoute() {
NavigationMessage(carContext).createAlert()
vieModel.loadRoute(surfaceRenderer.lastLocation, currentNavigationLocation)
@@ -293,4 +324,4 @@ class NavigationScreen(
}
invalidate()
}
}
}

View File

@@ -17,7 +17,7 @@ import com.kouros.navigation.data.Category
import com.kouros.navigation.data.Constants
import com.kouros.navigation.data.NavigationRepository
import com.kouros.navigation.data.Place
import com.kouros.navigation.data.nominatim.Search
import com.kouros.navigation.data.nominatim.SearchResult
import com.kouros.navigation.model.ViewModel
@@ -34,9 +34,9 @@ class SearchScreen(
Category(id = Constants.CONTACTS, name = carContext.getString(R.string.contacts))
)
lateinit var searchResult: Search
lateinit var searchResult: List<SearchResult>
val observer = Observer<Search> { newSearch ->
val observer = Observer<List<SearchResult>> { newSearch ->
println(newSearch)
searchResult = newSearch
invalidate()
@@ -93,13 +93,9 @@ class SearchScreen(
return SearchTemplate.Builder(
object : SearchCallback {
override fun onSearchTextChanged(searchText: String) {
//doSearch(searchText, searchItemListBuilder)
}
override fun onSearchSubmitted(searchTerm: String) {
isSearchComplete = true
viewModel.searchPlaces(searchTerm)
viewModel.searchPlaces(searchTerm, location)
}
})
.setHeaderAction(Action.BACK)
@@ -111,15 +107,9 @@ class SearchScreen(
@SuppressLint("DefaultLocale")
fun doSearch(searchItemListBuilder: ItemList.Builder) {
searchResult.forEach {
println(it.displayName)
//val name: String = address.getAddressLine(0)
//addressLocation.latitude = address.latitude
//adressLocation.longitude = address.longitude
//val distance = location.distanceTo(addressLocation)
//val dist = String.format("%.1f", (distance / 1000))
searchItemListBuilder.addItem(
Row.Builder()
.setTitle(it.displayName)
.setTitle("${(it.distance/1000).toInt()} km ${it.displayName} ")
.setOnClickListener {
val place = Place(
name = it.displayName,
@@ -127,7 +117,8 @@ class SearchScreen(
longitude = it.lon.toDouble(),
street = it.address.road,
city = it.address.city,
postalCode = it.address.postcode
postalCode = it.address.postcode,
distance = it.distance
)
setResult(place)
finish()
@@ -136,8 +127,6 @@ class SearchScreen(
.build()
)
}
// val itemList = searchItemListBuilder.build()
invalidate()
}
}