Skip to content

Commit fac840d

Browse files
committed
adopt drop in to use new speed info view
1 parent 46fb4df commit fac840d

32 files changed

Lines changed: 770 additions & 84 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ Mapbox welcomes participation and contributions from everyone.
2727
.build()
2828
}
2929
```
30+
- Added support to use `MapboxSpeedInfoView` as default view to render posted and current speed in Drop-In UI. [#6743](https://github.com/mapbox/mapbox-navigation-android/pull/6743)
31+
- Introduced `ViewStyleCustomization.speedInfoOptions` to style the `MapboxSpeedInfoView` using Drop-In UI. [#6743](https://github.com/mapbox/mapbox-navigation-android/pull/6743)
32+
- Introduced `ViewBinderCustomization.legacySpeedLimitBinder()` and `ViewBinderCustomization.defaultSpeedInfoBinder` to facilitate the simple use of legacy `MapboxSpeedLimitView` and new `MapboxSpeedInfoView`. [#6743](https://github.com/mapbox/mapbox-navigation-android/pull/6743)
33+
- :warning: Deprecated `ViewStyleCustomization.setSpeedLimitStyle` and `ViewStyleCustomization.setSpeedLimitTextAppearance`. [#6743](https://github.com/mapbox/mapbox-navigation-android/pull/6743)
34+
To use the legacy speed limit view, add the following code:
35+
```kotlin
36+
binding.navigationView.customizeViewBinders {
37+
binding.navigationView.customizeViewBinders {
38+
speedLimitBinder = legacySpeedLimitBinder()
39+
}
40+
}
41+
```
3042

3143
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
3244
### Changelog
@@ -35,6 +47,7 @@ Mapbox welcomes participation and contributions from everyone.
3547
#### Features
3648
- Introduced `MapboxSpeedInfoApi` and `MapboxSpeedInfoView`. The combination of API and View can be used to render posted and current speed limit at user's current location. [#6687](https://github.com/mapbox/mapbox-navigation-android/pull/6687)
3749
- :warning: Deprecated `MapboxSpeedLimitApi` and `MapboxSpeedLimitView`. [#6687](https://github.com/mapbox/mapbox-navigation-android/pull/6687)
50+
3851
#### Bug fixes and improvements
3952
- Fixed approaches list update in `RouteOptionsUpdater`(uses for reroute). It was putting to the origin approach corresponding approach from legacy approach list. [#6540](https://github.com/mapbox/mapbox-navigation-android/pull/6540)
4053
- Updated the `MapboxRestAreaApi` logic to load a SAPA map only if the upcoming rest stop is at the current step of the route leg. [#6695](https://github.com/mapbox/mapbox-navigation-android/pull/6695)

libnavui-dropin/api/current.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ package com.mapbox.navigation.dropin {
6161
}
6262

6363
public final class ViewBinderCustomization {
64-
ctor public ViewBinderCustomization();
64+
ctor @Deprecated public ViewBinderCustomization();
65+
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? defaultSpeedInfoBinder();
6566
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getActionButtonsBinder();
6667
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getActionCameraModeButtonBinder();
6768
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getActionCompassButtonBinder();
@@ -88,6 +89,7 @@ package com.mapbox.navigation.dropin {
8889
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getRightFrameBinder();
8990
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getRoadNameBinder();
9091
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? getSpeedLimitBinder();
92+
method public com.mapbox.navigation.ui.base.lifecycle.UIBinder? legacySpeedLimitBinder();
9193
method public void setActionButtonsBinder(com.mapbox.navigation.ui.base.lifecycle.UIBinder?);
9294
method public void setActionCameraModeButtonBinder(com.mapbox.navigation.ui.base.lifecycle.UIBinder?);
9395
method public void setActionCompassButtonBinder(com.mapbox.navigation.ui.base.lifecycle.UIBinder?);
@@ -253,8 +255,9 @@ package com.mapbox.navigation.dropin {
253255
method public Integer? getRoadNameBackground();
254256
method public Integer? getRoadNameTextAppearance();
255257
method public Integer? getRoutePreviewButtonStyle();
256-
method public Integer? getSpeedLimitStyle();
257-
method public Integer? getSpeedLimitTextAppearance();
258+
method public com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions? getSpeedInfoOptions();
259+
method @Deprecated public Integer? getSpeedLimitStyle();
260+
method @Deprecated public Integer? getSpeedLimitTextAppearance();
258261
method public Integer? getStartNavigationButtonStyle();
259262
method public Integer? getTripProgressStyle();
260263
method public void setArrivalTextAppearance(Integer?);
@@ -274,8 +277,9 @@ package com.mapbox.navigation.dropin {
274277
method public void setRoadNameBackground(Integer?);
275278
method public void setRoadNameTextAppearance(Integer?);
276279
method public void setRoutePreviewButtonStyle(Integer?);
277-
method public void setSpeedLimitStyle(Integer?);
278-
method public void setSpeedLimitTextAppearance(Integer?);
280+
method public void setSpeedInfoOptions(com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions?);
281+
method @Deprecated public void setSpeedLimitStyle(Integer?);
282+
method @Deprecated public void setSpeedLimitTextAppearance(Integer?);
279283
method public void setStartNavigationButtonStyle(Integer?);
280284
method public void setTripProgressStyle(Integer?);
281285
property public final Integer? arrivalTextAppearance;
@@ -295,8 +299,9 @@ package com.mapbox.navigation.dropin {
295299
property public final Integer? roadNameBackground;
296300
property public final Integer? roadNameTextAppearance;
297301
property public final Integer? routePreviewButtonStyle;
298-
property public final Integer? speedLimitStyle;
299-
property public final Integer? speedLimitTextAppearance;
302+
property public final com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions? speedInfoOptions;
303+
property @Deprecated public final Integer? speedLimitStyle;
304+
property @Deprecated public final Integer? speedLimitTextAppearance;
300305
property public final Integer? startNavigationButtonStyle;
301306
property public final Integer? tripProgressStyle;
302307
field public static final com.mapbox.navigation.dropin.ViewStyleCustomization.Companion Companion;
@@ -320,8 +325,9 @@ package com.mapbox.navigation.dropin {
320325
method @DrawableRes public int defaultRoadNameBackground();
321326
method @StyleRes public int defaultRoadNameTextAppearance();
322327
method @StyleRes public int defaultRoutePreviewButtonStyle();
323-
method @StyleRes public int defaultSpeedLimitStyle();
324-
method @StyleRes public int defaultSpeedLimitTextAppearance();
328+
method public com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions defaultSpeedInfoOptions();
329+
method @Deprecated @StyleRes public int defaultSpeedLimitStyle();
330+
method @Deprecated @StyleRes public int defaultSpeedLimitTextAppearance();
325331
method @StyleRes public int defaultStartNavigationButtonStyle();
326332
method @StyleRes public int defaultTripProgressStyle();
327333
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/ViewBinderCustomization.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import com.mapbox.navigation.dropin.actionbutton.ActionButtonDescription
55
import com.mapbox.navigation.dropin.actionbutton.ActionButtonsBinder
66
import com.mapbox.navigation.dropin.infopanel.InfoPanelBinder
77
import com.mapbox.navigation.dropin.map.MapViewBinder
8+
import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
9+
import com.mapbox.navigation.dropin.speedlimit.SpeedInfoViewBinder
10+
import com.mapbox.navigation.dropin.speedlimit.SpeedLimitViewBinder
811
import com.mapbox.navigation.ui.base.lifecycle.UIBinder
12+
import com.mapbox.navigation.utils.internal.ifNonNull
913

1014
/**
1115
* A class that allows you to define [UIBinder] for various different views used by the
1216
* [NavigationView]. If not specified, [NavigationView] uses the default [UIBinder] defined for
1317
* each of these views.
1418
*/
15-
class ViewBinderCustomization {
19+
class ViewBinderCustomization internal constructor(private val navContext: NavigationViewContext?) {
20+
21+
/**
22+
* constructor
23+
*/
24+
@Deprecated(
25+
message = "The constructor, if used, would return null when legacySpeedLimitBinder() and " +
26+
"defaultSpeedLimitBinder() are invoked"
27+
)
28+
constructor() : this(null)
1629

1730
/**
1831
* Customize the speed limit view by providing your own [UIBinder].
@@ -181,4 +194,24 @@ class ViewBinderCustomization {
181194
* Use [MapViewBinder.defaultBinder] to reset to default.
182195
*/
183196
var mapViewBinder: MapViewBinder? = null
197+
198+
/**
199+
* Invoke the function to use the legacy speed limit binder.
200+
* @return UIBinder
201+
*/
202+
fun legacySpeedLimitBinder(): UIBinder? {
203+
return ifNonNull(navContext) {
204+
SpeedLimitViewBinder(it)
205+
}
206+
}
207+
208+
/**
209+
* Invoke the function to use the default speed limit binder.
210+
* @return UIBinder
211+
*/
212+
fun defaultSpeedInfoBinder(): UIBinder? {
213+
return ifNonNull(navContext) {
214+
SpeedInfoViewBinder(it)
215+
}
216+
}
184217
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/ViewStyleCustomization.kt

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import com.mapbox.navigation.ui.maneuver.view.MapboxManeuverView
2727
import com.mapbox.navigation.ui.maps.puck.LocationPuckOptions
2828
import com.mapbox.navigation.ui.maps.roadname.view.MapboxRoadNameView
2929
import com.mapbox.navigation.ui.maps.view.MapboxCameraModeButton
30+
import com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions
31+
import com.mapbox.navigation.ui.speedlimit.view.MapboxSpeedInfoView
3032
import com.mapbox.navigation.ui.speedlimit.view.MapboxSpeedLimitView
3133
import com.mapbox.navigation.ui.tripprogress.view.MapboxTripProgressView
3234
import com.mapbox.navigation.ui.voice.view.MapboxAudioGuidanceButton
@@ -101,18 +103,10 @@ class ViewStyleCustomization {
101103
var tripProgressStyle: Int? = null
102104

103105
/**
104-
* Provide custom [MapboxSpeedLimitView] style.
105-
* Use [defaultSpeedLimitStyle] to reset to default.
106-
*/
107-
@StyleRes
108-
var speedLimitStyle: Int? = null
109-
110-
/**
111-
* Provide custom [MapboxSpeedLimitView] [TextAppearance].
112-
* Use [defaultSpeedLimitTextAppearance] to reset to default.
106+
* Provide options to style [MapboxSpeedInfoView] MUTCD and VIENNA configuration .
107+
* Use [defaultSpeedInfoOptions] to reset to default.
113108
*/
114-
@StyleRes
115-
var speedLimitTextAppearance: Int? = null
109+
var speedInfoOptions: MapboxSpeedInfoOptions? = null
116110

117111
/**
118112
* Provide custom [MapboxRoadNameView] [TextAppearance].
@@ -191,6 +185,28 @@ class ViewStyleCustomization {
191185
*/
192186
var locationPuckOptions: LocationPuckOptions? = null
193187

188+
/**
189+
* Provide custom [MapboxSpeedLimitView] style.
190+
* Use [defaultSpeedLimitStyle] to reset to default.
191+
*/
192+
@StyleRes
193+
@Deprecated(
194+
message = "The parent MapboxSpeedLimitView is deprecated",
195+
replaceWith = ReplaceWith("speedInfoOptions")
196+
)
197+
var speedLimitStyle: Int? = null
198+
199+
/**
200+
* Provide custom [MapboxSpeedLimitView] [TextAppearance].
201+
* Use [defaultSpeedLimitTextAppearance] to reset to default.
202+
*/
203+
@StyleRes
204+
@Deprecated(
205+
message = "The parent MapboxSpeedLimitView is deprecated",
206+
replaceWith = ReplaceWith("speedInfoOptions")
207+
)
208+
var speedLimitTextAppearance: Int? = null
209+
194210
companion object {
195211
/**
196212
* Default info panel peek height in pixels.
@@ -255,18 +271,6 @@ class ViewStyleCustomization {
255271
@StyleRes
256272
fun defaultTripProgressStyle(): Int = R.style.DropInStyleTripProgressView
257273

258-
/**
259-
* Default [MapboxSpeedLimitView] style.
260-
*/
261-
@StyleRes
262-
fun defaultSpeedLimitStyle(): Int = R.style.DropInStyleSpeedLimit
263-
264-
/**
265-
* Default [MapboxSpeedLimitView] [TextAppearance].
266-
*/
267-
@StyleRes
268-
fun defaultSpeedLimitTextAppearance(): Int = R.style.DropInSpeedLimitTextAppearance
269-
270274
/**
271275
* Default [MapboxRoadNameView] [TextAppearance].
272276
*/
@@ -382,6 +386,32 @@ class ViewStyleCustomization {
382386
fun defaultLocationPuckOptions(context: Context): LocationPuckOptions =
383387
LocationPuckOptions.Builder(context).build()
384388

389+
/**
390+
* Default [MapboxSpeedInfoOptions]
391+
*/
392+
fun defaultSpeedInfoOptions(): MapboxSpeedInfoOptions =
393+
MapboxSpeedInfoOptions.Builder().build()
394+
395+
/**
396+
* Default [MapboxSpeedLimitView] style.
397+
*/
398+
@Deprecated(
399+
message = "The parent MapboxSpeedLimitView is deprecated",
400+
replaceWith = ReplaceWith("speedInfoOptions")
401+
)
402+
@StyleRes
403+
fun defaultSpeedLimitStyle(): Int = R.style.DropInStyleSpeedLimit
404+
405+
/**
406+
* Default [MapboxSpeedLimitView] [TextAppearance].
407+
*/
408+
@Deprecated(
409+
message = "The parent MapboxSpeedLimitView is deprecated",
410+
replaceWith = ReplaceWith("speedInfoOptions")
411+
)
412+
@StyleRes
413+
fun defaultSpeedLimitTextAppearance(): Int = R.style.DropInSpeedLimitTextAppearance
414+
385415
private fun defaultMutcdProperties() = MapboxExitProperties.PropertiesMutcd(
386416
exitBackground = R.drawable.mapbox_dropin_exit_board_background,
387417
fallbackDrawable = R.drawable.mapbox_dropin_ic_exit_arrow_right_mutcd,

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/navigationview/NavigationViewContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal class NavigationViewContext(
6868
)
6969

7070
fun applyBinderCustomization(action: ViewBinderCustomization.() -> Unit) {
71-
val customization = ViewBinderCustomization().apply(action)
71+
val customization = ViewBinderCustomization(this).apply(action)
7272
uiBinders.applyCustomization(customization)
7373
}
7474

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/navigationview/NavigationViewStyles.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
55
import com.mapbox.navigation.dropin.ViewStyleCustomization
66
import com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions
77
import com.mapbox.navigation.ui.maps.puck.LocationPuckOptions
8+
import com.mapbox.navigation.ui.speedlimit.model.MapboxSpeedInfoOptions
89
import kotlinx.coroutines.flow.MutableStateFlow
910
import kotlinx.coroutines.flow.StateFlow
1011
import kotlinx.coroutines.flow.asStateFlow
@@ -41,10 +42,8 @@ internal class NavigationViewStyles(context: Context) {
4142
private var _startNavigationButtonStyle: MutableStateFlow<Int> =
4243
MutableStateFlow(ViewStyleCustomization.defaultStartNavigationButtonStyle())
4344

44-
private val _speedLimitStyle: MutableStateFlow<Int> =
45-
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitStyle())
46-
private val _speedLimitTextAppearance: MutableStateFlow<Int> =
47-
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitTextAppearance())
45+
private val _speedInfoOptions: MutableStateFlow<MapboxSpeedInfoOptions> =
46+
MutableStateFlow(ViewStyleCustomization.defaultSpeedInfoOptions())
4847
private val _roadNameBackground: MutableStateFlow<Int> =
4948
MutableStateFlow(ViewStyleCustomization.defaultRoadNameBackground())
5049
private val _roadNameTextAppearance: MutableStateFlow<Int> =
@@ -58,6 +57,14 @@ internal class NavigationViewStyles(context: Context) {
5857
private val _locationPuckOptions: MutableStateFlow<LocationPuckOptions> =
5958
MutableStateFlow(ViewStyleCustomization.defaultLocationPuckOptions(context))
6059

60+
@Deprecated(message = "The parent MapboxSpeedLimitView is deprecated")
61+
private val _speedLimitStyle: MutableStateFlow<Int> =
62+
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitStyle())
63+
64+
@Deprecated(message = "The parent MapboxSpeedLimitView is deprecated")
65+
private val _speedLimitTextAppearance: MutableStateFlow<Int> =
66+
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitTextAppearance())
67+
6168
val infoPanelPeekHeight: StateFlow<Int> = _infoPanelPeekHeight.asStateFlow()
6269
val infoPanelMarginStart: StateFlow<Int> = _infoPanelMarginStart.asStateFlow()
6370
val infoPanelMarginEnd: StateFlow<Int> = _infoPanelMarginEnd.asStateFlow()
@@ -75,8 +82,7 @@ internal class NavigationViewStyles(context: Context) {
7582
val endNavigationButtonStyle: StateFlow<Int> = _endNavigationButtonStyle.asStateFlow()
7683
val startNavigationButtonStyle: StateFlow<Int> = _startNavigationButtonStyle.asStateFlow()
7784

78-
val speedLimitStyle: StateFlow<Int> = _speedLimitStyle.asStateFlow()
79-
val speedLimitTextAppearance: StateFlow<Int> = _speedLimitTextAppearance.asStateFlow()
85+
val speedInfoOptions: StateFlow<MapboxSpeedInfoOptions> = _speedInfoOptions.asStateFlow()
8086
val destinationMarkerAnnotationOptions: StateFlow<PointAnnotationOptions> =
8187
_destinationMarkerAnnotationOptions.asStateFlow()
8288
val roadNameBackground: StateFlow<Int> = _roadNameBackground.asStateFlow()
@@ -85,6 +91,18 @@ internal class NavigationViewStyles(context: Context) {
8591
val arrivalTextAppearance: StateFlow<Int> = _arrivalTextAppearance.asStateFlow()
8692
val locationPuckOptions: StateFlow<LocationPuckOptions> = _locationPuckOptions.asStateFlow()
8793

94+
@Deprecated(
95+
message = "The parent MapboxSpeedLimitView is deprecated",
96+
replaceWith = ReplaceWith("speedInfoStyle")
97+
)
98+
val speedLimitStyle: StateFlow<Int> = _speedLimitStyle.asStateFlow()
99+
100+
@Deprecated(
101+
message = "The parent MapboxSpeedLimitView is deprecated",
102+
replaceWith = ReplaceWith("speedInfoStyle")
103+
)
104+
val speedLimitTextAppearance: StateFlow<Int> = _speedLimitTextAppearance.asStateFlow()
105+
88106
fun applyCustomization(customization: ViewStyleCustomization) {
89107
customization.infoPanelPeekHeight?.also { _infoPanelPeekHeight.value = it }
90108
customization.infoPanelMarginStart?.also { _infoPanelMarginStart.value = it }
@@ -104,15 +122,17 @@ internal class NavigationViewStyles(context: Context) {
104122
customization.endNavigationButtonStyle?.also { _endNavigationButtonStyle.value = it }
105123
customization.startNavigationButtonStyle?.also { _startNavigationButtonStyle.value = it }
106124

107-
customization.speedLimitStyle?.also { _speedLimitStyle.value = it }
125+
customization.speedInfoOptions?.also { _speedInfoOptions.value = it }
108126
customization.maneuverViewOptions?.also { _maneuverViewOptions.value = it }
109-
customization.speedLimitTextAppearance?.also { _speedLimitTextAppearance.value = it }
110127
customization.destinationMarkerAnnotationOptions?.also {
111128
_destinationMarkerAnnotationOptions.value = it
112129
}
113130
customization.roadNameBackground?.also { _roadNameBackground.value = it }
114131
customization.roadNameTextAppearance?.also { _roadNameTextAppearance.value = it }
115132
customization.arrivalTextAppearance?.also { _arrivalTextAppearance.value = it }
116133
customization.locationPuckOptions?.also { _locationPuckOptions.value = it }
134+
135+
customization.speedLimitStyle?.also { _speedLimitStyle.value = it }
136+
customization.speedLimitTextAppearance?.also { _speedLimitTextAppearance.value = it }
117137
}
118138
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.mapbox.navigation.dropin.speedlimit
2+
3+
import android.view.ViewGroup
4+
import androidx.transition.Fade
5+
import androidx.transition.Scene
6+
import androidx.transition.TransitionManager
7+
import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
8+
import com.mapbox.navigation.dropin.R
9+
import com.mapbox.navigation.dropin.databinding.MapboxSpeedInfoLayoutBinding
10+
import com.mapbox.navigation.dropin.internal.extensions.reloadOnChange
11+
import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
12+
import com.mapbox.navigation.ui.base.lifecycle.UIBinder
13+
import com.mapbox.navigation.ui.speedlimit.internal.SpeedInfoComponent
14+
15+
internal class SpeedInfoViewBinder(
16+
val context: NavigationViewContext
17+
) : UIBinder {
18+
override fun bind(viewGroup: ViewGroup): MapboxNavigationObserver {
19+
val scene = Scene.getSceneForLayout(
20+
viewGroup,
21+
R.layout.mapbox_speed_info_layout,
22+
viewGroup.context
23+
)
24+
TransitionManager.go(scene, Fade())
25+
val binding = MapboxSpeedInfoLayoutBinding.bind(viewGroup)
26+
27+
return reloadOnChange(
28+
context.styles.speedInfoOptions,
29+
context.options.distanceFormatterOptions,
30+
) { options, distanceFormatter ->
31+
SpeedInfoComponent(
32+
speedInfoOptions = options,
33+
speedInfoView = binding.speedInfoView,
34+
distanceFormatterOptions = distanceFormatter,
35+
)
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)