Skip to content

Commit eeda372

Browse files
committed
Add the attribution text glow effect
1 parent e167f54 commit eeda372

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

gradle/libs.versions.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ dokka = "2.1.0"
77
nmcp = "1.2.0"
88

99
# AndroidX Core
10-
androidx-core = "1.15.0"
11-
androidx-lifecycle = "2.8.7"
12-
androidx-activity = "1.9.3"
13-
androidx-test-core = "1.6.1"
14-
androidx-test-runner = "1.6.2"
15-
androidx-test-rules = "1.6.1"
16-
androidx-test-junit = "1.2.1"
10+
androidx-core = "1.17.0"
11+
androidx-lifecycle = "2.9.4"
12+
androidx-activity = "1.11.0"
13+
androidx-test-core = "1.7.0"
14+
androidx-test-runner = "1.7.0"
15+
androidx-test-rules = "1.7.0"
16+
androidx-test-junit = "1.3.0"
1717

1818
# Compose
19-
compose-ui = "1.7.5"
20-
compose-ui-graphics = "1.7.6"
21-
compose-material3 = "1.3.1"
19+
compose-ui = "1.9.4"
20+
compose-ui-graphics = "1.9.4"
21+
compose-material3 = "1.4.0"
2222

2323
# Networking
24-
ktor = "2.3.7"
24+
ktor = "3.3.2"
2525

2626
# Utilities
2727
disklrucache = "2.0.2"
2828

2929
# Testing
3030
junit = "4.13.2"
31-
mockk = "1.13.8"
32-
robolectric = "4.14"
33-
kotlinx-coroutines = "1.9.0"
31+
mockk = "1.14.6"
32+
robolectric = "4.16"
33+
kotlinx-coroutines = "1.10.2"
3434

3535
# Code Quality
3636
ktlint = "1.3.1"

openmapview/src/main/kotlin/de/afarber/openmapview/AttributionOverlay.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package de.afarber.openmapview
99

1010
import android.content.Context
11+
import android.graphics.BlurMaskFilter
1112
import android.graphics.Canvas
1213
import android.graphics.Color
1314
import android.graphics.Paint
@@ -26,21 +27,33 @@ class AttributionOverlay(
2627
private var attributionText = "© OpenStreetMap contributors"
2728
private var attributionUrl = "https://www.openstreetmap.org/copyright"
2829

30+
private val density = context.resources.displayMetrics.density
31+
2932
private val textPaint =
3033
TextPaint().apply {
3134
color = Color.BLACK
32-
textSize = 12f * context.resources.displayMetrics.density
35+
textSize = 12f * density
3336
isAntiAlias = true
3437
}
3538

39+
private val glowPaint =
40+
TextPaint().apply {
41+
color = Color.WHITE
42+
textSize = 12f * density
43+
isAntiAlias = true
44+
maskFilter = BlurMaskFilter(5f * density, BlurMaskFilter.Blur.NORMAL)
45+
}
46+
3647
private val backgroundPaint =
3748
Paint().apply {
3849
color = Color.argb(180, 255, 255, 255)
3950
style = Paint.Style.FILL
4051
}
4152

4253
private var textBounds = Rect()
43-
private val padding = (4 * context.resources.displayMetrics.density).toInt()
54+
private val padding = (4 * density).toInt()
55+
56+
var isGlowEnabled: Boolean = true
4457

4558
var onAttributionClickListener: (() -> Unit)? = null
4659

@@ -96,6 +109,9 @@ class AttributionOverlay(
96109
val textX = viewWidth - textWidth - padding
97110
val textY = viewHeight - padding
98111

112+
if (isGlowEnabled) {
113+
canvas.drawText(attributionText, textX.toFloat(), textY.toFloat(), glowPaint)
114+
}
99115
canvas.drawText(attributionText, textX.toFloat(), textY.toFloat(), textPaint)
100116
}
101117

openmapview/src/main/kotlin/de/afarber/openmapview/OpenMapView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class OpenMapView
105105
controller.setOnTileLoadedCallback {
106106
invalidate()
107107
}
108+
attributionOverlay.isGlowEnabled = uiSettings.isAttributionGlowEnabled
108109
}
109110

110111
override fun dispatchDraw(canvas: Canvas) {
@@ -113,6 +114,7 @@ class OpenMapView
113114
if (uiSettings.isZoomControlsEnabled) {
114115
zoomControlsOverlay.draw(canvas, width, height)
115116
}
117+
attributionOverlay.isGlowEnabled = uiSettings.isAttributionGlowEnabled
116118
attributionOverlay.draw(canvas, width, height)
117119
}
118120

openmapview/src/main/kotlin/de/afarber/openmapview/UiSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ class UiSettings {
3838
*/
3939
var isScrollGesturesEnabledDuringRotateOrZoom: Boolean = true
4040

41+
/**
42+
* Whether the attribution text glow effect is enabled.
43+
* When true, attribution text is rendered with a white glow/halo effect.
44+
* Default is true.
45+
*/
46+
var isAttributionGlowEnabled: Boolean = true
47+
4148
/**
4249
* Whether rotate gestures are enabled.
4350
* Currently not implemented, always returns false.

0 commit comments

Comments
 (0)