Skip to content

Commit 857c8e3

Browse files
tomaszrybakiewiczabhishek1508
authored andcommitted
Updated ViewOptionsCustomization and added support for showing/hiding:
- SpeedLimitView - TripProgressView - ManeuverView - RoadNameView - ActionButtonView - Camera Mode Button - Toggle Audio Button - Recenter Camera Button - Start navigation button - End navigation button - Route preview button Added examples for toggling the visibility of NavigationView views Added CHANGELOG entry
1 parent 3dda4f9 commit 857c8e3

22 files changed

Lines changed: 893 additions & 265 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Mapbox welcomes participation and contributions from everyone.
44

55
## Unreleased
66
#### Features
7+
- Introduced new `ViewOptionsCustomization` options that allows showing/hiding of various `NavigationView` subviews. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
8+
- `ViewOptionsCustomization.showManeuver` can be used to show/hide the maneuver view. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
9+
- `ViewOptionsCustomization.showSpeedLimit` can be used to show/hide the speed limit view. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
10+
- `ViewOptionsCustomization.showRoadName` can be used to show/hide the road name view. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
11+
- `ViewOptionsCustomization.showActionButtons` can be used to show/hide action buttons layout. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
12+
- `ViewOptionsCustomization.showCompassActionButton` can be used to show/hide compass action button. The default is `false`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
13+
- `ViewOptionsCustomization.showCameraModeActionButton` can be used to show/hide toggle camera mode action button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
14+
- `ViewOptionsCustomization.showToggleAudioActionButton` can be used to show/hide toggle voice instructions action button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
15+
- `ViewOptionsCustomization.showRecenterActionButton` can be used to show/hide re-center camera action button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
16+
- `ViewOptionsCustomization.showTripProgress` can be used to show/hide info panel's trip progress view. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
17+
- `ViewOptionsCustomization.showRoutePreviewButton` can be used to show/hide info panel's show route preview button. The default is `true`. [#6506](https://github.com/mapbox/mapbox-navigation-android/pull/6506)
18+
- `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)
19+
- `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)
720
#### Bug fixes and improvements
821
- :warning: Updated `NavigationView` buttons customization to allow styling via XML styles: [#6498](https://github.com/mapbox/mapbox-navigation-android/pull/6498)
922
- `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)

libnavui-dropin/api/current.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,20 @@ package com.mapbox.navigation.dropin {
145145
method public String? getMapStyleUriNight();
146146
method public com.mapbox.navigation.ui.maps.route.arrow.model.RouteArrowOptions? getRouteArrowOptions();
147147
method public com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions? getRouteLineOptions();
148+
method public Boolean? getShowActionButtons();
148149
method public Boolean? getShowCameraDebugInfo();
150+
method public Boolean? getShowCameraModeActionButton();
149151
method public Boolean? getShowCompassActionButton();
152+
method public Boolean? getShowEndNavigationButton();
150153
method public Boolean? getShowInfoPanelInFreeDrive();
154+
method public Boolean? getShowManeuver();
155+
method public Boolean? getShowRecenterActionButton();
156+
method public Boolean? getShowRoadName();
157+
method public Boolean? getShowRoutePreviewButton();
158+
method public Boolean? getShowSpeedLimit();
159+
method public Boolean? getShowStartNavigationButton();
160+
method public Boolean? getShowToggleAudioActionButton();
161+
method public Boolean? getShowTripProgress();
151162
method public Boolean? isInfoPanelHideable();
152163
method public void setDistanceFormatterOptions(com.mapbox.navigation.base.formatter.DistanceFormatterOptions?);
153164
method public void setEnableMapLongClickIntercept(Boolean?);
@@ -157,9 +168,20 @@ package com.mapbox.navigation.dropin {
157168
method public void setMapStyleUriNight(String?);
158169
method public void setRouteArrowOptions(com.mapbox.navigation.ui.maps.route.arrow.model.RouteArrowOptions?);
159170
method public void setRouteLineOptions(com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions?);
171+
method public void setShowActionButtons(Boolean?);
160172
method public void setShowCameraDebugInfo(Boolean?);
173+
method public void setShowCameraModeActionButton(Boolean?);
161174
method public void setShowCompassActionButton(Boolean?);
175+
method public void setShowEndNavigationButton(Boolean?);
162176
method public void setShowInfoPanelInFreeDrive(Boolean?);
177+
method public void setShowManeuver(Boolean?);
178+
method public void setShowRecenterActionButton(Boolean?);
179+
method public void setShowRoadName(Boolean?);
180+
method public void setShowRoutePreviewButton(Boolean?);
181+
method public void setShowSpeedLimit(Boolean?);
182+
method public void setShowStartNavigationButton(Boolean?);
183+
method public void setShowToggleAudioActionButton(Boolean?);
184+
method public void setShowTripProgress(Boolean?);
163185
property public final com.mapbox.navigation.base.formatter.DistanceFormatterOptions? distanceFormatterOptions;
164186
property public final Boolean? enableMapLongClickIntercept;
165187
property public final Integer? infoPanelForcedState;
@@ -168,9 +190,20 @@ package com.mapbox.navigation.dropin {
168190
property public final String? mapStyleUriNight;
169191
property public final com.mapbox.navigation.ui.maps.route.arrow.model.RouteArrowOptions? routeArrowOptions;
170192
property public final com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions? routeLineOptions;
193+
property public final Boolean? showActionButtons;
171194
property public final Boolean? showCameraDebugInfo;
195+
property public final Boolean? showCameraModeActionButton;
172196
property public final Boolean? showCompassActionButton;
197+
property public final Boolean? showEndNavigationButton;
173198
property public final Boolean? showInfoPanelInFreeDrive;
199+
property public final Boolean? showManeuver;
200+
property public final Boolean? showRecenterActionButton;
201+
property public final Boolean? showRoadName;
202+
property public final Boolean? showRoutePreviewButton;
203+
property public final Boolean? showSpeedLimit;
204+
property public final Boolean? showStartNavigationButton;
205+
property public final Boolean? showToggleAudioActionButton;
206+
property public final Boolean? showTripProgress;
174207
field public static final com.mapbox.navigation.dropin.ViewOptionsCustomization.Companion Companion;
175208
}
176209

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
55
import com.mapbox.maps.plugin.gestures.OnMapLongClickListener
66
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
77
import com.mapbox.navigation.base.formatter.DistanceFormatterOptions
8+
import com.mapbox.navigation.dropin.infopanel.InfoPanelBinder
9+
import com.mapbox.navigation.ui.base.lifecycle.Binder
810
import com.mapbox.navigation.ui.maps.NavigationStyles
911
import com.mapbox.navigation.ui.maps.route.RouteLayerConstants
1012
import com.mapbox.navigation.ui.maps.route.arrow.model.RouteArrowOptions
@@ -83,12 +85,78 @@ class ViewOptionsCustomization {
8385
*/
8486
var showCameraDebugInfo: Boolean? = null
8587

88+
/**
89+
* Sets whether the maneuver view should be visible.
90+
* Set to `true` for the default behavior.
91+
*/
92+
var showManeuver: Boolean? = null
93+
94+
/**
95+
* Sets whether the speed limit view should be visible.
96+
* Set to `true` for the default behavior.
97+
*/
98+
var showSpeedLimit: Boolean? = null
99+
100+
/**
101+
* Sets whether the road name view should be visible.
102+
* Set to `true` for the default behavior.
103+
*/
104+
var showRoadName: Boolean? = null
105+
106+
/**
107+
* Sets whether action buttons should be visible.
108+
* Set to `true` for the default behavior.
109+
*/
110+
var showActionButtons: Boolean? = null
111+
86112
/**
87113
* Sets whether the compass action button should be visible.
88114
* Set to `false` for the default behavior.
89115
*/
90116
var showCompassActionButton: Boolean? = null
91117

118+
/**
119+
* Sets whether the camera mode button should be visible.
120+
* Set to `true` for the default behavior.
121+
*/
122+
var showCameraModeActionButton: Boolean? = null
123+
124+
/**
125+
* Sets whether the toggle audio button should be visible.
126+
* Set to `true` for the default behavior.
127+
*/
128+
var showToggleAudioActionButton: Boolean? = null
129+
130+
/**
131+
* Sets whether the recenter camera button should be visible.
132+
* Set to `true` for the default behavior.
133+
*/
134+
var showRecenterActionButton: Boolean? = null
135+
136+
/**
137+
* Sets whether the trip progress view should be visible.
138+
* Set to `true` for the default behavior.
139+
*/
140+
var showTripProgress: Boolean? = null
141+
142+
/**
143+
* Sets whether the route preview button should be visible.
144+
* Set to `true` for the default behavior.
145+
*/
146+
var showRoutePreviewButton: Boolean? = null
147+
148+
/**
149+
* Sets whether the end navigation button should be visible.
150+
* Set to `true` for the default behavior.
151+
*/
152+
var showEndNavigationButton: Boolean? = null
153+
154+
/**
155+
* Sets whether the start navigation button should be visible.
156+
* Set to `true` for the default behavior.
157+
*/
158+
var showStartNavigationButton: Boolean? = null
159+
92160
companion object {
93161
/**
94162
* Default route line options.

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mapbox.navigation.dropin.actionbutton
33
import android.view.ViewGroup
44
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
55
import com.mapbox.navigation.core.MapboxNavigation
6+
import com.mapbox.navigation.dropin.EmptyBinder
67
import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
78
import com.mapbox.navigation.ui.base.lifecycle.UIBinder
89
import com.mapbox.navigation.ui.base.lifecycle.UICoordinator
@@ -21,15 +22,20 @@ internal class ActionButtonsCoordinator(
2122

2223
override fun MapboxNavigation.flowViewBinders(): Flow<UIBinder> {
2324
return combine(
25+
context.options.showActionButtons,
2426
context.uiBinders.actionButtonsBinder,
2527
context.uiBinders.customActionButtons
26-
) { uiBinder, customButtons ->
27-
val binder = uiBinder ?: ActionButtonsBinder.defaultBinder()
28-
if (binder is ActionButtonsBinder) {
29-
binder.context = context
30-
binder.customButtons = customButtons
28+
) { show, uiBinder, customButtons ->
29+
if (show) {
30+
val binder = uiBinder ?: ActionButtonsBinder.defaultBinder()
31+
if (binder is ActionButtonsBinder) {
32+
binder.context = context
33+
binder.customButtons = customButtons
34+
}
35+
binder
36+
} else {
37+
EmptyBinder()
3138
}
32-
binder
3339
}
3440
}
3541
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/internal/extensions/NavigationViewContextEx.kt

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.mapbox.navigation.dropin.map.geocoding.POINameComponent
2020
import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
2121
import com.mapbox.navigation.dropin.tripprogress.TripProgressBinder
2222
import kotlinx.coroutines.flow.combine
23-
import kotlinx.coroutines.flow.map
2423

2524
@ExperimentalPreviewMapboxNavigationAPI
2625
internal fun NavigationViewContext.poiNameComponent(textView: AppCompatTextView) =
@@ -30,8 +29,15 @@ internal fun NavigationViewContext.poiNameComponent(textView: AppCompatTextView)
3029
internal fun NavigationViewContext.routePreviewButtonComponent(
3130
buttonContainer: ViewGroup
3231
): MapboxNavigationObserver {
33-
val binderFlow = uiBinders.infoPanelRoutePreviewButtonBinder.map {
34-
it ?: InfoPanelRoutePreviewButtonBinder(this)
32+
val binderFlow = combine(
33+
options.showRoutePreviewButton,
34+
uiBinders.infoPanelRoutePreviewButtonBinder
35+
) { show, binder ->
36+
if (show) {
37+
binder ?: InfoPanelRoutePreviewButtonBinder(this)
38+
} else {
39+
EmptyBinder()
40+
}
3541
}
3642
return reloadOnChange(binderFlow) { it.bind(buttonContainer) }
3743
}
@@ -40,8 +46,15 @@ internal fun NavigationViewContext.routePreviewButtonComponent(
4046
internal fun NavigationViewContext.startNavigationButtonComponent(
4147
buttonContainer: ViewGroup
4248
): MapboxNavigationObserver {
43-
val binderFlow = uiBinders.infoPanelStartNavigationButtonBinder.map {
44-
it ?: InfoPanelStartNavigationButtonBinder(this)
49+
val binderFlow = combine(
50+
options.showStartNavigationButton,
51+
uiBinders.infoPanelStartNavigationButtonBinder
52+
) { show, binder ->
53+
if (show) {
54+
binder ?: InfoPanelStartNavigationButtonBinder(this)
55+
} else {
56+
EmptyBinder()
57+
}
4558
}
4659
return reloadOnChange(binderFlow) { it.bind(buttonContainer) }
4760
}
@@ -50,8 +63,15 @@ internal fun NavigationViewContext.startNavigationButtonComponent(
5063
internal fun NavigationViewContext.endNavigationButtonComponent(
5164
endNavigationButtonLayout: ViewGroup
5265
): MapboxNavigationObserver {
53-
val binderFlow = uiBinders.infoPanelEndNavigationButtonBinder.map {
54-
it ?: InfoPanelEndNavigationButtonBinder(this)
66+
val binderFlow = combine(
67+
options.showEndNavigationButton,
68+
uiBinders.infoPanelEndNavigationButtonBinder
69+
) { show, binder ->
70+
if (show) {
71+
binder ?: InfoPanelEndNavigationButtonBinder(this)
72+
} else {
73+
EmptyBinder()
74+
}
5575
}
5676
return reloadOnChange(binderFlow) { it.bind(endNavigationButtonLayout) }
5777
}
@@ -64,8 +84,15 @@ internal fun NavigationViewContext.arrivalTextComponent(textView: AppCompatTextV
6484
internal fun NavigationViewContext.tripProgressComponent(
6585
tripProgressLayout: ViewGroup
6686
): MapboxNavigationObserver {
67-
val binderFlow = uiBinders.infoPanelTripProgressBinder.map {
68-
it ?: TripProgressBinder(this)
87+
val binderFlow = combine(
88+
options.showTripProgress,
89+
uiBinders.infoPanelTripProgressBinder
90+
) { show, binder ->
91+
if (show) {
92+
binder ?: TripProgressBinder(this)
93+
} else {
94+
EmptyBinder()
95+
}
6996
}
7097
return reloadOnChange(binderFlow) { it.bind(tripProgressLayout) }
7198
}
@@ -93,8 +120,15 @@ internal fun NavigationViewContext.cameraModeButtonComponent(
93120
buttonContainer: ViewGroup,
94121
@Px verticalSpacing: Int
95122
): MapboxNavigationObserver {
96-
val binderFlow = uiBinders.actionCameraModeButtonBinder.map {
97-
it ?: CameraModeButtonBinder(this, verticalSpacing)
123+
val binderFlow = combine(
124+
options.showCameraModeActionButton,
125+
uiBinders.actionCameraModeButtonBinder
126+
) { show, binder ->
127+
if (show) {
128+
binder ?: CameraModeButtonBinder(this, verticalSpacing)
129+
} else {
130+
EmptyBinder()
131+
}
98132
}
99133
return reloadOnChange(binderFlow) { it.bind(buttonContainer) }
100134
}
@@ -104,8 +138,15 @@ internal fun NavigationViewContext.audioGuidanceButtonComponent(
104138
buttonContainer: ViewGroup,
105139
@Px verticalSpacing: Int
106140
): MapboxNavigationObserver {
107-
val binderFlow = uiBinders.actionToggleAudioButtonBinder.map {
108-
it ?: AudioGuidanceButtonBinder(this, verticalSpacing)
141+
val binderFlow = combine(
142+
options.showToggleAudioActionButton,
143+
uiBinders.actionToggleAudioButtonBinder
144+
) { show, binder ->
145+
if (show) {
146+
binder ?: AudioGuidanceButtonBinder(this, verticalSpacing)
147+
} else {
148+
EmptyBinder()
149+
}
109150
}
110151
return reloadOnChange(binderFlow) { it.bind(buttonContainer) }
111152
}
@@ -115,8 +156,15 @@ internal fun NavigationViewContext.recenterButtonComponent(
115156
buttonContainer: ViewGroup,
116157
@Px verticalSpacing: Int
117158
): MapboxNavigationObserver {
118-
val binderFlow = uiBinders.actionRecenterButtonBinder.map {
119-
it ?: RecenterButtonBinder(this, verticalSpacing)
159+
val binderFlow = combine(
160+
options.showRecenterActionButton,
161+
uiBinders.actionRecenterButtonBinder
162+
) { show, binder ->
163+
if (show) {
164+
binder ?: RecenterButtonBinder(this, verticalSpacing)
165+
} else {
166+
EmptyBinder()
167+
}
120168
}
121169
return reloadOnChange(binderFlow) { it.bind(buttonContainer) }
122170
}

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
88
import com.mapbox.navigation.ui.app.internal.navigation.NavigationState
99
import com.mapbox.navigation.ui.base.lifecycle.UIBinder
1010
import com.mapbox.navigation.ui.base.lifecycle.UICoordinator
11-
import kotlinx.coroutines.ExperimentalCoroutinesApi
1211
import kotlinx.coroutines.flow.Flow
13-
import kotlinx.coroutines.flow.flatMapLatest
14-
import kotlinx.coroutines.flow.map
12+
import kotlinx.coroutines.flow.combine
1513

1614
/**
1715
* Coordinator for navigation guidance.
@@ -25,17 +23,17 @@ internal class ManeuverCoordinator(
2523

2624
private val store = context.store
2725

28-
@OptIn(ExperimentalCoroutinesApi::class)
2926
override fun MapboxNavigation.flowViewBinders(): Flow<UIBinder> {
30-
return store.select { it.navigation }
31-
.flatMapLatest { navigationState ->
32-
context.uiBinders.maneuver.map {
33-
if (navigationState == NavigationState.ActiveNavigation) {
34-
it ?: ManeuverViewBinder(context)
35-
} else {
36-
EmptyBinder()
37-
}
38-
}
27+
return combine(
28+
context.options.showManeuver,
29+
context.uiBinders.maneuver,
30+
store.select { it.navigation }
31+
) { show, binder, navigationState ->
32+
if (show && navigationState == NavigationState.ActiveNavigation) {
33+
binder ?: ManeuverViewBinder(context)
34+
} else {
35+
EmptyBinder()
3936
}
37+
}
4038
}
4139
}

0 commit comments

Comments
 (0)