chore: MapboxToolbox removed
MapControl took most Toolbox functionalities
This commit is contained in:
parent
6b6cffc87f
commit
5f854b883f
2 changed files with 0 additions and 108 deletions
|
@ -51,7 +51,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
mapControl.initNavigation()
|
mapControl.initNavigation()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
private val mapboxToolbox = MapboxToolbox(lifecycle, this)
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -67,26 +66,15 @@ class MainActivity : AppCompatActivity() {
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
mapboxToolbox.onCreate()
|
|
||||||
bluetoothInit()
|
bluetoothInit()
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
|
||||||
super.onStart()
|
|
||||||
mapboxToolbox.onStart()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStop() {
|
|
||||||
super.onStop()
|
|
||||||
mapboxToolbox.onStop()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
mapControl.onDestroy()
|
mapControl.onDestroy()
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
mapboxToolbox.onDestroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bluetoothInit() {
|
private fun bluetoothInit() {
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
package eu.ztsh.garmin
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.location.Location
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import com.mapbox.navigation.base.formatter.DistanceFormatterOptions
|
|
||||||
import com.mapbox.navigation.base.options.NavigationOptions
|
|
||||||
import com.mapbox.navigation.core.formatter.MapboxDistanceFormatter
|
|
||||||
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
|
|
||||||
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
|
||||||
import com.mapbox.navigation.core.trip.session.LocationObserver
|
|
||||||
import com.mapbox.navigation.core.trip.session.NavigationSessionState
|
|
||||||
import com.mapbox.navigation.core.trip.session.NavigationSessionStateObserver
|
|
||||||
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
|
|
||||||
import com.mapbox.navigation.ui.maneuver.api.MapboxManeuverApi
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
class MapboxToolbox(lifecycle: Lifecycle, private val context: MainActivity) {
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onCreate() {
|
|
||||||
if (!MapboxNavigationApp.isSetup()) {
|
|
||||||
MapboxNavigationApp.setup {
|
|
||||||
NavigationOptions.Builder(context)
|
|
||||||
.accessToken(BuildConfig.MAPBOX_DOWNLOADS_TOKEN)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MapboxNavigationApp.current()?.startTripSession()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onStart() {
|
|
||||||
MapboxNavigationApp.current()?.registerRouteProgressObserver(routeProgressObserver)
|
|
||||||
MapboxNavigationApp.current()?.registerLocationObserver(locationObserver)
|
|
||||||
MapboxNavigationApp.current()?.registerNavigationSessionStateObserver(navigationStateObserver)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onStop() {
|
|
||||||
MapboxNavigationApp.current()?.unregisterRouteProgressObserver(routeProgressObserver)
|
|
||||||
MapboxNavigationApp.current()?.unregisterLocationObserver(locationObserver)
|
|
||||||
MapboxNavigationApp.current()?.unregisterNavigationSessionStateObserver(navigationStateObserver)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onDestroy() {
|
|
||||||
MapboxNavigationApp.current()?.stopTripSession()
|
|
||||||
maneuverApi.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define distance formatter options
|
|
||||||
private val distanceFormatter: DistanceFormatterOptions by lazy {
|
|
||||||
DistanceFormatterOptions.Builder(context).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 {
|
|
||||||
context.garmin.process(
|
|
||||||
this[0]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val locationObserver = object : LocationObserver {
|
|
||||||
override fun onNewLocationMatcherResult(locationMatcherResult: LocationMatcherResult) {
|
|
||||||
context.garmin.process(locationMatcherResult)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNewRawLocation(rawLocation: Location) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val navigationStateObserver = NavigationSessionStateObserver { context.garmin.process(it) }
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue