Add straighten button, straightens trkpts between two points.
This commit is contained in:
parent
a8e2bb26fd
commit
47e0c36c3a
3 changed files with 86 additions and 0 deletions
|
@ -62,6 +62,7 @@ import org.osmdroid.views.overlay.TilesOverlay
|
||||||
import org.osmdroid.views.overlay.simplefastpoint.SimpleFastPointOverlay
|
import org.osmdroid.views.overlay.simplefastpoint.SimpleFastPointOverlay
|
||||||
import org.osmdroid.views.overlay.simplefastpoint.SimpleFastPointOverlayOptions
|
import org.osmdroid.views.overlay.simplefastpoint.SimpleFastPointOverlayOptions
|
||||||
import org.osmdroid.views.overlay.simplefastpoint.SimplePointTheme
|
import org.osmdroid.views.overlay.simplefastpoint.SimplePointTheme
|
||||||
|
import java.lang.Math.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
|
@ -87,7 +88,9 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
lateinit var isolate_trkseg_button: ImageButton
|
lateinit var isolate_trkseg_button: ImageButton
|
||||||
lateinit var when_was_i_here_button: ImageButton
|
lateinit var when_was_i_here_button: ImageButton
|
||||||
lateinit var interpolate_points_button: ImageButton
|
lateinit var interpolate_points_button: ImageButton
|
||||||
|
lateinit var straighten_points_button: ImageButton
|
||||||
var ready_to_interpolate: Boolean = false
|
var ready_to_interpolate: Boolean = false
|
||||||
|
var ready_to_straighten: Boolean = false
|
||||||
var track_query_start_time_previous: Int = 0
|
var track_query_start_time_previous: Int = 0
|
||||||
var track_query_end_time_previous: Int = 0
|
var track_query_end_time_previous: Int = 0
|
||||||
private lateinit var mapView: MapView
|
private lateinit var mapView: MapView
|
||||||
|
@ -347,6 +350,11 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
interpolate_points_button = rootView.findViewById(R.id.interpolate_points_button)
|
interpolate_points_button = rootView.findViewById(R.id.interpolate_points_button)
|
||||||
interpolate_points_button.setOnClickListener {
|
interpolate_points_button.setOnClickListener {
|
||||||
Log.i("VOUSSOIR", "interpolate_points_button.")
|
Log.i("VOUSSOIR", "interpolate_points_button.")
|
||||||
|
if (ready_to_straighten)
|
||||||
|
{
|
||||||
|
ready_to_straighten = false
|
||||||
|
straighten_points_button.setColorFilter(null)
|
||||||
|
}
|
||||||
if (ready_to_interpolate)
|
if (ready_to_interpolate)
|
||||||
{
|
{
|
||||||
interpolate_points_button.setColorFilter(null)
|
interpolate_points_button.setColorFilter(null)
|
||||||
|
@ -358,6 +366,25 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
ready_to_interpolate = !ready_to_interpolate
|
ready_to_interpolate = !ready_to_interpolate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
straighten_points_button = rootView.findViewById(R.id.straighten_points_button)
|
||||||
|
straighten_points_button.setOnClickListener {
|
||||||
|
Log.i("VOUSSOIR", "straighten_points_button.")
|
||||||
|
if (ready_to_interpolate)
|
||||||
|
{
|
||||||
|
ready_to_interpolate = false
|
||||||
|
interpolate_points_button.setColorFilter(null)
|
||||||
|
}
|
||||||
|
if (ready_to_straighten)
|
||||||
|
{
|
||||||
|
straighten_points_button.setColorFilter(null)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
straighten_points_button.setColorFilter(resources.getColor(R.color.fuchsia))
|
||||||
|
}
|
||||||
|
ready_to_straighten = !ready_to_straighten
|
||||||
|
}
|
||||||
|
|
||||||
save_track_button.setOnClickListener {
|
save_track_button.setOnClickListener {
|
||||||
val dialog = Dialog(activity as Context)
|
val dialog = Dialog(activity as Context)
|
||||||
dialog.setContentView(R.layout.dialog_rename_track)
|
dialog.setContentView(R.layout.dialog_rename_track)
|
||||||
|
@ -450,9 +477,12 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
mapView.invalidate()
|
mapView.invalidate()
|
||||||
}
|
}
|
||||||
ready_to_interpolate = false
|
ready_to_interpolate = false
|
||||||
|
ready_to_straighten = false
|
||||||
interpolate_points_button.setColorFilter(null)
|
interpolate_points_button.setColorFilter(null)
|
||||||
|
straighten_points_button.setColorFilter(null)
|
||||||
delete_selected_trkpt_button.visibility = View.GONE
|
delete_selected_trkpt_button.visibility = View.GONE
|
||||||
interpolate_points_button.visibility = View.GONE
|
interpolate_points_button.visibility = View.GONE
|
||||||
|
straighten_points_button.visibility = View.GONE
|
||||||
use_trkpt_as_start_button.visibility = View.GONE
|
use_trkpt_as_start_button.visibility = View.GONE
|
||||||
use_trkpt_as_end_button.visibility = View.GONE
|
use_trkpt_as_end_button.visibility = View.GONE
|
||||||
isolate_trkseg_button.visibility = View.GONE
|
isolate_trkseg_button.visibility = View.GONE
|
||||||
|
@ -560,6 +590,13 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
handler.post(requery_and_render)
|
handler.post(requery_and_render)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
else if (ready_to_straighten && selected_trkpt != null)
|
||||||
|
{
|
||||||
|
straighten_points(selected_trkpt!!, trkpt)
|
||||||
|
deselect_trkpt()
|
||||||
|
handler.post(requery_and_render)
|
||||||
|
return
|
||||||
|
}
|
||||||
selected_trkpt = trkpt
|
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_info.text = "${trkpt.time}\n${iso8601_local(trkpt.time)}\n${trkpt.latitude}\n${trkpt.longitude}\n${trkpt.accuracy}"
|
||||||
selected_trkpt_marker.position = trkpt
|
selected_trkpt_marker.position = trkpt
|
||||||
|
@ -568,6 +605,7 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
mapView.overlays.add(selected_trkpt_marker)
|
mapView.overlays.add(selected_trkpt_marker)
|
||||||
}
|
}
|
||||||
interpolate_points_button.visibility = View.VISIBLE
|
interpolate_points_button.visibility = View.VISIBLE
|
||||||
|
straighten_points_button.visibility = View.VISIBLE
|
||||||
delete_selected_trkpt_button.visibility = View.VISIBLE
|
delete_selected_trkpt_button.visibility = View.VISIBLE
|
||||||
use_trkpt_as_start_button.visibility = View.VISIBLE
|
use_trkpt_as_start_button.visibility = View.VISIBLE
|
||||||
use_trkpt_as_end_button.visibility = View.VISIBLE
|
use_trkpt_as_end_button.visibility = View.VISIBLE
|
||||||
|
@ -593,6 +631,28 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
return pl
|
return pl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun straighten_points(a: Trkpt, b: Trkpt)
|
||||||
|
{
|
||||||
|
val subtrack = Track(track.database, track.device_id)
|
||||||
|
subtrack.load_trkpts(trackbook.database.select_trkpt_start_end(
|
||||||
|
track.device_id,
|
||||||
|
start_time=min(a.time, b.time),
|
||||||
|
end_time=max(a.time, b.time),
|
||||||
|
))
|
||||||
|
val lat_step = (b.latitude - a.latitude) / (b.time - a.time)
|
||||||
|
val lon_step = (b.longitude - a.longitude) / (b.time - a.time)
|
||||||
|
val ele_step = (b.altitude - a.altitude) / (b.time - a.time)
|
||||||
|
for (trkpt in subtrack.trkpts)
|
||||||
|
{
|
||||||
|
val index = trkpt.time - a.time
|
||||||
|
trkpt.latitude = a.latitude + (index * lat_step)
|
||||||
|
trkpt.longitude = a.longitude + (index * lon_step)
|
||||||
|
trkpt.altitude = a.altitude + (index * ele_step)
|
||||||
|
trackbook.database.update_trkpt(trkpt, commit=false)
|
||||||
|
}
|
||||||
|
trackbook.database.commit()
|
||||||
|
}
|
||||||
|
|
||||||
fun set_datetime(datepicker: DatePicker, timepicker: TimePicker, setdate: Date, _ending: Boolean)
|
fun set_datetime(datepicker: DatePicker, timepicker: TimePicker, setdate: Date, _ending: Boolean)
|
||||||
{
|
{
|
||||||
datetime_change_listener_enabled = false
|
datetime_change_listener_enabled = false
|
||||||
|
|
13
app/src/main/res/drawable/ic_straighten_24dp.xml
Normal file
13
app/src/main/res/drawable/ic_straighten_24dp.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:name="vector"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:name="path"
|
||||||
|
android:pathData="M 3.014 9.656 C 1.725 9.656 0.67 10.711 0.67 12 C 0.67 13.289 1.725 14.344 3.014 14.344 C 3.944 14.344 4.747 13.791 5.125 13 L 6.895 13 C 7.272 13.791 8.073 14.344 9.004 14.344 C 9.934 14.344 10.737 13.791 11.115 13 L 12.885 13 C 13.263 13.791 14.066 14.344 14.996 14.344 C 15.927 14.344 16.728 13.791 17.105 13 L 18.875 13 C 19.253 13.791 20.056 14.344 20.986 14.344 C 22.275 14.344 23.33 13.289 23.33 12 C 23.33 10.711 22.275 9.656 20.986 9.656 C 20.056 9.656 19.253 10.209 18.875 11 L 17.105 11 C 16.728 10.209 15.927 9.656 14.996 9.656 C 14.066 9.656 13.263 10.209 12.885 11 L 11.115 11 C 10.737 10.209 9.934 9.656 9.004 9.656 C 8.073 9.656 7.272 10.209 6.895 11 L 5.125 11 C 4.747 10.209 3.944 9.656 3.014 9.656 Z"
|
||||||
|
android:fillColor="@color/icon_default"
|
||||||
|
/>
|
||||||
|
</vector>
|
|
@ -133,6 +133,19 @@
|
||||||
app:layout_constraintEnd_toStartOf="@+id/isolate_trkseg_button"
|
app:layout_constraintEnd_toStartOf="@+id/isolate_trkseg_button"
|
||||||
app:srcCompat="@drawable/ic_bug_report_24dp" />
|
app:srcCompat="@drawable/ic_bug_report_24dp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/straighten_points_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:contentDescription="Straighten points"
|
||||||
|
android:tooltipText="Straighten points"
|
||||||
|
android:src="@drawable/ic_straighten_24dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:backgroundTint="@color/default_transparent"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/interpolate_points_button"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/interpolate_points_button"
|
||||||
|
app:srcCompat="@drawable/ic_straighten_24dp" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/delete_selected_trkpt_button"
|
android:id="@+id/delete_selected_trkpt_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue