Merge remote-tracking branch 'origin/mapbox' into mapbox

This commit is contained in:
Piotr Dec 2024-07-30 18:01:30 +02:00
commit 73719bbedf
Signed by: stawros
GPG key ID: F89F27AD8F881A91
15 changed files with 961 additions and 268 deletions

View file

@ -33,71 +33,31 @@ class MainActivity : AppCompatActivity() {
lateinit var garmin: Garmin
private lateinit var binding: ActivityMainBinding
private val mapboxObserver = MapboxObserver()
init {
lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onResume(owner: LifecycleOwner) {
MapboxNavigationApp.attach(owner)
MapboxNavigationApp.registerObserver(mapboxObserver)
}
override fun onPause(owner: LifecycleOwner) {
MapboxNavigationApp.detach(owner)
MapboxNavigationApp.unregisterObserver(mapboxObserver)
}
})
}
private val mapboxToolbox = MapboxToolbox(lifecycle, this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
if (!MapboxNavigationApp.isSetup()) {
MapboxNavigationApp.setup {
NavigationOptions.Builder(applicationContext)
.accessToken(BuildConfig.MAPBOX_DOWNLOADS_TOKEN)
.build()
}
}
MapboxNavigationApp.current()?.startTripSession()
mapboxToolbox.onCreate()
bluetoothInit()
}
override fun onStart() {
super.onStart()
MapboxNavigationApp.current()?.registerRouteProgressObserver(routeProgressObserver)
mapboxToolbox.onStart()
}
override fun onStop() {
super.onStop()
MapboxNavigationApp.current()?.unregisterRouteProgressObserver(routeProgressObserver)
mapboxToolbox.onStop()
}
override fun onDestroy() {
super.onDestroy()
MapboxNavigationApp.current()?.stopTripSession()
maneuverApi.cancel()
mapboxToolbox.onDestroy()
}
// Define distance formatter options
private val distanceFormatter: DistanceFormatterOptions by lazy {
DistanceFormatterOptions.Builder(this).build()
}
// Create an instance of the Maneuver API
private val maneuverApi: MapboxManeuverApi by lazy {
MapboxManeuverApi(MapboxDistanceFormatter(distanceFormatter))
}
private val routeProgressObserver =
RouteProgressObserver { routeProgress ->
maneuverApi.getManeuvers(routeProgress).value?.apply {
garmin.process(
this[0]
)
}
}
private fun bluetoothInit() {
val bluetoothManager: BluetoothManager = getSystemService(BluetoothManager::class.java)
val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter