Skip to content

Commit 27a84ac

Browse files
authored
introduce showMapScalebar to control its visibility (#6523)
1 parent 857c8e3 commit 27a84ac

18 files changed

Lines changed: 114 additions & 170 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Mapbox welcomes participation and contributions from everyone.
1818
- `ViewOptionsCustomization.showStartNavigationButton` can be used to show/hide info panel's start navigation button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
1919
- `ViewOptionsCustomization.showEndNavigationButton` can be used to show/hide info panel's end navigation button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
2020
#### Bug fixes and improvements
21+
- :warning: Removed `MapboxMapScalebarParams` and replaced `ViewStyleCustomization.mapScalebarParams` by `ViewOptionsCustomization.showMapScalebar` [#6523](https://github.com/mapbox/mapbox-navigation-android/pull/6523)
22+
- Refactored `ScalebarComponent` to use `ViewOptionsCustomization.distanceFormatterOptions` to change between imperial and metric based unit. [#6523](https://github.com/mapbox/mapbox-navigation-android/pull/6523)
2123
- :warning: Updated `NavigationView` buttons customization to allow styling via XML styles: [#6498](https://github.com/mapbox/mapbox-navigation-android/pull/6498)
2224
- `ViewStyleCustomization.compassButtonParams` option has been replaced by `ViewStyleCustomization.compassButtonStyle`. The default style can be accessed via `ViewStyleCustomization.defaultCompassButtonStyle()` [#6498](https://github.com/mapbox/mapbox-navigation-android/pull/6498)
2325
- `ViewStyleCustomization.cameraModeButtonParams` option has been replaced by `ViewStyleCustomization.cameraModeButtonStyle`. The default style can be accessed via `ViewStyleCustomization.defaultCameraModeButtonStyle()` [#6498](https://github.com/mapbox/mapbox-navigation-android/pull/6498)

libnavui-dropin/api/current.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ package com.mapbox.navigation.dropin {
152152
method public Boolean? getShowEndNavigationButton();
153153
method public Boolean? getShowInfoPanelInFreeDrive();
154154
method public Boolean? getShowManeuver();
155+
method public Boolean? getShowMapScalebar();
155156
method public Boolean? getShowRecenterActionButton();
156157
method public Boolean? getShowRoadName();
157158
method public Boolean? getShowRoutePreviewButton();
@@ -175,6 +176,7 @@ package com.mapbox.navigation.dropin {
175176
method public void setShowEndNavigationButton(Boolean?);
176177
method public void setShowInfoPanelInFreeDrive(Boolean?);
177178
method public void setShowManeuver(Boolean?);
179+
method public void setShowMapScalebar(Boolean?);
178180
method public void setShowRecenterActionButton(Boolean?);
179181
method public void setShowRoadName(Boolean?);
180182
method public void setShowRoutePreviewButton(Boolean?);
@@ -197,6 +199,7 @@ package com.mapbox.navigation.dropin {
197199
property public final Boolean? showEndNavigationButton;
198200
property public final Boolean? showInfoPanelInFreeDrive;
199201
property public final Boolean? showManeuver;
202+
property public final Boolean? showMapScalebar;
200203
property public final Boolean? showRecenterActionButton;
201204
property public final Boolean? showRoadName;
202205
property public final Boolean? showRoutePreviewButton;
@@ -226,7 +229,6 @@ package com.mapbox.navigation.dropin {
226229
method public Integer? getInfoPanelPeekHeight();
227230
method public com.mapbox.maps.plugin.LocationPuck? getLocationPuck();
228231
method public com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions? getManeuverViewOptions();
229-
method public com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams? getMapScalebarParams();
230232
method public Integer? getPoiNameTextAppearance();
231233
method public Integer? getRecenterButtonStyle();
232234
method public Integer? getRoadNameBackground();
@@ -248,7 +250,6 @@ package com.mapbox.navigation.dropin {
248250
method public void setInfoPanelPeekHeight(Integer?);
249251
method public void setLocationPuck(com.mapbox.maps.plugin.LocationPuck?);
250252
method public void setManeuverViewOptions(com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions?);
251-
method public void setMapScalebarParams(com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams?);
252253
method public void setPoiNameTextAppearance(Integer?);
253254
method public void setRecenterButtonStyle(Integer?);
254255
method public void setRoadNameBackground(Integer?);
@@ -270,7 +271,6 @@ package com.mapbox.navigation.dropin {
270271
property public final Integer? infoPanelPeekHeight;
271272
property public final com.mapbox.maps.plugin.LocationPuck? locationPuck;
272273
property public final com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions? maneuverViewOptions;
273-
property public final com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams? mapScalebarParams;
274274
property public final Integer? poiNameTextAppearance;
275275
property public final Integer? recenterButtonStyle;
276276
property public final Integer? roadNameBackground;
@@ -296,7 +296,6 @@ package com.mapbox.navigation.dropin {
296296
method @Px public int defaultInfoPanelPeekHeight(android.content.Context context);
297297
method public com.mapbox.maps.plugin.LocationPuck defaultLocationPuck(android.content.Context context);
298298
method public com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions defaultManeuverViewOptions();
299-
method public com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams defaultMapScalebarParams(android.content.Context context);
300299
method @StyleRes public int defaultPoiNameTextAppearance();
301300
method @StyleRes public int defaultRecenterButtonStyle();
302301
method @DrawableRes public int defaultRoadNameBackground();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class ViewOptionsCustomization {
139139
*/
140140
var showTripProgress: Boolean? = null
141141

142+
/**
143+
* Sets whether the map scalebar should be visible.
144+
* Set to `false` for the default behavior.
145+
*/
146+
var showMapScalebar: Boolean? = null
147+
142148
/**
143149
* Sets whether the route preview button should be visible.
144150
* Set to `true` for the default behavior.

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
1515
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
1616
import com.mapbox.navigation.dropin.arrival.ArrivalTextComponent
1717
import com.mapbox.navigation.dropin.map.geocoding.POINameComponent
18-
import com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams
1918
import com.mapbox.navigation.ui.base.view.MapboxExtendableButton
2019
import com.mapbox.navigation.ui.maneuver.model.ManeuverExitOptions
2120
import com.mapbox.navigation.ui.maneuver.model.ManeuverPrimaryOptions
@@ -181,16 +180,6 @@ class ViewStyleCustomization {
181180
*/
182181
var locationPuck: LocationPuck? = null
183182

184-
/**
185-
* Map scalebar params.
186-
* Use [defaultMapScalebarParams] to reset to default.
187-
* NOTE: When `enabled`, the `scalebar` will always be added to the top start corner
188-
* of the screen. Position of the `scalebar` using `NavigationView` cannot be changed at any
189-
* given time. However, if you change the position using `MapView`, the behavior is undefined
190-
* and you will be responsible to ensure the correct positioning based on other view overlays.
191-
*/
192-
var mapScalebarParams: MapboxMapScalebarParams? = null
193-
194183
companion object {
195184
/**
196185
* Default info panel peek height in pixels.
@@ -380,12 +369,6 @@ class ViewStyleCustomization {
380369
)
381370
)
382371

383-
/**
384-
* Default map scalebar parameters.
385-
*/
386-
fun defaultMapScalebarParams(context: Context): MapboxMapScalebarParams =
387-
MapboxMapScalebarParams.Builder(context).build()
388-
389372
private fun defaultMutcdProperties() = MapboxExitProperties.PropertiesMutcd(
390373
exitBackground = R.drawable.mapbox_dropin_exit_board_background,
391374
fallbackDrawable = R.drawable.mapbox_dropin_ic_exit_arrow_right_mutcd,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ abstract class MapViewBinder : UIBinder {
102102
},
103103
ScalebarComponent(
104104
mapView,
105-
context.styles.mapScalebarParams,
106-
context.systemBarsInsets
105+
context.options.showMapScalebar,
106+
context.systemBarsInsets,
107+
context.options.distanceFormatterOptions,
107108
)
108109
)
109110
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/map/scalebar/ScalebarComponent.kt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@ import androidx.core.graphics.Insets
55
import com.mapbox.maps.MapView
66
import com.mapbox.maps.plugin.scalebar.scalebar
77
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
8+
import com.mapbox.navigation.base.formatter.DistanceFormatterOptions
9+
import com.mapbox.navigation.base.formatter.UnitType
810
import com.mapbox.navigation.core.MapboxNavigation
911
import com.mapbox.navigation.ui.base.lifecycle.UIComponent
1012
import kotlinx.coroutines.flow.StateFlow
1113

1214
@ExperimentalPreviewMapboxNavigationAPI
1315
internal class ScalebarComponent(
1416
private val mapView: MapView,
15-
private val scalebarParams: StateFlow<MapboxMapScalebarParams>,
17+
private val isEnabled: StateFlow<Boolean>,
1618
private val systemBarInsets: StateFlow<Insets>,
19+
private val options: StateFlow<DistanceFormatterOptions>,
1720
) : UIComponent() {
1821

1922
private val defaultMarginTop = 4f
2023
private val defaultMarginLeft = 4f
2124

2225
init {
23-
setUpScalebar(scalebarParams.value)
2426
mapView.scalebar.updateSettings {
27+
enabled = isEnabled.value
28+
isMetricUnits = when (options.value.unitType) {
29+
UnitType.METRIC -> true
30+
UnitType.IMPERIAL -> false
31+
}
2532
position = Gravity.TOP or Gravity.START
2633
// temporary workaround, remove after MAPSMBL-173
2734
textBorderWidth = 3f
@@ -30,19 +37,27 @@ internal class ScalebarComponent(
3037

3138
override fun onAttached(mapboxNavigation: MapboxNavigation) {
3239
super.onAttached(mapboxNavigation)
33-
scalebarParams.observe { setUpScalebar(it) }
40+
41+
options.observe { formatter ->
42+
mapView.scalebar.updateSettings {
43+
isMetricUnits = when (formatter.unitType) {
44+
UnitType.METRIC -> true
45+
UnitType.IMPERIAL -> false
46+
}
47+
}
48+
}
49+
50+
isEnabled.observe { enabled ->
51+
mapView.scalebar.updateSettings {
52+
this.enabled = enabled
53+
}
54+
}
55+
3456
systemBarInsets.observe { insets ->
3557
mapView.scalebar.updateSettings {
3658
marginTop = defaultMarginTop + insets.top
3759
marginLeft = defaultMarginLeft + insets.left
3860
}
3961
}
4062
}
41-
42-
private fun setUpScalebar(params: MapboxMapScalebarParams) {
43-
mapView.scalebar.updateSettings {
44-
enabled = params.enabled
45-
isMetricUnits = params.isMetricUnits
46-
}
47-
}
4863
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/map/scalebar/ScalebarPlaceholderBinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class ScalebarPlaceholderBinder(
1818
val binding = inflateLayout(viewGroup)
1919
return ScalebarPlaceholderComponent(
2020
binding.scalebarPlaceholder,
21-
context.styles.mapScalebarParams,
21+
context.options.showMapScalebar,
2222
context.maneuverBehavior.maneuverViewVisibility
2323
)
2424
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/map/scalebar/ScalebarPlaceholderComponent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import kotlinx.coroutines.launch
1212
@ExperimentalPreviewMapboxNavigationAPI
1313
internal class ScalebarPlaceholderComponent(
1414
private val scalebarPlaceholder: View,
15-
private val scalebarParams: StateFlow<MapboxMapScalebarParams>,
15+
private val isEnabled: StateFlow<Boolean>,
1616
private val maneuverViewVisible: StateFlow<Boolean>,
1717
) : UIComponent() {
1818

1919
override fun onAttached(mapboxNavigation: MapboxNavigation) {
2020
super.onAttached(mapboxNavigation)
2121
coroutineScope.launch {
22-
combine(scalebarParams, maneuverViewVisible) { params, maneuverViewVisible ->
22+
combine(isEnabled, maneuverViewVisible) { enabled, maneuverViewVisible ->
2323
scalebarPlaceholder.visibility =
24-
if (params.enabled && !maneuverViewVisible) {
24+
if (enabled && !maneuverViewVisible) {
2525
View.VISIBLE
2626
} else {
2727
View.GONE

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal class NavigationViewOptions(context: Context) {
4848
private var _showCameraModeActionButton: MutableStateFlow<Boolean> = MutableStateFlow(true)
4949
private var _showToggleAudioActionButton: MutableStateFlow<Boolean> = MutableStateFlow(true)
5050
private var _showRecenterActionButton: MutableStateFlow<Boolean> = MutableStateFlow(true)
51+
private var _showMapScalebar: MutableStateFlow<Boolean> = MutableStateFlow(false)
5152
private var _showTripProgress: MutableStateFlow<Boolean> = MutableStateFlow(true)
5253
private var _showRoutePreviewButton: MutableStateFlow<Boolean> = MutableStateFlow(true)
5354
private var _showEndNavigationButton: MutableStateFlow<Boolean> = MutableStateFlow(true)
@@ -73,6 +74,7 @@ internal class NavigationViewOptions(context: Context) {
7374
val showCameraModeActionButton: StateFlow<Boolean> = _showCameraModeActionButton.asStateFlow()
7475
val showToggleAudioActionButton: StateFlow<Boolean> = _showToggleAudioActionButton.asStateFlow()
7576
val showRecenterActionButton: StateFlow<Boolean> = _showRecenterActionButton.asStateFlow()
77+
val showMapScalebar: StateFlow<Boolean> = _showMapScalebar.asStateFlow()
7678
val showTripProgress: StateFlow<Boolean> = _showTripProgress.asStateFlow()
7779
val showRoutePreviewButton: StateFlow<Boolean> = _showRoutePreviewButton.asStateFlow()
7880
val showEndNavigationButton: StateFlow<Boolean> = _showEndNavigationButton.asStateFlow()
@@ -100,6 +102,7 @@ internal class NavigationViewOptions(context: Context) {
100102
}
101103
customization.showRecenterActionButton?.also { _showRecenterActionButton.value = it }
102104
customization.showTripProgress?.also { _showTripProgress.value = it }
105+
customization.showMapScalebar?.also { _showMapScalebar.value = it }
103106
customization.showRoutePreviewButton?.also { _showRoutePreviewButton.value = it }
104107
customization.showEndNavigationButton?.also { _showEndNavigationButton.value = it }
105108
customization.showStartNavigationButton?.also { _showStartNavigationButton.value = it }

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.mapbox.maps.plugin.LocationPuck
55
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
66
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
77
import com.mapbox.navigation.dropin.ViewStyleCustomization
8-
import com.mapbox.navigation.dropin.map.scalebar.MapboxMapScalebarParams
98
import com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions
109
import kotlinx.coroutines.flow.MutableStateFlow
1110
import kotlinx.coroutines.flow.StateFlow
@@ -58,9 +57,6 @@ internal class NavigationViewStyles(context: Context) {
5857
MutableStateFlow(ViewStyleCustomization.defaultArrivalTextAppearance())
5958
private val _locationPuck: MutableStateFlow<LocationPuck> =
6059
MutableStateFlow(ViewStyleCustomization.defaultLocationPuck(context))
61-
private val _mapScalebarParams: MutableStateFlow<MapboxMapScalebarParams> = MutableStateFlow(
62-
ViewStyleCustomization.defaultMapScalebarParams(context)
63-
)
6460

6561
val infoPanelPeekHeight: StateFlow<Int> = _infoPanelPeekHeight.asStateFlow()
6662
val infoPanelMarginStart: StateFlow<Int> = _infoPanelMarginStart.asStateFlow()
@@ -86,7 +82,6 @@ internal class NavigationViewStyles(context: Context) {
8682
val maneuverViewOptions: StateFlow<ManeuverViewOptions> = _maneuverViewOptions.asStateFlow()
8783
val arrivalTextAppearance: StateFlow<Int> = _arrivalTextAppearance.asStateFlow()
8884
val locationPuck: StateFlow<LocationPuck> = _locationPuck.asStateFlow()
89-
val mapScalebarParams: StateFlow<MapboxMapScalebarParams> = _mapScalebarParams.asStateFlow()
9085

9186
fun applyCustomization(customization: ViewStyleCustomization) {
9287
customization.infoPanelPeekHeight?.also { _infoPanelPeekHeight.value = it }
@@ -114,6 +109,5 @@ internal class NavigationViewStyles(context: Context) {
114109
customization.roadNameTextAppearance?.also { _roadNameTextAppearance.value = it }
115110
customization.arrivalTextAppearance?.also { _arrivalTextAppearance.value = it }
116111
customization.locationPuck?.also { _locationPuck.value = it }
117-
customization.mapScalebarParams?.also { _mapScalebarParams.value = it }
118112
}
119113
}

0 commit comments

Comments
 (0)