Skip to content

Commit 92ae2eb

Browse files
authored
add option to specify custom location puck with drop-in
1 parent 25ba11f commit 92ae2eb

File tree

10 files changed

+102
-160
lines changed

10 files changed

+102
-160
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ Mapbox welcomes participation and contributions from everyone.
77
- Moved `MapboxAudioGuidance` and `MapboxAudioGuidanceState` into public api. [#6336](https://github.com/mapbox/mapbox-navigation-android/pull/6336)
88
- Introduced `ViewOptionsCustomization.showCameraDebugInfo` to allow end users to enable camera debug info. [#6356](https://github.com/mapbox/mapbox-navigation-android/pull/6356)
99
- Added `ComponentInstaller` for the `LocationComponent` that offers simplified integration of map LocationPuck. [#6206](https://github.com/mapbox/mapbox-navigation-android/pull/6206)
10+
- Added `ViewStyleCustomization.locationPuck` that allows to define a custom location puck using `NavigationView`. [#6365](https://github.com/mapbox/mapbox-navigation-android/pull/6365)
1011
#### Bug fixes and improvements
1112
- Marked `PredictiveCacheController`, `MapboxBuildingView`, `ViewportDataSourceUpdateObserver`, `NavigationScaleGestureHandler`, `NavigationCameraStateChangedObserver`, `NavigationCameraStateTransition`, `NavigationCameraTransition`, `TransitionEndListener`, `MapboxRecenterButton`, `MapboxRouteOverviewButton`, `MapboxJunctionView`, `MapboxSignboardView`, `MapboxRoadNameLabelView`, `MapboxRoadNameView`, `MapboxRouteArrowView`, `MapboxRouteLineView`, `MapboxCameraModeButton` methods and `View.capture` extension with `@UiThread` annotation. [#6235](https://github.com/mapbox/mapbox-navigation-android/pull/6235)
1213
- Marked `Binder`, `MapboxExtendableButton` methods and `MapboxNavigation#installComponents` methods with `@UiThread` annotation. [#6268](https://github.com/mapbox/mapbox-navigation-android/pull/6268)
1314
- Fixed an issue with `NavigationView` that caused `ViewOptionsCustomization.routeArrowOptions` to be ignored, if arrows have already been drawn on the map. [#6333](https://github.com/mapbox/mapbox-navigation-android/pull/6333)
15+
- Replaced `ViewStyleCustomization.defaultMarkerAnnotationOptions` with `ViewStyleCustomization.defaultDestinationMarkerAnnotationOptions`. [#6365](https://github.com/mapbox/mapbox-navigation-android/pull/6365)
1416

1517
## Mapbox Navigation SDK 2.9.0-alpha.2 - 16 September, 2022
1618
### Changelog

libnavigation-core/api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,13 @@ package com.mapbox.navigation.core.routealternatives {
676676
}
677677

678678
public final class AlternativeRouteMetadata {
679+
method public int getAlternativeId();
679680
method public com.mapbox.navigation.core.routealternatives.AlternativeRouteIntersection getForkIntersectionOfAlternativeRoute();
680681
method public com.mapbox.navigation.core.routealternatives.AlternativeRouteIntersection getForkIntersectionOfPrimaryRoute();
681682
method public com.mapbox.navigation.core.routealternatives.AlternativeRouteInfo getInfoFromFork();
682683
method public com.mapbox.navigation.core.routealternatives.AlternativeRouteInfo getInfoFromStartOfPrimary();
683684
method public com.mapbox.navigation.base.route.NavigationRoute getNavigationRoute();
685+
property public final int alternativeId;
684686
property public final com.mapbox.navigation.core.routealternatives.AlternativeRouteIntersection forkIntersectionOfAlternativeRoute;
685687
property public final com.mapbox.navigation.core.routealternatives.AlternativeRouteIntersection forkIntersectionOfPrimaryRoute;
686688
property public final com.mapbox.navigation.core.routealternatives.AlternativeRouteInfo infoFromFork;

libnavui-dropin/api/current.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ package com.mapbox.navigation.dropin {
216216
method public Integer? getInfoPanelMarginEnd();
217217
method public Integer? getInfoPanelMarginStart();
218218
method public Integer? getInfoPanelPeekHeight();
219+
method public com.mapbox.maps.plugin.LocationPuck? getLocationPuck();
219220
method public com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions? getManeuverViewOptions();
220221
method public Integer? getPoiNameTextAppearance();
221222
method public com.mapbox.navigation.dropin.MapboxExtendableButtonParams? getRecenterButtonParams();
@@ -235,6 +236,7 @@ package com.mapbox.navigation.dropin {
235236
method public void setInfoPanelMarginEnd(Integer?);
236237
method public void setInfoPanelMarginStart(Integer?);
237238
method public void setInfoPanelPeekHeight(Integer?);
239+
method public void setLocationPuck(com.mapbox.maps.plugin.LocationPuck?);
238240
method public void setManeuverViewOptions(com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions?);
239241
method public void setPoiNameTextAppearance(Integer?);
240242
method public void setRecenterButtonParams(com.mapbox.navigation.dropin.MapboxExtendableButtonParams?);
@@ -254,6 +256,7 @@ package com.mapbox.navigation.dropin {
254256
property public final Integer? infoPanelMarginEnd;
255257
property public final Integer? infoPanelMarginStart;
256258
property public final Integer? infoPanelPeekHeight;
259+
property public final com.mapbox.maps.plugin.LocationPuck? locationPuck;
257260
property public final com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions? maneuverViewOptions;
258261
property public final Integer? poiNameTextAppearance;
259262
property public final com.mapbox.navigation.dropin.MapboxExtendableButtonParams? recenterButtonParams;
@@ -271,13 +274,14 @@ package com.mapbox.navigation.dropin {
271274
method @StyleRes public int defaultArrivalTextAppearance();
272275
method public com.mapbox.navigation.dropin.MapboxExtendableButtonParams defaultAudioGuidanceButtonParams(android.content.Context context);
273276
method public com.mapbox.navigation.dropin.MapboxExtendableButtonParams defaultCameraModeButtonParams(android.content.Context context);
277+
method public com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions defaultDestinationMarkerAnnotationOptions(android.content.Context context);
274278
method public com.mapbox.navigation.dropin.MapboxExtendableButtonParams defaultEndNavigationButtonParams(android.content.Context context);
275279
method @DrawableRes public int defaultInfoPanelBackground();
276280
method @Px public int defaultInfoPanelMarginEnd();
277281
method @Px public int defaultInfoPanelMarginStart();
278282
method @Px public int defaultInfoPanelPeekHeight(android.content.Context context);
283+
method public com.mapbox.maps.plugin.LocationPuck defaultLocationPuck(android.content.Context context);
279284
method public com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions defaultManeuverViewOptions();
280-
method public com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions defaultMarkerAnnotationOptions(android.content.Context context);
281285
method @StyleRes public int defaultPoiNameTextAppearance();
282286
method public com.mapbox.navigation.dropin.MapboxExtendableButtonParams defaultRecenterButtonParams(android.content.Context context);
283287
method @DrawableRes public int defaultRoadNameBackground();
Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapbox.navigation.dropin
22

33
import android.content.Context
4+
import com.mapbox.maps.plugin.LocationPuck
45
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
56
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
67
import com.mapbox.navigation.ui.maneuver.model.ManeuverViewOptions
@@ -11,44 +12,46 @@ import kotlinx.coroutines.flow.asStateFlow
1112
@ExperimentalPreviewMapboxNavigationAPI
1213
internal class NavigationViewStyles(context: Context) {
1314

14-
private var _infoPanelPeekHeight: MutableStateFlow<Int> =
15+
private val _infoPanelPeekHeight: MutableStateFlow<Int> =
1516
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelPeekHeight(context))
16-
private var _infoPanelMarginStart: MutableStateFlow<Int> =
17+
private val _infoPanelMarginStart: MutableStateFlow<Int> =
1718
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelMarginStart())
18-
private var _infoPanelMarginEnd: MutableStateFlow<Int> =
19+
private val _infoPanelMarginEnd: MutableStateFlow<Int> =
1920
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelMarginEnd())
20-
private var _infoPanelBackground: MutableStateFlow<Int> =
21+
private val _infoPanelBackground: MutableStateFlow<Int> =
2122
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelBackground())
22-
private var _poiNameTextAppearance: MutableStateFlow<Int> =
23+
private val _poiNameTextAppearance: MutableStateFlow<Int> =
2324
MutableStateFlow(ViewStyleCustomization.defaultPoiNameTextAppearance())
24-
private var _tripProgressStyle: MutableStateFlow<Int> =
25+
private val _tripProgressStyle: MutableStateFlow<Int> =
2526
MutableStateFlow(ViewStyleCustomization.defaultTripProgressStyle())
26-
private var _audioGuidanceButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
27+
private val _audioGuidanceButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
2728
MutableStateFlow(ViewStyleCustomization.defaultAudioGuidanceButtonParams(context))
28-
private var _recenterButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
29+
private val _recenterButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
2930
MutableStateFlow(ViewStyleCustomization.defaultRecenterButtonParams(context))
30-
private var _cameraModeButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
31+
private val _cameraModeButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
3132
MutableStateFlow(ViewStyleCustomization.defaultCameraModeButtonParams(context))
32-
private var _routePreviewButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
33+
private val _routePreviewButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
3334
MutableStateFlow(ViewStyleCustomization.defaultRoutePreviewButtonParams(context))
34-
private var _endNavigationButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
35+
private val _endNavigationButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
3536
MutableStateFlow(ViewStyleCustomization.defaultEndNavigationButtonParams(context))
36-
private var _startNavigationButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
37+
private val _startNavigationButtonParams: MutableStateFlow<MapboxExtendableButtonParams> =
3738
MutableStateFlow(ViewStyleCustomization.defaultStartNavigationButtonParams(context))
38-
private var _speedLimitStyle: MutableStateFlow<Int> =
39+
private val _speedLimitStyle: MutableStateFlow<Int> =
3940
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitStyle())
40-
private var _speedLimitTextAppearance: MutableStateFlow<Int> =
41+
private val _speedLimitTextAppearance: MutableStateFlow<Int> =
4142
MutableStateFlow(ViewStyleCustomization.defaultSpeedLimitTextAppearance())
42-
private var _roadNameBackground: MutableStateFlow<Int> =
43+
private val _roadNameBackground: MutableStateFlow<Int> =
4344
MutableStateFlow(ViewStyleCustomization.defaultRoadNameBackground())
44-
private var _roadNameTextAppearance: MutableStateFlow<Int> =
45+
private val _roadNameTextAppearance: MutableStateFlow<Int> =
4546
MutableStateFlow(ViewStyleCustomization.defaultRoadNameTextAppearance())
46-
private var _maneuverViewOptions: MutableStateFlow<ManeuverViewOptions> =
47+
private val _maneuverViewOptions: MutableStateFlow<ManeuverViewOptions> =
4748
MutableStateFlow(ViewStyleCustomization.defaultManeuverViewOptions())
48-
private var _destinationMarkerAnnotationOptions: MutableStateFlow<PointAnnotationOptions> =
49-
MutableStateFlow(ViewStyleCustomization.defaultMarkerAnnotationOptions(context))
50-
private var _arrivalTextAppearance: MutableStateFlow<Int> =
49+
private val _destinationMarkerAnnotationOptions: MutableStateFlow<PointAnnotationOptions> =
50+
MutableStateFlow(ViewStyleCustomization.defaultDestinationMarkerAnnotationOptions(context))
51+
private val _arrivalTextAppearance: MutableStateFlow<Int> =
5152
MutableStateFlow(ViewStyleCustomization.defaultArrivalTextAppearance())
53+
private val _locationPuck: MutableStateFlow<LocationPuck> =
54+
MutableStateFlow(ViewStyleCustomization.defaultLocationPuck(context))
5255

5356
val infoPanelPeekHeight: StateFlow<Int> = _infoPanelPeekHeight.asStateFlow()
5457
val infoPanelMarginStart: StateFlow<Int> = _infoPanelMarginStart.asStateFlow()
@@ -76,32 +79,30 @@ internal class NavigationViewStyles(context: Context) {
7679
val roadNameTextAppearance: StateFlow<Int> = _roadNameTextAppearance.asStateFlow()
7780
val maneuverViewOptions: StateFlow<ManeuverViewOptions> = _maneuverViewOptions.asStateFlow()
7881
val arrivalTextAppearance: StateFlow<Int> = _arrivalTextAppearance.asStateFlow()
82+
val locationPuck: StateFlow<LocationPuck> = _locationPuck.asStateFlow()
7983

8084
fun applyCustomization(customization: ViewStyleCustomization) {
81-
customization.infoPanelPeekHeight?.also { _infoPanelPeekHeight.tryEmit(it) }
82-
customization.infoPanelMarginStart?.also { _infoPanelMarginStart.tryEmit(it) }
83-
customization.infoPanelMarginEnd?.also { _infoPanelMarginEnd.tryEmit(it) }
84-
customization.infoPanelBackground?.also { _infoPanelBackground.tryEmit(it) }
85-
customization.poiNameTextAppearance?.also { _poiNameTextAppearance.tryEmit(it) }
86-
customization.tripProgressStyle?.also { _tripProgressStyle.tryEmit(it) }
87-
customization.recenterButtonParams?.also { _recenterButtonParams.tryEmit(it) }
88-
customization.cameraModeButtonParams?.also {
89-
_cameraModeButtonParams.tryEmit(it)
90-
}
91-
customization.routePreviewButtonParams?.also { _routePreviewButtonParams.tryEmit(it) }
92-
customization.audioGuidanceButtonParams?.also {
93-
_audioGuidanceButtonParams.tryEmit(it)
94-
}
95-
customization.endNavigationButtonParams?.also { _endNavigationButtonParams.tryEmit(it) }
96-
customization.startNavigationButtonParams?.also { _startNavigationButtonParams.tryEmit(it) }
97-
customization.speedLimitStyle?.also { _speedLimitStyle.tryEmit(it) }
98-
customization.maneuverViewOptions?.also { _maneuverViewOptions.tryEmit(it) }
99-
customization.speedLimitTextAppearance?.also { _speedLimitTextAppearance.tryEmit(it) }
85+
customization.infoPanelPeekHeight?.also { _infoPanelPeekHeight.value = it }
86+
customization.infoPanelMarginStart?.also { _infoPanelMarginStart.value = it }
87+
customization.infoPanelMarginEnd?.also { _infoPanelMarginEnd.value = it }
88+
customization.infoPanelBackground?.also { _infoPanelBackground.value = it }
89+
customization.poiNameTextAppearance?.also { _poiNameTextAppearance.value = it }
90+
customization.tripProgressStyle?.also { _tripProgressStyle.value = it }
91+
customization.recenterButtonParams?.also { _recenterButtonParams.value = it }
92+
customization.cameraModeButtonParams?.also { _cameraModeButtonParams.value = it }
93+
customization.routePreviewButtonParams?.also { _routePreviewButtonParams.value = it }
94+
customization.audioGuidanceButtonParams?.also { _audioGuidanceButtonParams.value = it }
95+
customization.endNavigationButtonParams?.also { _endNavigationButtonParams.value = it }
96+
customization.startNavigationButtonParams?.also { _startNavigationButtonParams.value = it }
97+
customization.speedLimitStyle?.also { _speedLimitStyle.value = it }
98+
customization.maneuverViewOptions?.also { _maneuverViewOptions.value = it }
99+
customization.speedLimitTextAppearance?.also { _speedLimitTextAppearance.value = it }
100100
customization.destinationMarkerAnnotationOptions?.also {
101-
_destinationMarkerAnnotationOptions.tryEmit(it)
101+
_destinationMarkerAnnotationOptions.value = it
102102
}
103-
customization.roadNameBackground?.also { _roadNameBackground.tryEmit(it) }
104-
customization.roadNameTextAppearance?.also { _roadNameTextAppearance.tryEmit(it) }
105-
customization.arrivalTextAppearance?.also { _arrivalTextAppearance.tryEmit(it) }
103+
customization.roadNameBackground?.also { _roadNameBackground.value = it }
104+
customization.roadNameTextAppearance?.also { _roadNameTextAppearance.value = it }
105+
customization.arrivalTextAppearance?.also { _arrivalTextAppearance.value = it }
106+
customization.locationPuck?.also { _locationPuck.value = it }
106107
}
107108
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import androidx.annotation.StyleRes
88
import androidx.core.content.ContextCompat
99
import androidx.core.graphics.drawable.toBitmap
1010
import com.google.android.material.resources.TextAppearance
11+
import com.mapbox.maps.MapView
1112
import com.mapbox.maps.extension.style.layers.properties.generated.IconAnchor
13+
import com.mapbox.maps.plugin.LocationPuck
14+
import com.mapbox.maps.plugin.LocationPuck2D
1215
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
1316
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
1417
import com.mapbox.navigation.dropin.component.infopanel.ArrivalTextComponent
@@ -71,7 +74,7 @@ class ViewStyleCustomization {
7174

7275
/**
7376
* Provide [PointAnnotationOptions] for destination marker.
74-
* Use [defaultMarkerAnnotationOptions] to reset to default.
77+
* Use [defaultDestinationMarkerAnnotationOptions] to reset to default.
7578
*/
7679
var destinationMarkerAnnotationOptions: PointAnnotationOptions? = null
7780

@@ -159,6 +162,12 @@ class ViewStyleCustomization {
159162
@StyleRes
160163
var arrivalTextAppearance: Int? = null
161164

165+
/**
166+
* Provide custom [LocationPuck] for [MapView].
167+
* Use [defaultLocationPuck] to reset to default.
168+
*/
169+
var locationPuck: LocationPuck? = null
170+
162171
companion object {
163172
/**
164173
* Default info panel peek height in pixels.
@@ -188,7 +197,7 @@ class ViewStyleCustomization {
188197
/**
189198
* Default [PointAnnotationOptions] for showing destination marker.
190199
*/
191-
fun defaultMarkerAnnotationOptions(context: Context): PointAnnotationOptions =
200+
fun defaultDestinationMarkerAnnotationOptions(context: Context): PointAnnotationOptions =
192201
PointAnnotationOptions().apply {
193202
withIconImage(
194203
ContextCompat.getDrawable(
@@ -353,6 +362,16 @@ class ViewStyleCustomization {
353362
)
354363
.build()
355364

365+
/**
366+
* Default [LocationPuck] for [MapView].
367+
*/
368+
fun defaultLocationPuck(context: Context): LocationPuck = LocationPuck2D(
369+
bearingImage = ContextCompat.getDrawable(
370+
context,
371+
R.drawable.mapbox_navigation_puck_icon,
372+
)
373+
)
374+
356375
private fun Context.defaultSpacing() =
357376
resources.getDimensionPixelSize(R.dimen.mapbox_actionList_spacing)
358377

0 commit comments

Comments
 (0)