diff --git a/app/src/main/java/androidx/ui/fakeandroidview/ComposedView.kt b/app/src/main/java/androidx/ui/fakeandroidview/ComposedView.kt index 211a957f5..0c0e7e4aa 100644 --- a/app/src/main/java/androidx/ui/fakeandroidview/ComposedView.kt +++ b/app/src/main/java/androidx/ui/fakeandroidview/ComposedView.kt @@ -18,6 +18,7 @@ package androidx.ui.fakeandroidview import android.content.Context import android.view.LayoutInflater +import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT @@ -62,6 +63,10 @@ private class AndroidViewHolder(context: Context) : ViewGroup(context) { } } + init { + isClickable = true + } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { view?.measure(widthMeasureSpec, heightMeasureSpec) setMeasuredDimension(view?.measuredWidth ?: 0, view?.measuredHeight ?: 0) @@ -74,4 +79,26 @@ private class AndroidViewHolder(context: Context) : ViewGroup(context) { override fun getLayoutParams(): LayoutParams? { return view?.layoutParams ?: LayoutParams(MATCH_PARENT, MATCH_PARENT) } + + /** + * Implement this method to handle touch screen motion events. + * + * + * If this method is used to detect click actions, it is recommended that + * the actions be performed by implementing and calling + * [.performClick]. This will ensure consistent system behavior, + * including: + * + * * obeying click sound preferences + * * dispatching OnClickListener calls + * * handling [ACTION_CLICK][AccessibilityNodeInfo.ACTION_CLICK] when + * accessibility features are enabled + * + * + * @param event The motion event. + * @return True if the event was handled, false otherwise. + */ + override fun onTouchEvent(event: MotionEvent?): Boolean { + return super.onTouchEvent(event) + } } diff --git a/app/src/main/java/com/geeksville/mesh/ui/Map.kt b/app/src/main/java/com/geeksville/mesh/ui/Map.kt index 6bef3b9c8..19a721a41 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/Map.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/Map.kt @@ -2,6 +2,7 @@ package com.geeksville.mesh.ui import android.app.Activity import android.app.Application +import android.graphics.Color import android.os.Bundle import androidx.compose.Composable import androidx.compose.onCommit @@ -21,8 +22,12 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory import com.mapbox.mapboxsdk.geometry.LatLng import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.Style +import com.mapbox.mapboxsdk.style.expressions.Expression import com.mapbox.mapboxsdk.style.layers.Property +import com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_TOP +import com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_AUTO import com.mapbox.mapboxsdk.style.layers.PropertyFactory +import com.mapbox.mapboxsdk.style.layers.PropertyFactory.* import com.mapbox.mapboxsdk.style.layers.SymbolLayer import com.mapbox.mapboxsdk.style.sources.GeoJsonSource @@ -88,18 +93,21 @@ fun MapContent() { // Find all nodes with valid locations val locations = NodeDB.nodes.values.mapNotNull { node -> val p = node.position - if (p != null && (p.latitude != 0.0 || p.longitude != 0.0)) - Feature.fromGeometry( + if (p != null && (p.latitude != 0.0 || p.longitude != 0.0)) { + val f = Feature.fromGeometry( Point.fromLngLat( - p.latitude, - p.longitude + p.longitude, + p.latitude ) ) - else + node.user?.let { f.addStringProperty("name", it.longName) } + f + } else null } val nodeSourceId = "node-positions" val nodeLayerId = "node-layer" + val labelLayerId = "label-layer" val markerImageId = "my-marker-image" val nodePositions = GeoJsonSource(nodeSourceId, FeatureCollection.fromFeatures(locations)) @@ -107,13 +115,19 @@ fun MapContent() { // val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24) val markerIcon = context.getDrawable(R.drawable.ic_twotone_person_pin_24)!! - val nodeLayer = SymbolLayer(nodeLayerId, nodeSourceId) - nodeLayer.setProperties( + val nodeLayer = SymbolLayer(nodeLayerId, nodeSourceId).withProperties( PropertyFactory.iconImage(markerImageId), PropertyFactory.iconAnchor(Property.ICON_ANCHOR_BOTTOM) ) - //Column { + val labelLayer = SymbolLayer(labelLayerId, nodeSourceId).withProperties( + textField(Expression.get("name")), + textSize(12f), + textColor(Color.RED), + textVariableAnchor(arrayOf(TEXT_ANCHOR_TOP)), + textJustify(TEXT_JUSTIFY_AUTO) + ) + AndroidView(R.layout.map_view) { view -> view as MapView view.onCreate(UIState.savedInstanceState) @@ -125,21 +139,24 @@ fun MapContent() { view.getMapAsync { map -> map.setStyle(Style.OUTDOORS) { style -> - style.addImage(markerImageId, markerIcon) style.addSource(nodePositions) + style.addImage(markerImageId, markerIcon) style.addLayer(nodeLayer) + style.addLayer(labelLayer) } + //map.uiSettings.isScrollGesturesEnabled = true + //map.uiSettings.isZoomGesturesEnabled = true + // Center on the user's position (if we have it) NodeDB.ourNodeInfo?.position?.let { val cameraPos = CameraPosition.Builder().target( LatLng(it.latitude, it.longitude) - ).zoom(8.0).build() + ).zoom(9.0).build() map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), 1000) } } } - //} } diff --git a/app/src/main/res/layout/map_view.xml b/app/src/main/res/layout/map_view.xml index 554c64b3a..a77c3ecf9 100644 --- a/app/src/main/res/layout/map_view.xml +++ b/app/src/main/res/layout/map_view.xml @@ -5,5 +5,6 @@ android:id="@+id/mapView" android:layout_width="match_parent" android:layout_height="match_parent" + android:clickable="true" mapbox:mapbox_uiZoomGestures="true" mapbox:mapbox_uiScrollGestures="true">