Skip to content

Commit e8a6f1a

Browse files
aleksprogeractions-user
authored andcommitted
[Backport release/v0.19] Add building button to indoor selector (#10401)
- Backports mapbox/mapbox-sdk#10383 cc @mapbox/maps-ios cc @mapbox/core-sdk cc @mapbox/gl-native cc @mapbox/maps-android --------- Co-authored-by: Changelog autocreator bot <actions@github.com> GitOrigin-RevId: 6e562ccfbad9957ef1c0750d53772123e49c13ff
1 parent eba0eac commit e8a6f1a

5 files changed

Lines changed: 79 additions & 13 deletions

File tree

app/src/main/java/com/mapbox/maps/testapp/examples/IndoorExampleActivity.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.mapbox.maps.testapp.examples
33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
55
import com.mapbox.geojson.Point
6-
import com.mapbox.maps.CameraOptions
76
import com.mapbox.maps.MapInitOptions
87
import com.mapbox.maps.MapView
98
import com.mapbox.maps.MapboxExperimental
@@ -73,15 +72,6 @@ class IndoorExampleActivity : AppCompatActivity() {
7372
enabled = true
7473
puckBearingEnabled = true
7574
locationPuck = createDefault2DPuck(withBearing = true)
76-
77-
addOnIndicatorPositionChangedListener { point ->
78-
mapView.mapboxMap.setCamera(
79-
CameraOptions.Builder()
80-
.center(point)
81-
.zoom(18.0)
82-
.build()
83-
)
84-
}
8575
}
8676
}
8777
}

plugin-indoorselector/src/main/java/com/mapbox/maps/plugin/indoorselector/IndoorSelectorPluginImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ internal class IndoorSelectorPluginImpl(
193193
}
194194
}
195195

