feat!: Application outline
This commit is contained in:
parent
80dfa6ab4e
commit
01fbf32042
9 changed files with 1440 additions and 190 deletions
73
app/src/main/java/eu/ztsh/garmin/mock/ReplayResources.kt
Normal file
73
app/src/main/java/eu/ztsh/garmin/mock/ReplayResources.kt
Normal file
|
@ -0,0 +1,73 @@
|
|||
package eu.ztsh.garmin.mock
|
||||
|
||||
import com.mapbox.api.directions.v5.models.DirectionsRoute
|
||||
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
|
||||
import com.mapbox.navigation.core.MapboxNavigation
|
||||
import com.mapbox.navigation.core.replay.route.ReplayProgressObserver
|
||||
import com.mapbox.navigation.core.replay.route.ReplayRouteMapper
|
||||
import eu.ztsh.garmin.mapbox.MapControl
|
||||
import java.util.*
|
||||
|
||||
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
|
||||
class ReplayResources(private val mapControl: MapControl) {
|
||||
|
||||
/**
|
||||
* Debug observer that makes sure the replayer has always an up-to-date information to generate mock updates.
|
||||
*/
|
||||
private lateinit var replayProgressObserver: ReplayProgressObserver
|
||||
|
||||
/**
|
||||
* Debug object that converts a route into events that can be replayed to navigate a route.
|
||||
*/
|
||||
private val replayRouteMapper = ReplayRouteMapper()
|
||||
|
||||
fun replayOriginLocation() {
|
||||
with(mapControl.mapboxNavigation().mapboxReplayer) {
|
||||
play()
|
||||
pushEvents(
|
||||
listOf(
|
||||
ReplayRouteMapper.mapToUpdateLocation(
|
||||
Date().time.toDouble(),
|
||||
com.mapbox.geojson.Point.fromLngLat(-122.39726512303575, 37.785128345296805)
|
||||
)
|
||||
)
|
||||
)
|
||||
playFirstLocation()
|
||||
}
|
||||
}
|
||||
|
||||
fun startSimulation(route: DirectionsRoute) {
|
||||
with(mapControl.mapboxNavigation()) {
|
||||
mapboxReplayer.stop()
|
||||
mapboxReplayer.clearEvents()
|
||||
val replayData = replayRouteMapper.mapDirectionsRouteGeometry(route)
|
||||
mapboxReplayer.pushEvents(replayData)
|
||||
mapboxReplayer.seekTo(replayData[0])
|
||||
mapboxReplayer.play()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopSimulation() {
|
||||
with(mapControl.mapboxNavigation()) {
|
||||
mapboxReplayer.stop()
|
||||
mapboxReplayer.clearEvents()
|
||||
}
|
||||
}
|
||||
|
||||
fun onAttached(mapboxNavigation: MapboxNavigation) {
|
||||
replayProgressObserver = ReplayProgressObserver(mapboxNavigation.mapboxReplayer)
|
||||
mapboxNavigation.registerRouteProgressObserver(replayProgressObserver)
|
||||
|
||||
// Start the trip session to being receiving location updates in free drive
|
||||
// and later when a route is set also receiving route progress updates.
|
||||
// In case of `startReplayTripSession`,
|
||||
// location events are emitted by the `MapboxReplayer`
|
||||
mapboxNavigation.startReplayTripSession()
|
||||
}
|
||||
|
||||
fun onDetached(mapboxNavigation: MapboxNavigation) {
|
||||
mapboxNavigation.unregisterRouteProgressObserver(replayProgressObserver)
|
||||
mapboxNavigation.mapboxReplayer.finish()
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue