Traffic Android
Setup
Add the following dependencies in the build.gradle
file of your application:
The activity launching Traffic must handle the following configuration changes: orientation|screenSize
declared into your AndroidManifest.xml
:
Implementation
Warning
Make sure to read the modules configuration section before proceeding
This module is set up by calling TrafficUI.getInstance()
. The singleton behaves like a builder in which each method allows you to configure the module. Then, you need to call the init()
method at the end. You should call this method in an Application
subclass.
This method takes the following parameters:
Name | Required | Description | Type | Default |
---|---|---|---|---|
context |
Context in which the module is launched | Context |
||
token |
Get your token | String |
||
configuration |
Module configuration object | TrafficConfiguration |
null |
|
configurationJsonFile |
Module configuration JSON file name | String |
null |
|
onNavigate |
Listener for the navigation between module screens | Unit |
{ _ -> } |
|
onBack |
Listener for the navigation back button click event | Unit |
{ _ -> } |
Example
TrafficUI.getInstance().let { instance ->
instance.init(
context = this,
token = "your_token",
configuration = TrafficConfiguration(
coverage = "your_coverage",
timezone = "Europe/Paris",
env = TrafficEnvironment.PROD,
colors = TrafficColors(
primary = "#88819f"
),
transportCategories = listOf<TrafficTransportCategory>()
)
)
}
Navigation listener
Since the module launches its own fragments, you may want your application to be aware of navigation events.
For that, you have to set a navigation listener by calling this method before init()
.
trafficNavigationListenerImpl
should be the class instance implementingTrafficNavigationListener
interface.
This interface gives you the method onBack()
for any back event between two fragments and the method onNavigate
for the reverse.
Each method has a TrafficNavigationListener.Event
parameter you can rely on.
// Navigation events
ALL_DISRUPTIONS_BACK_TO_EXTERNAL
ALL_DISRUPTIONS_TO_AUTO_COMPLETION
ALL_DISRUPTIONS_TO_DISRUPTION
ALL_DISRUPTIONS_TO_MY_ALERTS
AUTO_COMPLETION_BACK_TO_ALL_DISRUPTIONS
AUTO_COMPLETION_TO_EDIT_ALERT
DISRUPTION_BACK_TO_ALL_DISRUPTIONS
EDIT_ALERT_BACK_TO_AUTO_COMPLETION
EDIT_ALERT_BACK_TO_ALL_DISRUPTIONS
EXTERNAL_TO_TRAFFIC
MY_ALERTS_BACK_TO_ALL_DISRUPTIONS
MY_ALERTS_TO_AUTO_COMPLETION
MY_ALERTS_TO_EDIT_ALERT
Alert subscription
To enable the alert subscription feature, the following instructions are required:
- Add the environment configuration
- Pass the Kronos API credentials to the initialization method
- Set the firebase token TrafficUI.getInstance().firebaseToken("token")
once received from the Firebase API at runtime
Traffic alert subscription credentials
Name | Required | Description | Type |
---|---|---|---|
username |
Kronos authentication username | String |
|
password |
Kronos authentication password | String |
Events tracking
In order to receive the list of generated events within Traffic module, you have to attach the tracker to the module instance.
You can call this method before or after init()
.
trafficTrackerImpl
should be the class instance implementingTrafficTracker
interface.
Launching
Traffic has a single entry point AllDisruptionsFragment
.
Assuming you have an Activity
with a fragment container, refer to the following example to launch the entry screen fragment:
supportFragmentManager.beginTransaction().run {
replace(
R.id.container_id,
AllDisruptionsFragment.newInstance(showBack = false),
"TAG"
)
addToBackStack("TAG")
commit()
}
The newInstance()
method creates an instance of the target fragment and takes the following parameters:
Name | Required | Description | Type | Default |
---|---|---|---|---|
showBack |
Show/hide back button on the first screen | Boolean |
false |
Theming
The module uses graphical components from Material Design 3. To ensure these components function correctly and get displayed properly on the screen, it is crucial to apply the appropriate parent theme:
- Replace by the specific theme. For example:
Theme.Material3.Light.NoActionBar