Skip to content

Commit 5d52e38

Browse files
Updated the default, NavigationView navigation puck. (#6678)
Added QA-Test-App “use legacy puck” toggle. Updated navigation puck vector drawable. CHANGELOG entry Updated navigation puck asset. Added NavPuck spinner to QA-Test-App. More changes to puck asset Using RenderScript to apply blurred shadow to new navigation puck.
1 parent 67a81b4 commit 5d52e38

12 files changed

Lines changed: 227 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ Mapbox welcomes participation and contributions from everyone.
55
## Unreleased
66
#### Features
77
#### Bug fixes and improvements
8+
- :warning: Updated the `NavigationView` default navigation puck asset. [#6678](https://github.com/mapbox/mapbox-navigation-android/pull/6678)
9+
10+
Previous puck can be restored by injecting `LocationPuck2D` with the `bearingImage` set to `com.mapbox.navigation.ui.maps.R.drawable.mapbox_navigation_puck_icon` drawable:
11+
```kotlin
12+
navigationView.customizeViewStyles {
13+
locationPuckOptions = LocationPuckOptions.Builder(context)
14+
.defaultPuck(
15+
LocationPuck2D(
16+
bearingImage = ContextCompat.getDrawable(
17+
context,
18+
com.mapbox.navigation.ui.maps.R.drawable.mapbox_navigation_puck_icon,
19+
)
20+
)
21+
)
22+
.idlePuck(regularPuck(context))
23+
.build()
24+
}
25+
```
826

927
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
1028
### Changelog

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/puck/LocationPuckOptions.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.mapbox.maps.plugin.LocationPuck3D
88
import com.mapbox.navigation.ui.maps.R
99
import com.mapbox.navigation.ui.maps.camera.state.NavigationCameraState
1010
import com.mapbox.navigation.ui.maps.puck.LocationPuckOptions.Builder
11+
import com.mapbox.navigation.ui.utils.internal.extensions.withBlurEffect
1112

1213
/**
1314
* Gives options to specify either [LocationPuck2D] or [LocationPuck3D] references to the location
@@ -212,8 +213,12 @@ class LocationPuckOptions private constructor(
212213
fun navigationPuck(context: Context): LocationPuck = LocationPuck2D(
213214
bearingImage = ContextCompat.getDrawable(
214215
context,
215-
R.drawable.mapbox_navigation_puck_icon,
216-
)
216+
R.drawable.mapbox_navigation_puck_icon2,
217+
),
218+
shadowImage = ContextCompat.getDrawable(
219+
context,
220+
R.drawable.mapbox_navigation_puck_icon2_shadow,
221+
)?.withBlurEffect(context, 7.5f)
217222
)
218223

219224
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="64dp"
4+
android:height="64dp"
5+
android:viewportWidth="64"
6+
android:viewportHeight="64">
7+
<path
8+
android:pathData="M28.569,12.285C29.605,9.923 32.941,9.883 34.034,12.219L51.713,50.026C52.88,52.52 50.35,55.137 47.817,54.055L36.59,49.26C33.488,47.934 29.97,47.977 26.9,49.376L15.791,54.439C13.285,55.581 10.693,53.026 11.8,50.504L28.569,12.285Z"
9+
android:fillColor="@color/colorPrimary"/>
10+
<path
11+
android:pathData="M36.751,10.948L54.431,48.754C56.764,53.744 51.704,58.977 46.639,56.814L35.412,52.018C33.085,51.024 30.447,51.056 28.144,52.105L17.035,57.168C12.023,59.453 6.84,54.342 9.053,49.298L25.822,11.079C27.894,6.356 34.566,6.276 36.751,10.948ZM34.034,12.219C32.941,9.883 29.605,9.923 28.569,12.285L11.8,50.503C10.693,53.025 13.285,55.581 15.791,54.439L26.9,49.376C29.97,47.976 33.488,47.934 36.591,49.259L47.818,54.055C50.35,55.137 52.88,52.52 51.713,50.025L34.034,12.219Z"
12+
android:fillColor="#ffffff"
13+
android:fillType="evenOdd"/>
14+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="64dp"
4+
android:height="64dp"
5+
android:viewportWidth="64"
6+
android:viewportHeight="64">
7+
<path
8+
android:pathData="M36.751,10.948L54.431,48.754C56.764,53.744 51.704,58.977 46.639,56.814L35.412,52.018C33.085,51.024 30.447,51.056 28.144,52.105L17.035,57.168C12.023,59.453 6.84,54.342 9.053,49.298L25.822,11.079C27.894,6.356 34.566,6.276 36.751,10.948ZM34.034,12.219C32.941,9.883 29.605,9.923 28.569,12.285L11.8,50.503C10.693,53.025 13.285,55.581 15.791,54.439L26.9,49.376C29.97,47.976 33.488,47.934 36.591,49.259L47.818,54.055C50.35,55.137 52.88,52.52 51.713,50.025L34.034,12.219Z"
9+
android:fillColor="#29263D57"
10+
android:fillType="evenOdd"/>
11+
</vector>

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/puck/LocationPuckOptionsTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
package com.mapbox.navigation.ui.maps.puck
22

33
import android.content.Context
4+
import android.graphics.drawable.Drawable
5+
import androidx.core.content.ContextCompat
46
import com.mapbox.navigation.testing.BuilderTest
7+
import com.mapbox.navigation.ui.utils.internal.extensions.withBlurEffect
8+
import io.mockk.every
59
import io.mockk.mockk
10+
import io.mockk.mockkStatic
11+
import org.junit.Before
612
import kotlin.reflect.KClass
713

814
class LocationPuckOptionsTest :
915
BuilderTest<LocationPuckOptions, LocationPuckOptions.Builder>() {
1016

1117
private val context: Context = mockk(relaxed = true)
1218

19+
@Before
20+
fun setUp() {
21+
mockkStatic(Drawable::withBlurEffect)
22+
mockkStatic(ContextCompat::getDrawable)
23+
every { ContextCompat.getDrawable(any(), any()) } returns mockk {
24+
every { withBlurEffect(any(), any()) } returns mockk()
25+
}
26+
}
27+
1328
override fun getImplementationClass(): KClass<LocationPuckOptions> = LocationPuckOptions::class
1429

1530
override fun getFilledUpBuilder(): LocationPuckOptions.Builder {

libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/extensions/DrawableEx.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.mapbox.navigation.ui.utils.internal.extensions
22

3+
import android.content.Context
34
import android.graphics.Bitmap
45
import android.graphics.Canvas
56
import android.graphics.drawable.BitmapDrawable
67
import android.graphics.drawable.Drawable
8+
import android.renderscript.Allocation
9+
import android.renderscript.Element
10+
import android.renderscript.RenderScript
11+
import android.renderscript.ScriptIntrinsicBlur
12+
import kotlin.math.roundToInt
713

814
/**
915
* Converts a [Drawable] to [Bitmap]
@@ -25,3 +31,35 @@ fun Drawable.getBitmap(): Bitmap {
2531
bitmap
2632
}
2733
}
34+
35+
/**
36+
* Return Drawable with blur effect.
37+
*/
38+
fun Drawable.withBlurEffect(context: Context, radius: Float): Drawable {
39+
return BitmapDrawable(
40+
context.resources,
41+
blurBitmap(context, getBitmap(), radius)
42+
)
43+
}
44+
45+
private fun blurBitmap(
46+
context: Context,
47+
image: Bitmap,
48+
radius: Float,
49+
scale: Float = 1.0f
50+
): Bitmap = runCatching {
51+
val width = (image.width * scale).roundToInt()
52+
val height = (image.height * scale).roundToInt()
53+
val inputBitmap = Bitmap.createScaledBitmap(image, width, height, false)
54+
val outputBitmap = Bitmap.createBitmap(inputBitmap)
55+
val rs = RenderScript.create(context)
56+
val intrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
57+
val tmpIn = Allocation.createFromBitmap(rs, inputBitmap)
58+
val tmpOut = Allocation.createFromBitmap(rs, outputBitmap)
59+
intrinsic.setRadius(radius)
60+
intrinsic.setInput(tmpIn)
61+
intrinsic.forEach(tmpOut)
62+
tmpOut.copyTo(outputBitmap)
63+
rs.destroy()
64+
outputBitmap
65+
}.getOrDefault(image) // return original image on failure

qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/customnavview/CustomizedViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CustomizedViewModel : ViewModel() {
2525
val enableScalebar = MutableLiveData(false)
2626
val enableBuildingHighlight = MutableLiveData(true)
2727
val enableBuildingHighlightCustomization = MutableLiveData(false)
28+
val navigationPuck = MutableLiveData("--")
2829

2930
// Action Buttons
3031
val actionsShowCompassButton = MutableLiveData(false)

qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/customnavview/MapboxNavigationViewCustomizedActivity.kt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.navigation.qa_test_app.view.customnavview
22

3+
import android.content.Context
34
import android.graphics.Color
45
import android.location.Location
56
import android.os.Bundle
@@ -22,8 +23,11 @@ import com.mapbox.api.directions.v5.models.RouteOptions
2223
import com.mapbox.geojson.Point
2324
import com.mapbox.maps.MapView
2425
import com.mapbox.maps.Style
26+
import com.mapbox.maps.extension.style.expressions.dsl.generated.literal
2527
import com.mapbox.maps.extension.style.layers.properties.generated.IconAnchor
28+
import com.mapbox.maps.plugin.LocationPuck
2629
import com.mapbox.maps.plugin.LocationPuck2D
30+
import com.mapbox.maps.plugin.LocationPuck3D
2731
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
2832
import com.mapbox.maps.plugin.gestures.OnMapLongClickListener
2933
import com.mapbox.maps.plugin.gestures.gestures
@@ -86,6 +90,7 @@ import com.mapbox.navigation.ui.base.lifecycle.UIComponent
8690
import com.mapbox.navigation.ui.maps.NavigationStyles
8791
import com.mapbox.navigation.ui.maps.building.model.MapboxBuildingHighlightOptions
8892
import com.mapbox.navigation.ui.maps.puck.LocationPuckOptions
93+
import com.mapbox.navigation.ui.maps.puck.LocationPuckOptions.Builder.Companion.regularPuck
8994
import com.mapbox.navigation.ui.voice.model.SpeechAnnouncement
9095
import com.mapbox.navigation.utils.internal.toPoint
9196

@@ -443,6 +448,26 @@ class MapboxNavigationViewCustomizedActivity : DrawerActivity() {
443448
viewModel.enableBuildingHighlightCustomization,
444449
::toggleBuildingHighlightCustomization
445450
)
451+
452+
bindSpinner(
453+
menuBinding.spinnerNavPuck,
454+
viewModel.navigationPuck,
455+
::toggleNavigationPuck
456+
)
457+
}
458+
459+
private fun toggleNavigationPuck(name: String) {
460+
val context = this
461+
binding.navigationView.customizeViewStyles {
462+
locationPuckOptions = if (name == "--") {
463+
LocationPuckOptions.Builder(context).build()
464+
} else {
465+
LocationPuckOptions.Builder(context)
466+
.defaultPuck(NavPuck.valueOf(name).getLocationPuck(context))
467+
.idlePuck(regularPuck(context))
468+
.build()
469+
}
470+
}
446471
}
447472

448473
private fun toggleCustomMap(enabled: Boolean) {
@@ -1071,4 +1096,40 @@ class MapboxNavigationViewCustomizedActivity : DrawerActivity() {
10711096
onBackPressedDispatcher.addCallback(owner = this, enabled = false) {
10721097
binding.navigationView.api.startFreeDrive()
10731098
}
1099+
1100+
private enum class NavPuck(
1101+
val getLocationPuck: (context: Context) -> LocationPuck
1102+
) {
1103+
NAV_PUCK_2A({ context ->
1104+
LocationPuck2D(
1105+
bearingImage = ContextCompat.getDrawable(
1106+
context,
1107+
R.drawable.mapbox_navigation_puck_icon2a,
1108+
)
1109+
)
1110+
}),
1111+
NAV_PUCK_2B({ context ->
1112+
LocationPuck2D(
1113+
bearingImage = ContextCompat.getDrawable(
1114+
context,
1115+
R.drawable.mapbox_navigation_puck_icon2b,
1116+
)
1117+
)
1118+
}),
1119+
LEGACY({ context ->
1120+
LocationPuck2D(
1121+
bearingImage = ContextCompat.getDrawable(
1122+
context,
1123+
com.mapbox.navigation.ui.maps.R.drawable.mapbox_navigation_puck_icon,
1124+
)
1125+
)
1126+
}),
1127+
QUACK_QUACK({
1128+
LocationPuck3D(
1129+
modelUri = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF-Embedded/Duck.gltf", // ktlint-disable
1130+
modelScaleExpression = literal(listOf(30, 30, 30)).toJson(),
1131+
modelRotation = listOf(0f, 0f, -90f)
1132+
)
1133+
});
1134+
}
10741135
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="56dp"
4+
android:height="59dp"
5+
android:viewportWidth="56"
6+
android:viewportHeight="59">
7+
8+
<path
9+
android:pathData="M46.972,44.72L31.124,10.83C29.668,7.715 25.22,7.769 23.838,10.918L8.806,45.177C7.331,48.54 10.787,51.947 14.128,50.424L23.462,46.17C26.276,44.887 29.501,44.848 32.345,46.063L41.778,50.092C45.155,51.535 48.528,48.046 46.972,44.72Z"
10+
android:strokeLineJoin="round"
11+
android:strokeWidth="2"
12+
android:fillColor="@color/colorPrimary"
13+
android:strokeColor="#ffffff"/>
14+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="61dp"
4+
android:height="65dp"
5+
android:viewportWidth="61"
6+
android:viewportHeight="65">
7+
<path
8+
android:pathData="M27.538,12.341C28.574,9.979 31.91,9.939 33.003,12.275L50.683,50.081C51.849,52.576 49.319,55.193 46.787,54.111L35.56,49.315C32.457,47.99 28.94,48.032 25.869,49.432L14.761,54.495C12.255,55.637 9.663,53.082 10.769,50.56L27.538,12.341Z"
9+
android:fillColor="@color/colorPrimary"/>
10+
<path
11+
android:pathData="M52.042,49.446L34.362,11.64C32.723,8.136 27.719,8.196 26.165,11.738L9.396,49.957C7.736,53.74 11.624,57.573 15.383,55.86L26.492,50.797C29.178,49.572 32.256,49.535 34.971,50.695L46.198,55.49C49.997,57.113 53.792,53.188 52.042,49.446Z"
12+
android:strokeLineJoin="round"
13+
android:strokeWidth="3"
14+
android:fillColor="#00000000"
15+
android:strokeColor="#ffffff"/>
16+
</vector>

0 commit comments

Comments
 (0)