AnnouncementListener
Used to inform the caller that a new announcement that should be played has been generated.
To listen to the announcement updates, implement this interface to create a listener, for instance:
val announcementListener = AnnouncementListener { announcements ->
// Implement the necessary functionality for handling the new announcements.
}Content copied to clipboard
Subsequently, add this listener using TomTomNavigation.addAnnouncementListener. To stop listening to the announcement updates, remove the listener using TomTomNavigation.removeAnnouncementListener.
To migrate to this listener from the GuidanceUpdatedListener, while leaving the other logic intact, one can use the following code:
import com.tomtom.sdk.navigation.announcement.GuidanceAnnouncement
import com.tomtom.sdk.navigation.guidance.GuidanceAnnouncement as LegacyGuidanceAnnouncement
val announcementListener = AnnouncementListener { announcements ->
announcements
.filterIsInstance<GuidanceAnnouncement>()
.map { it.toLegacyGuidanceAnnouncement() }
.let { // use the same logic from the GuidanceUpdatedListener }
}
private fun GuidanceAnnouncement.toLegacyGuidanceAnnouncement(): LegacyGuidanceAnnouncement {
return LegacyGuidanceAnnouncement(
id = this.id,
announcementType = this.toAnnouncementType(),
ssmlMessage = this.message.ssmlMessage,
language = this.message.language,
)
}
private fun GuidanceAnnouncement.toAnnouncementType(): AnnouncementType {
return when (this) {
is GuidanceAnnouncement.Follow -> AnnouncementType.GuidanceFollow
is GuidanceAnnouncement.Main -> AnnouncementType.GuidanceMain
is GuidanceAnnouncement.Early -> AnnouncementType.GuidanceEarly
is GuidanceAnnouncement.Confirmation -> AnnouncementType.GuidanceConfirmation
is GuidanceAnnouncement.FarAway -> AnnouncementType.GuidanceFarAway
else -> throw IllegalArgumentException("Unsupported announcement type: $this")
}
}Content copied to clipboard