From cee0f7bef4cb5e43af766780b20542eaa4191979 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 4 Apr 2023 19:06:08 -0700 Subject: [PATCH] Add draggable marker to move trkpts in history. --- .../java/net/voussoir/trkpt/TrackFragment.kt | 42 +++++++++++++++++++ .../ic_marker_location_fuchsia_24dp.xml | 9 ++++ .../drawable/ic_marker_location_red_24dp.xml | 4 -- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_marker_location_fuchsia_24dp.xml diff --git a/app/src/main/java/net/voussoir/trkpt/TrackFragment.kt b/app/src/main/java/net/voussoir/trkpt/TrackFragment.kt index 428d643..8897f11 100644 --- a/app/src/main/java/net/voussoir/trkpt/TrackFragment.kt +++ b/app/src/main/java/net/voussoir/trkpt/TrackFragment.kt @@ -26,6 +26,7 @@ import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Paint +import android.location.Location import android.net.Uri import android.os.Bundle import android.os.Handler @@ -38,6 +39,7 @@ import android.widget.* import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult import androidx.constraintlayout.widget.Group +import androidx.core.content.ContextCompat import androidx.core.widget.NestedScrollView import androidx.fragment.app.Fragment import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -54,6 +56,7 @@ import org.osmdroid.tileprovider.tilesource.TileSourceFactory import org.osmdroid.util.GeoPoint import org.osmdroid.views.MapView import org.osmdroid.views.overlay.MapEventsOverlay +import org.osmdroid.views.overlay.Marker import org.osmdroid.views.overlay.Polyline import org.osmdroid.views.overlay.TilesOverlay import org.osmdroid.views.overlay.simplefastpoint.SimpleFastPointOverlay @@ -112,6 +115,9 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener private val handler: Handler = Handler(Looper.getMainLooper()) val RERENDER_DELAY: Long = 1000 + var selected_trkpt: Trkpt? = null + lateinit var selected_trkpt_marker: Marker + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -379,6 +385,31 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener statisticsSheetBehavior = BottomSheetBehavior.from(statisticsSheet) statisticsSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + selected_trkpt_marker = Marker(mapView, requireContext()) + selected_trkpt_marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER) + selected_trkpt_marker.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_marker_location_fuchsia_24dp)!! + selected_trkpt_marker.isDraggable = true + selected_trkpt_marker.infoWindow = null + selected_trkpt_marker.setOnMarkerDragListener(object : Marker.OnMarkerDragListener { + override fun onMarkerDrag(marker: Marker?) + { + if (marker == null || selected_trkpt == null) + { + return + } + selected_trkpt?.latitude = marker.position.latitude + selected_trkpt?.longitude = marker.position.longitude + selected_trkpt?.rendered_by_polyline?.setPoints(ArrayList(selected_trkpt?.rendered_by_polyline?.actualPoints)) + } + override fun onMarkerDragStart(marker: Marker?) + { + } + override fun onMarkerDragEnd(marker: Marker?) + { + selected_trkpt?.let { trackbook.database.update_trkpt(it, commit=true) } + } + }) + track_segment_overlays = ArrayDeque(10) render_track() @@ -397,6 +428,11 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener { track_points_overlay!!.selectedPoint = null } + if (selected_trkpt_marker in mapView.overlays) + { + mapView.overlays.remove(selected_trkpt_marker) + mapView.invalidate() + } delete_selected_trkpt_button.visibility = View.GONE use_trkpt_as_start_button.visibility = View.GONE use_trkpt_as_end_button.visibility = View.GONE @@ -491,7 +527,13 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener } val trkpt = (points[point]) as Trkpt Log.i("VOUSSOIR", "Clicked ${trkpt.device_id} ${trkpt.time}") + selected_trkpt = trkpt selected_trkpt_info.text = "${trkpt.time}\n${iso8601_local(trkpt.time)}\n${trkpt.latitude}\n${trkpt.longitude}\n${trkpt.accuracy}" + selected_trkpt_marker.position = trkpt + if (selected_trkpt_marker !in mapView.overlays) + { + mapView.overlays.add(selected_trkpt_marker) + } delete_selected_trkpt_button.visibility = View.VISIBLE use_trkpt_as_start_button.visibility = View.VISIBLE use_trkpt_as_end_button.visibility = View.VISIBLE diff --git a/app/src/main/res/drawable/ic_marker_location_fuchsia_24dp.xml b/app/src/main/res/drawable/ic_marker_location_fuchsia_24dp.xml new file mode 100644 index 0000000..36e8243 --- /dev/null +++ b/app/src/main/res/drawable/ic_marker_location_fuchsia_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_marker_location_red_24dp.xml b/app/src/main/res/drawable/ic_marker_location_red_24dp.xml index 9080ed6..2c0cf2c 100755 --- a/app/src/main/res/drawable/ic_marker_location_red_24dp.xml +++ b/app/src/main/res/drawable/ic_marker_location_red_24dp.xml @@ -3,10 +3,6 @@ android:viewportHeight="96.0" android:viewportWidth="96.0" android:width="24dp"> -