Navigation events
Navigation SDK UX Framework exposes the set of the NavigationEvents
to observe transitions between navigation states.
There are Navigation Events which can be observed from UX Framework:
OnFreeDrive
. The event is fired when the navigation system switches to theFreeDrive
state or when it is in theFreeDrive
state during the subscription.OnNavigationStart
. The event is fired when navigation starts.OnNavigationCancel
. The event is fired when navigation is canceled from any state except final destination Arrival.OnNavigationEnd
. The event is fired when navigation has ended after arriving at the final destination.OnOffRoute
. The event is fired when navigation system detects off-route.OnWaypointArrival
. The event is fired when navigation arrives at an intermediate waypoint..OnWaypointPass
. The event is fired when an intermediate waypoint is passed, and navigation continues to the next waypoint.OnDestinationArrival
. The event is fired when navigation arrives at the final destination..
The host application can observe the Navigation Event changes through the Dash.controller
instance.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeNavigationEvents()
.collect { /* NavigationEvent */ event ->
// Do something with the NavigationEvent
processNavigationEvents(event)
}
}
}
}
fun processNavigationEvents(event: NavigationEvent) {
when (event) {
is NavigationEvent.OnFreeDrive ->
Toast.makeText(
this,
"App switched to the FreeDrive mode",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnNavigationStart ->
Toast.makeText(
this,
"Navigation was started",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnNavigationCancel ->
Toast.makeText(
this,
"Navigation was cancelled before the arrival to the destination point",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnNavigationEnd ->
Toast.makeText(
this,
"Navigation was ended because of the arrival to the destination point",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnOffRoute ->
Toast.makeText(
this,
"You are off-route",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnWaypointArrival ->
Toast.makeText(
this,
"You are arrived to the intermediate waypoint",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnWaypointPass ->
Toast.makeText(
this,
"Moving to the next waypoint",
Toast.LENGTH_SHORT
).show()
is NavigationEvent.OnDestinationArrival ->
Toast.makeText(
this,
"Arriving to the final destination",
Toast.LENGTH_SHORT
).show()
}
}
}
Was this page helpful?