Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NavFragmentActivity : AppCompatActivity() {
private var pendingNavActions = mutableListOf<InitializedNavRunnable>()
private var arrivalListener: Navigator.ArrivalListener? = null
private var routeChangedListener: Navigator.RouteChangedListener? = null
private var navigationSessionListener: Navigator.NavigationSessionListener? = null

private lateinit var navFragment: SupportNavigationFragment
private var navInfoDisplayFragment: Fragment? = null
Expand Down Expand Up @@ -187,6 +188,14 @@ class NavFragmentActivity : AppCompatActivity() {
showToast("onRouteChanged: the driver's route changed")
}
navigator.addRouteChangedListener(routeChangedListener)

navigationSessionListener =
Navigator.NavigationSessionListener {
// Enable voice audio guidance (through the device speaker)
navigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)
}

navigator.addNavigationSessionListener(navigationSessionListener)
}
}

Expand Down Expand Up @@ -221,9 +230,6 @@ class NavFragmentActivity : AppCompatActivity() {
// Hide the toolbar to maximize the navigation UI
actionBar?.hide()

// Enable voice audio guidance (through the device speaker)
navigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)

// Simulate vehicle progress along the route (for demo/debug builds)
if (BuildConfig.DEBUG) {
navigator.simulator.simulateLocationsAlongExistingRoute(
Expand Down Expand Up @@ -357,6 +363,10 @@ class NavFragmentActivity : AppCompatActivity() {
navigator.removeRouteChangedListener(routeChangedListener)
}

if (navigationSessionListener != null) {
navigator.removeNavigationSessionListener(navigationSessionListener)
}

navigator.simulator.unsetUserLocation()
navigator.cleanup()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class NavViewActivity : AppCompatActivity() {
var pendingNavActions = mutableListOf<InitializedNavRunnable>()
private var arrivalListener: Navigator.ArrivalListener? = null
private var routeChangedListener: Navigator.RouteChangedListener? = null
private var navigationSessionListener: Navigator.NavigationSessionListener? = null

// Only used to demo the turn-by-turn nav forwarding feature.
var navInfoDisplayFragment: Fragment? = null
Expand Down Expand Up @@ -192,6 +193,14 @@ class NavViewActivity : AppCompatActivity() {
showToast("onRouteChanged: the driver's route changed")
}
navigator.addRouteChangedListener(routeChangedListener)

navigationSessionListener =
Navigator.NavigationSessionListener {
// Enable voice audio guidance (through the device speaker)
navigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)
}

navigator.addNavigationSessionListener(navigationSessionListener)
}
}

Expand Down Expand Up @@ -226,9 +235,6 @@ class NavViewActivity : AppCompatActivity() {
// Hide the toolbar to maximize the navigation UI
actionBar?.hide()

// Enable voice audio guidance (through the device speaker)
navigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)

// Simulate vehicle progress along the route (for demo/debug builds)
if (BuildConfig.DEBUG) {
navigator.simulator.simulateLocationsAlongExistingRoute(
Expand Down Expand Up @@ -297,6 +303,10 @@ class NavViewActivity : AppCompatActivity() {
navigator.removeRouteChangedListener(routeChangedListener)
}

if (navigationSessionListener != null) {
navigator.removeNavigationSessionListener(navigationSessionListener)
}

navigator.simulator?.unsetUserLocation()
navigator.cleanup()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
private lateinit var mapFragment: SupportMapFragment
private lateinit var navigationFragment: SupportNavigationFragment
private var arrivalListener: Navigator.ArrivalListener? = null
private var navigationSessionListener: Navigator.NavigationSessionListener? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -148,9 +149,6 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
// Hide the toolbar to maximize the navigation UI
actionBar?.hide()

// Enable voice audio guidance (through the device speaker)
navigator?.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)

// Simulate vehicle progress along the route (for demo/debug builds)
if (BuildConfig.DEBUG) {
navigator
Expand Down Expand Up @@ -197,7 +195,7 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
}
}

private fun registerArrivalListener() {
private fun registerListeners() {
arrivalListener =
Navigator.ArrivalListener {
showToast("User has arrived at the destination!")
Expand All @@ -212,6 +210,14 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
stopTripAndShowMapFragment(/* unused= */ null)
}
navigator?.addArrivalListener(arrivalListener)

navigationSessionListener =
Navigator.NavigationSessionListener {
// Enable voice audio guidance (through the device speaker)
navigator?.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)
}

navigator?.addNavigationSessionListener(navigationSessionListener)
}

// Detaches old fragment and adds a new fragment to the activity if it's not added otherwise
Expand Down Expand Up @@ -240,6 +246,10 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
if (arrivalListener != null) {
navigator?.removeArrivalListener(arrivalListener)
}
if (navigationSessionListener != null) {
navigator?.removeNavigationSessionListener(navigationSessionListener)
}

navigator?.simulator?.unsetUserLocation()
navigator?.cleanup()
super.onDestroy()
Expand Down Expand Up @@ -267,7 +277,7 @@ class SwappingMapAndNavActivity : AppCompatActivity() {
if (swappingMapAndNavActivity != null) {
swappingMapAndNavActivity.navigator = navigator
// Register an arrival listener that returns back to a top-down map once the trip is over.
swappingMapAndNavActivity.registerArrivalListener()
swappingMapAndNavActivity.registerListeners()
}
}

Expand Down