196+
/**
197+
* Called when the building button is tapped by the user via the UI.
198+
* Clears the active floor selection so the map shows buildings.
199+
*/
200+
fun onBuildingSelected() {
201+
selectedFloorId = null
202+
indoorManager.selectFloor(null)
203+
indoorSelectorView.updateFloors(currentFloors, null)
204+
}
205+
196206
/**
197207
* Update the list of available floors.
198208
* Call this method when indoor data becomes available or changes.

plugin-indoorselector/src/main/java/com/mapbox/maps/plugin/indoorselector/IndoorSelectorViewImpl.kt

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
5656

5757
private val topArrow: ImageView
5858
private val bottomArrow: ImageView
59+
private val buildingButton: ImageView
5960

6061
private var indoorFloors: List<IndoorFloor> = emptyList()
6162
private var selectedFloorId: String? = null
63+
private var isBuildingSelected = false
6264
private lateinit var presenter: IndoorSelectorPluginImpl
6365

6466
init {
@@ -75,11 +77,20 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
7577
cornerRadius = cornerRadiusPx
7678
}
7779

78-
addView(scrollView, LayoutParams(itemHeightPx, LayoutParams.WRAP_CONTENT))
80+
buildingButton = createBuildingButton()
81+
addView(buildingButton)
82+
83+
val scrollParams = LayoutParams(itemHeightPx, LayoutParams.WRAP_CONTENT).apply {
84+
topMargin = itemHeightPx
85+
}
86+
addView(scrollView, scrollParams)
7987

8088
topArrow = createArrowButton(isUp = true)
8189
bottomArrow = createArrowButton(isUp = false)
8290

91+
(topArrow.layoutParams as LayoutParams).topMargin = itemHeightPx
92+
(bottomArrow.layoutParams as LayoutParams).topMargin = itemHeightPx
93+
8394
addView(topArrow)
8495
addView(bottomArrow)
8596

@@ -141,6 +152,10 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
141152
setTextSize(TypedValue.COMPLEX_UNIT_SP, FLOOR_LABEL_TEXT_SIZE_SP)
142153

143154
setOnClickListener {
155+
if (isBuildingSelected) {
156+
isBuildingSelected = false
157+
updateBuildingButtonStyle()
158+
}
144159
if (::presenter.isInitialized) {
145160
presenter.onFloorSelected(level.id)
146161
}
@@ -165,7 +180,8 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
165180
for (i in 0 until containerLayout.childCount) {
166181
val view = containerLayout.getChildAt(i) as TextView
167182
val level = indoorFloors.getOrNull(i) ?: continue
168-
val isActive = level.id == activeId
183+
// When building button is active, no floor appears highlighted
184+
val isActive = !isBuildingSelected && level.id == activeId
169185

170186
view.setBackgroundColor(if (isActive) selectedBg else Color.TRANSPARENT)
171187
view.setTextColor(if (isActive) selectedTxt else normalTxt)
@@ -174,7 +190,8 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
174190

175191
private fun updateContainerHeight() {
176192
val visibleCount = indoorFloors.size.coerceAtMost(MAX_VISIBLE_ITEMS)
177-
val targetHeight = visibleCount * itemHeightPx
193+
// Add 1 for the building button
194+
val targetHeight = (visibleCount + 1) * itemHeightPx
178195

179196
updateLayoutParams {
180197
it.height = targetHeight
@@ -217,6 +234,45 @@ internal class IndoorSelectorViewImpl @JvmOverloads constructor(
217234
}
218235
}
219236

237+
private fun createBuildingButton() = ImageView(context).apply {
238+
scaleType = ImageView.ScaleType.CENTER_INSIDE
239+
setBackgroundColor(ContextCompat.getColor(context, R.color.mapbox_indoor_bg))
240+
setImageResource(R.drawable.mapbox_indoor_selector_building)
241+
contentDescription = context.getString(R.string.mapbox_indoorselector_building)
242+
setColorFilter(ContextCompat.getColor(context, R.color.mapbox_indoor_text), PorterDuff.Mode.SRC_IN)
243+
244+
layoutParams = LayoutParams(itemHeightPx, itemHeightPx).apply {
245+
gravity = Gravity.TOP
246+
}
247+
248+
setOnClickListener { onBuildingButtonTapped() }
249+
}
250+
251+
private fun onBuildingButtonTapped() {
252+
if (isBuildingSelected) return
253+
isBuildingSelected = true
254+
updateBuildingButtonStyle()
255+
if (::presenter.isInitialized) {
256+
presenter.onBuildingSelected()
257+
}
258+
}
259+
260+
private fun updateBuildingButtonStyle() {
261+
val bgColor = if (isBuildingSelected) {
262+
ContextCompat.getColor(context, R.color.mapbox_indoor_selected_bg)
263+
} else {
264+
ContextCompat.getColor(context, R.color.mapbox_indoor_bg)
265+
}
266+
val iconColor = if (isBuildingSelected) {
267+
ContextCompat.getColor(context, R.color.mapbox_indoor_selected_text)
268+
} else {
269+
ContextCompat.getColor(context, R.color.mapbox_indoor_text)
270+
}
271+
buildingButton.setBackgroundColor(bgColor)
272+
buildingButton.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN)
273+
updateSelectionHighlight(selectedFloorId)
274+
}
275+
220276
private inline fun updateLayoutParams(block: (LayoutParams) -> Unit) {
221277
(layoutParams as? LayoutParams)?.let {
222278
block(it)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M12,7L12,3L2,3v18h20L22,7L12,7zM6,19L4,19v-2h2v2zM6,15L4,15v-2h2v2zM6,11L4,11L4,9h2v2zM6,7L4,7L4,5h2v2zM10,19L8,19v-2h2v2zM10,15L8,15v-2h2v2zM10,11L8,11L8,9h2v2zM10,7L8,7L8,5h2v2zM20,19h-8v-2h2v-2h-2v-2h2v-2h-2L12,9h8v10zM18,11h-2v2h2v-2zM18,15h-2v2h2v-2z"/>
9+
</vector>

plugin-indoorselector/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<!-- Indoor selector accessibility strings -->
44
<string name="mapbox_indoorselector_scroll_up">Scroll up</string>
55
<string name="mapbox_indoorselector_scroll_down">Scroll down</string>
6+
<string name="mapbox_indoorselector_building">Show building</string>
67
</resources>

0 commit comments

Comments
 (0)