TomTom Routing
This commit is contained in:
@@ -76,6 +76,7 @@ class SurfaceRenderer(
|
||||
val trafficData = MutableLiveData(emptyMap<String, String>())
|
||||
val speedCamerasData = MutableLiveData("")
|
||||
val speed = MutableLiveData(0F)
|
||||
val maxSpeed = MutableLiveData(0)
|
||||
var viewStyle = ViewStyle.VIEW
|
||||
lateinit var centerLocation: Location
|
||||
var previewDistance = 0.0
|
||||
@@ -209,11 +210,12 @@ class SurfaceRenderer(
|
||||
val cameraDuration =
|
||||
duration(viewStyle == ViewStyle.PREVIEW, position!!.bearing, lastBearing)
|
||||
val currentSpeed: Float? by speed.observeAsState()
|
||||
val maxSpeed: Int? by maxSpeed.observeAsState()
|
||||
if (viewStyle == ViewStyle.VIEW || viewStyle == ViewStyle.PAN_VIEW) {
|
||||
DrawNavigationImages(
|
||||
paddingValues,
|
||||
currentSpeed,
|
||||
routeModel,
|
||||
maxSpeed!!,
|
||||
width,
|
||||
height
|
||||
)
|
||||
|
||||
@@ -294,16 +294,16 @@ fun BuildingLayer(tiles: Source) {
|
||||
fun DrawNavigationImages(
|
||||
padding: PaddingValues,
|
||||
speed: Float?,
|
||||
routeModel: RouteModel,
|
||||
maxSpeed: Int,
|
||||
width: Int,
|
||||
height: Int
|
||||
) {
|
||||
NavigationImage(padding, width, height)
|
||||
if (speed != null) {
|
||||
CurrentSpeed(width, height, speed, routeModel.maxSpeed)
|
||||
CurrentSpeed(width, height, speed, maxSpeed)
|
||||
}
|
||||
if (speed != null && routeModel.maxSpeed > 0 && (speed * 3.6) > routeModel.maxSpeed) {
|
||||
MaxSpeed(width, height, routeModel.maxSpeed)
|
||||
if (speed != null && maxSpeed > 0 && (speed * 3.6) > maxSpeed) {
|
||||
MaxSpeed(width, height, maxSpeed)
|
||||
}
|
||||
//DebugInfo(width, height, routeModel)
|
||||
}
|
||||
@@ -470,7 +470,7 @@ fun DebugInfo(
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
val textMeasurerLocation = rememberTextMeasurer()
|
||||
val location = routeModel.location.latitude.toString()
|
||||
val location = routeModel.currentLocation.latitude.toString()
|
||||
val styleSpeed = TextStyle(
|
||||
fontSize = 26.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.kouros.navigation.car.navigation
|
||||
|
||||
import android.location.Location
|
||||
import android.text.SpannableString
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
@@ -98,17 +99,17 @@ class RouteCarModel() : RouteModel() {
|
||||
}
|
||||
|
||||
fun travelEstimate(carContext: CarContext): TravelEstimate {
|
||||
val timeLeft = travelLeftTime()
|
||||
val timeLeft = routeCalculator.travelLeftTime()
|
||||
val timeToDestinationMillis =
|
||||
TimeUnit.SECONDS.toMillis(timeLeft.toLong())
|
||||
val leftDistance = travelLeftDistance() / 1000
|
||||
val leftDistance = routeCalculator.travelLeftDistance() / 1000
|
||||
val displayUnit = if (leftDistance > 1.0) {
|
||||
Distance.UNIT_KILOMETERS
|
||||
} else {
|
||||
Distance.UNIT_METERS
|
||||
}
|
||||
val arrivalTime = DateTimeWithZone.create(
|
||||
arrivalTime(),
|
||||
routeCalculator.arrivalTime(),
|
||||
TimeZone.getTimeZone("Europe/Berlin")
|
||||
)
|
||||
val travelBuilder = TravelEstimate.Builder( // The estimated distance to the destination.
|
||||
@@ -133,99 +134,99 @@ class RouteCarModel() : RouteModel() {
|
||||
return travelBuilder.build()
|
||||
}
|
||||
|
||||
fun addLanes(carContext: CarContext, step: Step.Builder, stepData: StepData) {
|
||||
var laneImageAdded = false
|
||||
stepData.lane.forEach {
|
||||
if (it.indications.isNotEmpty() && it.valid) {
|
||||
Collections.sort<String>(it.indications)
|
||||
var direction = ""
|
||||
it.indications.forEach { it2 ->
|
||||
direction = if (direction.isEmpty()) {
|
||||
it2.trim()
|
||||
} else {
|
||||
"${direction}_${it2.trim()}"
|
||||
fun addLanes(carContext: CarContext, step: Step.Builder, stepData: StepData) {
|
||||
var laneImageAdded = false
|
||||
stepData.lane.forEach {
|
||||
if (it.indications.isNotEmpty() && it.valid) {
|
||||
Collections.sort<String>(it.indications)
|
||||
var direction = ""
|
||||
it.indications.forEach { it2 ->
|
||||
direction = if (direction.isEmpty()) {
|
||||
it2.trim()
|
||||
} else {
|
||||
"${direction}_${it2.trim()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
val laneDirection = addLanes(direction, stepData)
|
||||
if (laneDirection != LaneDirection.SHAPE_UNKNOWN) {
|
||||
if (!laneImageAdded) {
|
||||
step.setLanesImage(createCarIcon(createLaneIcon(carContext, stepData)))
|
||||
laneImageAdded = true
|
||||
val laneDirection = iconMapper.addLanes(direction, stepData)
|
||||
if (laneDirection != LaneDirection.SHAPE_UNKNOWN) {
|
||||
if (!laneImageAdded) {
|
||||
step.setLanesImage(createCarIcon(iconMapper.createLaneIcon(carContext, stepData)))
|
||||
laneImageAdded = true
|
||||
}
|
||||
val laneType =
|
||||
Lane.Builder()
|
||||
.addDirection(LaneDirection.create(laneDirection, false))
|
||||
.build()
|
||||
step.addLane(laneType)
|
||||
}
|
||||
val laneType =
|
||||
Lane.Builder()
|
||||
.addDirection(LaneDirection.create(laneDirection, false))
|
||||
.build()
|
||||
step.addLane(laneType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createString(
|
||||
text: String
|
||||
): SpannableString {
|
||||
val spannableString = SpannableString(text)
|
||||
return spannableString
|
||||
}
|
||||
fun createString(
|
||||
text: String
|
||||
): SpannableString {
|
||||
val spannableString = SpannableString(text)
|
||||
return spannableString
|
||||
}
|
||||
|
||||
fun createCarText(carContext: CarContext, @StringRes stringRes: Int): CarText {
|
||||
return CarText.create(carContext.getString(stringRes))
|
||||
}
|
||||
fun createCarText(carContext: CarContext, @StringRes stringRes: Int): CarText {
|
||||
return CarText.create(carContext.getString(stringRes))
|
||||
}
|
||||
|
||||
fun createCarIcon(carContext: CarContext, @DrawableRes iconRes: Int): CarIcon {
|
||||
return CarIcon.Builder(IconCompat.createWithResource(carContext, iconRes)).build()
|
||||
}
|
||||
fun createCarIcon(carContext: CarContext, @DrawableRes iconRes: Int): CarIcon {
|
||||
return CarIcon.Builder(IconCompat.createWithResource(carContext, iconRes)).build()
|
||||
}
|
||||
|
||||
// fun createCarIcon(iconCompat: IconCompat): CarIcon {
|
||||
// return CarIcon.Builder(iconCompat).build()
|
||||
// }
|
||||
fun createCarIcon(iconCompat: IconCompat): CarIcon {
|
||||
return CarIcon.Builder(iconCompat).build()
|
||||
}
|
||||
|
||||
fun showSpeedCamera(carContext: CarContext, distance: Double, maxSpeed: String) {
|
||||
carContext.getCarService<AppManager?>(AppManager::class.java)
|
||||
.showAlert(
|
||||
createAlert(
|
||||
carContext,
|
||||
maxSpeed,
|
||||
createCarIcon(carContext, R.drawable.speed_camera_24px)
|
||||
fun showSpeedCamera(carContext: CarContext, distance: Double, maxSpeed: String) {
|
||||
carContext.getCarService<AppManager?>(AppManager::class.java)
|
||||
.showAlert(
|
||||
createAlert(
|
||||
carContext,
|
||||
maxSpeed,
|
||||
createCarIcon(carContext, R.drawable.speed_camera_24px)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun createAlert(
|
||||
carContext: CarContext,
|
||||
maxSpeed: String?,
|
||||
icon: CarIcon
|
||||
): Alert {
|
||||
val title = createCarText(carContext, R.string.speed_camera)
|
||||
val subtitle = CarText.create(maxSpeed!!)
|
||||
|
||||
val dismissAction: Action = createToastAction(
|
||||
carContext,
|
||||
R.string.exit_action_title, R.string.exit_action_title,
|
||||
FLAG_DEFAULT
|
||||
)
|
||||
}
|
||||
return Alert.Builder( /* alertId: */0, title, /* durationMillis: */5000)
|
||||
.setSubtitle(subtitle)
|
||||
.setIcon(icon)
|
||||
.addAction(dismissAction).setCallback(object : AlertCallback {
|
||||
override fun onCancel(reason: Int) {
|
||||
}
|
||||
|
||||
fun createAlert(
|
||||
carContext: CarContext,
|
||||
maxSpeed: String?,
|
||||
icon: CarIcon
|
||||
): Alert {
|
||||
val title = createCarText(carContext, R.string.speed_camera)
|
||||
val subtitle = CarText.create(maxSpeed!!)
|
||||
override fun onDismiss() {
|
||||
}
|
||||
}).build()
|
||||
}
|
||||
|
||||
val dismissAction: Action = createToastAction(
|
||||
carContext,
|
||||
R.string.exit_action_title, R.string.exit_action_title,
|
||||
FLAG_DEFAULT
|
||||
)
|
||||
return Alert.Builder( /* alertId: */0, title, /* durationMillis: */5000)
|
||||
.setSubtitle(subtitle)
|
||||
.setIcon(icon)
|
||||
.addAction(dismissAction).setCallback(object : AlertCallback {
|
||||
override fun onCancel(reason: Int) {
|
||||
}
|
||||
|
||||
override fun onDismiss() {
|
||||
}
|
||||
}).build()
|
||||
}
|
||||
|
||||
private fun createToastAction(
|
||||
carContext: CarContext,
|
||||
@StringRes titleRes: Int, @StringRes toastStringRes: Int,
|
||||
flags: Int
|
||||
): Action {
|
||||
return Action.Builder()
|
||||
.setOnClickListener { }
|
||||
.setTitle(createCarText(carContext, titleRes))
|
||||
.setFlags(flags)
|
||||
.build()
|
||||
}
|
||||
private fun createToastAction(
|
||||
carContext: CarContext,
|
||||
@StringRes titleRes: Int, @StringRes toastStringRes: Int,
|
||||
flags: Int
|
||||
): Action {
|
||||
return Action.Builder()
|
||||
.setOnClickListener { }
|
||||
.setTitle(createCarText(carContext, titleRes))
|
||||
.setFlags(flags)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ class NavigationScreen(
|
||||
}
|
||||
|
||||
fun getRoutingInfo(): RoutingInfo {
|
||||
var currentDistance = routeModel.leftStepDistance()
|
||||
var currentDistance = routeModel.routeCalculator.leftStepDistance()
|
||||
val displayUnit = if (currentDistance > 1000.0) {
|
||||
currentDistance /= 1000.0
|
||||
Distance.UNIT_KILOMETERS
|
||||
@@ -496,7 +496,7 @@ class NavigationScreen(
|
||||
|| maneuverType == Maneuver.TYPE_DESTINATION_LEFT
|
||||
|| maneuverType == Maneuver.TYPE_DESTINATION_RIGHT
|
||||
|| maneuverType == Maneuver.TYPE_DESTINATION_STRAIGHT)
|
||||
&& leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
|
||||
&& routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
|
||||
) {
|
||||
stopNavigation()
|
||||
arrived = true
|
||||
|
||||
Reference in New Issue
Block a user