Skip to content

Commit 4a0e30a

Browse files
evil159kiryldz
andauthored
Update examples for view annotation priority (#2904)
* Update examples for view annotation priority * lint * Update mapbox-maps-android/CHANGELOG.md Co-authored-by: Kiryl Dzehtsiarenka <[email protected]> * Add comment --------- Co-authored-by: Kiryl Dzehtsiarenka <[email protected]>
1 parent f30a797 commit 4a0e30a

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone.
55
# main
66
## Features ✨ and improvements 🏁
77
* Localize geofencing attribution dialog.
8+
* Introduce `ViewAnnotationOptions.priority`, deprecate `ViewAnnotationOptions.selected`. Use this property to define view annotation sort order.
89

910

1011
# 11.9.0 December 18, 2024

app/src/main/java/com/mapbox/maps/testapp/examples/markersandcallouts/viewannotation/ViewAnnotationBasicAddActivity.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class ViewAnnotationBasicAddActivity : AppCompatActivity(), OnMapClickListener {
3030
private lateinit var viewAnnotationManager: ViewAnnotationManager
3131
private val viewAnnotationViews = mutableListOf<View>()
3232

33+
// Increase-on-access priority assigned to the most recent selected annotation,
34+
// keeping it on top of other selected annotation.
35+
private var topPriority: Long = 0
36+
get() = ++field
37+
3338
override fun onCreate(savedInstanceState: Bundle?) {
3439
super.onCreate(savedInstanceState)
3540
val binding = ActivityViewAnnotationShowcaseBinding.inflate(layoutInflater)
@@ -112,7 +117,8 @@ class ViewAnnotationBasicAddActivity : AppCompatActivity(), OnMapClickListener {
112117
viewAnnotationManager.updateViewAnnotation(
113118
viewAnnotation,
114119
viewAnnotationOptions {
115-
selected(isSelected)
120+
allowOverlap(true)
121+
priority(if (isSelected) topPriority else 0)
116122
}
117123
)
118124
(button.layoutParams as ViewGroup.MarginLayoutParams).apply {

app/src/main/java/com/mapbox/maps/testapp/examples/markersandcallouts/viewannotation/ViewAnnotationShowcaseActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ViewAnnotationShowcaseActivity :
219219
viewAnnotationManager.updateViewAnnotation(
220220
viewAnnotation,
221221
viewAnnotationOptions {
222-
selected(isSelected)
222+
priority(if (isSelected) 1 else 0)
223223
}
224224
)
225225
(button.layoutParams as ViewGroup.MarginLayoutParams).apply {

app/src/main/java/com/mapbox/maps/testapp/examples/markersandcallouts/viewannotation/ViewAnnotationWithPointAnnotationActivity.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ class ViewAnnotationWithPointAnnotationActivity : AppCompatActivity() {
175175
val isSelected = button.text.toString().equals("SELECT", true)
176176
val pxDelta = if (isSelected) SELECTED_ADD_COEF_PX else -SELECTED_ADD_COEF_PX
177177
button.text = if (isSelected) "DESELECT" else "SELECT"
178-
viewAnnotationManager.updateViewAnnotation(
179-
viewAnnotation,
180-
viewAnnotationOptions {
181-
selected(isSelected)
182-
}
183-
)
184178
(button.layoutParams as ViewGroup.MarginLayoutParams).apply {
185179
bottomMargin += pxDelta
186180
rightMargin += pxDelta

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ japicmp = "0.4.1"
3535
# Dependencies
3636

3737
# GlNative and Common are used by the convention plugin
38-
mapboxGlNative = "11.9.0"
39-
mapboxCommon = "24.9.0"
38+
mapboxGlNative = "11.10.0-SNAPSHOT-01-03--04-28.git-f26a6d7"
39+
mapboxCommon = "24.10.0-SNAPSHOT-01-03--04-28.git-f26a6d7"
4040

4141
mapboxBase = "0.11.0"
4242
mapboxGestures = "0.8.0"

maps-sdk/src/androidTest/java/com/mapbox/maps/ViewAnnotationTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class ViewAnnotationTest(
349349
}
350350

351351
@Test
352-
fun addTwoViewAnnotationsOneSelectedAllowOverlapTrue() {
352+
fun addTwoViewAnnotationsOneWithPriorityAllowOverlapTrue() {
353353
viewAnnotationTestHelper(
354354
performAction = {
355355
firstView = viewAnnotationManager.addViewAnnotation(
@@ -360,7 +360,7 @@ class ViewAnnotationTest(
360360
anchor(ViewAnnotationAnchor.TOP_LEFT)
361361
}
362362
allowOverlap(true)
363-
selected(true)
363+
priority(32)
364364
}
365365
)
366366
secondView = viewAnnotationManager.addViewAnnotation(
@@ -485,7 +485,7 @@ class ViewAnnotationTest(
485485
}
486486

487487
@Test
488-
fun addTwoViewAnnotationsOneSelectedAllowOverlapFalse() {
488+
fun addTwoViewAnnotationsOneWithPriorityAllowOverlapFalse() {
489489
viewAnnotationTestHelper(
490490
performAction = {
491491
firstView = viewAnnotationManager.addViewAnnotation(
@@ -496,7 +496,7 @@ class ViewAnnotationTest(
496496
anchor(ViewAnnotationAnchor.TOP_LEFT)
497497
}
498498
allowOverlap(false)
499-
selected(true)
499+
priority(22)
500500
}
501501
)
502502
secondView = viewAnnotationManager.addViewAnnotation(
@@ -526,7 +526,7 @@ class ViewAnnotationTest(
526526
}
527527

528528
@Test
529-
fun addTwoViewAnnotationsTwoSelectedAllowOverlapFalse() {
529+
fun addTwoViewAnnotationsTwoWithPriorityAllowOverlapFalse() {
530530
viewAnnotationTestHelper(
531531
performAction = {
532532
firstView = viewAnnotationManager.addViewAnnotation(
@@ -537,7 +537,7 @@ class ViewAnnotationTest(
537537
anchor(ViewAnnotationAnchor.TOP_LEFT)
538538
}
539539
allowOverlap(false)
540-
selected(true)
540+
priority(1)
541541
}
542542
)
543543
secondView = viewAnnotationManager.addViewAnnotation(
@@ -548,7 +548,7 @@ class ViewAnnotationTest(
548548
anchor(ViewAnnotationAnchor.TOP_LEFT)
549549
}
550550
allowOverlap(false)
551-
selected(true)
551+
priority(34)
552552
}
553553
)
554554
},

0 commit comments

Comments
 (0)