Skip to content

Commit a412601

Browse files
committed
Add route callout customization example
1 parent 3382b0a commit a412601

20 files changed

+548
-222
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ android {
7373

7474
dependencies {
7575
// Mapbox Navigation SDK
76-
implementation "com.mapbox.navigationcore:navigation:3.5.0-beta.1"
77-
implementation "com.mapbox.navigationcore:ui-components:3.3.0"
76+
implementation "com.mapbox.navigationcore:navigation:3.8.0-rc.1"
77+
implementation "com.mapbox.navigationcore:ui-components:3.8.0-rc.1"
7878

7979
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.21"
8080
implementation "androidx.core:core-ktx:1.9.0"

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
android:exported="false"
2828
/>
2929

30-
<activity android:name=".standalone.callout.RouteCalloutActivity"
30+
<activity android:name=".standalone.callout.CustomRouteCalloutActivity"
3131
android:screenOrientation="portrait"
3232
android:exported="false"
3333
/>

app/src/main/java/com/mapbox/navigation/examples/standalone/StandaloneExamplesList.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.mapbox.navigation.examples.R
77
import com.mapbox.navigation.examples.standalone.alternative.ShowAlternativeRoutesActivity
88
import com.mapbox.navigation.examples.standalone.arrival.CustomArrivalActivity
99
import com.mapbox.navigation.examples.standalone.building.ShowBuildingExtrusionsActivity
10-
import com.mapbox.navigation.examples.standalone.callout.RouteCalloutActivity
10+
import com.mapbox.navigation.examples.standalone.callout.CustomRouteCalloutActivity
1111
import com.mapbox.navigation.examples.standalone.camera.ShowCameraTransitionsActivity
1212
import com.mapbox.navigation.examples.standalone.custompuck.CustomPuckActivity
1313
import com.mapbox.navigation.examples.standalone.fetchroute.FetchARouteActivity
@@ -26,10 +26,10 @@ import com.mapbox.navigation.examples.standalone.waypoints.MultipleWaypointsActi
2626

2727
fun Context.examplesList() = listOf(
2828
MapboxExample(
29-
ContextCompat.getDrawable(this, R.drawable.mapbox_screenshot_route_callout),
29+
ContextCompat.getDrawable(this, R.drawable.mapbox_screenshot_custom_route_callout),
3030
getString(R.string.title_show_route_callouts),
3131
getString(R.string.description_show_route_callouts),
32-
RouteCalloutActivity::class.java
32+
CustomRouteCalloutActivity::class.java
3333
),
3434
MapboxExample(
3535
ContextCompat.getDrawable(this, R.drawable.mapbox_ic_user_current_location),
@@ -44,7 +44,7 @@ fun Context.examplesList() = listOf(
4444
FetchARouteActivity::class.java
4545
),
4646
MapboxExample(
47-
ContextCompat.getDrawable(this, R.drawable.mapbox_ic_route_line),
47+
ContextCompat.getDrawable(this, R.drawable.mapbox_screenshot_route_lines),
4848
getString(R.string.title_route),
4949
getString(R.string.description_route),
5050
RenderRouteLineActivity::class.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.mapbox.navigation.examples.standalone.callout
2+
3+
import android.graphics.Bitmap
4+
import android.graphics.Canvas
5+
import android.graphics.drawable.BitmapDrawable
6+
import android.graphics.drawable.Drawable
7+
import androidx.annotation.ColorInt
8+
9+
/**
10+
* Utility class to work with bitmaps and drawables.
11+
*/
12+
object BitmapUtils {
13+
14+
fun drawableToBitmap(
15+
sourceDrawable: Drawable?,
16+
flipX: Boolean = false,
17+
flipY: Boolean = false,
18+
@ColorInt tint: Int? = null,
19+
): Bitmap? {
20+
if (sourceDrawable == null) {
21+
return null
22+
}
23+
return if (sourceDrawable is BitmapDrawable) {
24+
sourceDrawable.bitmap
25+
} else {
26+
// copying drawable object to not manipulate on the same reference
27+
val constantState = sourceDrawable.constantState ?: return null
28+
val drawable = constantState.newDrawable().mutate()
29+
val bitmap = Bitmap.createBitmap(
30+
drawable.intrinsicWidth, drawable.intrinsicHeight,
31+
Bitmap.Config.ARGB_8888
32+
)
33+
tint?.let(drawable::setTint)
34+
val canvas = Canvas(bitmap)
35+
drawable.setBounds(0, 0, canvas.width, canvas.height)
36+
canvas.scale(
37+
if (flipX) -1f else 1f,
38+
if (flipY) -1f else 1f,
39+
canvas.width / 2f,
40+
canvas.height / 2f
41+
)
42+
drawable.draw(canvas)
43+
bitmap
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)