@@ -27,6 +27,7 @@ import com.mapbox.geojson.FeatureCollection
2727import com.mapbox.maps.MapboxExperimental
2828import com.mapbox.maps.extension.androidauto.MapboxCarMapObserver
2929import com.mapbox.maps.extension.androidauto.MapboxCarMapSurface
30+ import com.mapbox.maps.extension.androidauto.mapboxMapInstaller
3031import com.mapbox.maps.plugin.delegates.listeners.OnStyleLoadedListener
3132import com.mapbox.navigation.base.trip.model.RouteLegProgress
3233import com.mapbox.navigation.base.trip.model.RouteProgress
@@ -44,20 +45,12 @@ class ActiveGuidanceScreen(
4445 private val placesLayerUtil : PlacesListOnMapLayerUtil = PlacesListOnMapLayerUtil (),
4546) : Screen(carActiveGuidanceContext.carContext) {
4647
47- val carRouteLine = CarRouteLine (carActiveGuidanceContext.mainCarContext)
48- val carLocationRenderer = CarLocationRenderer (carActiveGuidanceContext.mainCarContext)
49- val carSpeedLimitRenderer = CarSpeedLimitRenderer (carActiveGuidanceContext.mainCarContext)
50- val carNavigationCamera = CarNavigationCamera (
48+ private val carRouteProgressObserver = CarNavigationInfoObserver (carActiveGuidanceContext)
49+ private val carNavigationCamera = CarNavigationCamera (
5150 carActiveGuidanceContext.mapboxNavigation,
5251 CarCameraMode .FOLLOWING ,
5352 CarCameraMode .OVERVIEW ,
5453 )
55- private val roadLabelSurfaceLayer = RoadLabelSurfaceLayer (
56- carActiveGuidanceContext.carContext,
57- carActiveGuidanceContext.mapboxNavigation,
58- )
59-
60- private val carRouteProgressObserver = CarNavigationInfoObserver (carActiveGuidanceContext)
6154 private val mapActionStripBuilder = MainMapActionStrip (this , carNavigationCamera)
6255
6356 private val arrivalObserver = object : ArrivalObserver {
@@ -112,6 +105,21 @@ class ActiveGuidanceScreen(
112105 }
113106
114107 init {
108+ mapboxMapInstaller(carActiveGuidanceContext.mapboxCarMap)
109+ .onResumed(
110+ CarLocationRenderer (carActiveGuidanceContext.mainCarContext),
111+ RoadLabelSurfaceLayer (
112+ carContext,
113+ carActiveGuidanceContext.mapboxNavigation,
114+ ),
115+ CarSpeedLimitRenderer (carActiveGuidanceContext.mainCarContext),
116+ carNavigationCamera,
117+ CarRouteLine (carActiveGuidanceContext.mainCarContext),
118+ surfaceListener,
119+ )
120+ .gestureHandler(carNavigationCamera.gestureHandler)
121+ .install()
122+
115123 logAndroidAuto(" ActiveGuidanceScreen constructor" )
116124 lifecycle.addObserver(object : DefaultLifecycleObserver {
117125
@@ -122,29 +130,13 @@ class ActiveGuidanceScreen(
122130
123131 override fun onResume (owner : LifecycleOwner ) {
124132 logAndroidAuto(" ActiveGuidanceScreen onResume" )
125- carActiveGuidanceContext.mapboxCarMap.registerObserver(carLocationRenderer)
126- carActiveGuidanceContext.mapboxCarMap.registerObserver(roadLabelSurfaceLayer)
127- carActiveGuidanceContext.mapboxCarMap.registerObserver(carSpeedLimitRenderer)
128- carActiveGuidanceContext.mapboxCarMap.registerObserver(carNavigationCamera)
129- carActiveGuidanceContext.mapboxCarMap.setGestureHandler(
130- carNavigationCamera.gestureHandler
131- )
132- carActiveGuidanceContext.mapboxCarMap.registerObserver(carRouteLine)
133- carActiveGuidanceContext.mapboxCarMap.registerObserver(surfaceListener)
134133 carRouteProgressObserver.start {
135134 invalidate()
136135 }
137136 }
138137
139138 override fun onPause (owner : LifecycleOwner ) {
140139 logAndroidAuto(" ActiveGuidanceScreen onPause" )
141- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(roadLabelSurfaceLayer)
142- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(carLocationRenderer)
143- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(carSpeedLimitRenderer)
144- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(carNavigationCamera)
145- carActiveGuidanceContext.mapboxCarMap.setGestureHandler(null )
146- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(carRouteLine)
147- carActiveGuidanceContext.mapboxCarMap.unregisterObserver(surfaceListener)
148140 carRouteProgressObserver.stop()
149141 }
150142
0 commit comments