GPX output adapted for new "starred" feature

This commit is contained in:
y20k 2020-08-03 16:42:47 +02:00
parent 7d47068bb0
commit 2531a36f20
No known key found for this signature in database
GPG key ID: 824D4259F41FAFF6
7 changed files with 71 additions and 27 deletions

View file

@ -44,7 +44,7 @@ import org.y20k.trackbook.ui.MapFragmentLayoutHolder
/*
* MapFragment class
*/
class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.MarkerListener {
class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelper.MarkerListener {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(MapFragment::class.java)
@ -75,7 +75,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.Mark
/* Overrides onStop from Fragment */
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// initialize layout
layout = MapFragmentLayoutHolder(activity as Context, this as MapOverlay.MarkerListener, inflater, container, currentBestLocation, trackingState)
layout = MapFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, container, currentBestLocation, trackingState)
// set up buttons
layout.currentLocationButton.setOnClickListener {

View file

@ -41,12 +41,12 @@ import org.y20k.trackbook.core.Track
import org.y20k.trackbook.dialogs.RenameTrackDialog
import org.y20k.trackbook.helpers.FileHelper
import org.y20k.trackbook.helpers.LogHelper
import org.y20k.trackbook.helpers.MapOverlay
import org.y20k.trackbook.helpers.MapOverlayHelper
import org.y20k.trackbook.helpers.TrackHelper
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDialog.YesNoDialogListener, MapOverlay.MarkerListener {
class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDialog.YesNoDialogListener, MapOverlayHelper.MarkerListener {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(TrackFragment::class.java)
@ -73,7 +73,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
/* Overrides onCreateView from Fragment */
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// initialize layout
layout = TrackFragmentLayoutHolder(activity as Context, this as MapOverlay.MarkerListener, inflater, container, track)
layout = TrackFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, container, track)
// set up share button
layout.shareButton.setOnClickListener {

View file

@ -1,7 +1,7 @@
/*
* MapHelper.kt
* Implements the MapHelper object
* A MapHelper offers helper methods for manipulating osmdroid maps
* Implements the MapOverlayHelper class
* A MapOverlayHelper offers helper methods for creating osmdroid map overlays
*
* This file is part of
* TRACKBOOK - Movement Recorder for Android
@ -30,15 +30,17 @@ import org.osmdroid.views.overlay.OverlayItem
import org.y20k.trackbook.Keys
import org.y20k.trackbook.R
import org.y20k.trackbook.core.Track
import org.y20k.trackbook.core.WayPoint
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
/*
* MapHelper class
* MapOverlayHelper class
*/
class MapOverlay (private var markerListener: MarkerListener) {
class MapOverlayHelper (private var markerListener: MarkerListener) {
/* Interface used to communicate back to activity/fragment */
interface MarkerListener {
@ -47,14 +49,14 @@ class MapOverlay (private var markerListener: MarkerListener) {
}
/* Define log tag */
private val TAG = MapOverlay::class.java.simpleName
private val TAG = MapOverlayHelper::class.java.simpleName
/* Creates icon overlay for current position (used in MapFragment) */
fun createMyLocationOverlay(context: Context, location: Location, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
val overlayItems = ArrayList<OverlayItem>()
val locationIsOld = LocationHelper.isOldLocation(location)
val overlayItems: ArrayList<OverlayItem> = ArrayList<OverlayItem>()
val locationIsOld:Boolean = LocationHelper.isOldLocation(location)
// create marker
val newMarker: Drawable
@ -76,7 +78,7 @@ class MapOverlay (private var markerListener: MarkerListener) {
}
// add marker to list of overlay items
val overlayItem = createOverlayItem(context, location.latitude, location.longitude, location.accuracy, location.provider, location.time)
val overlayItem: OverlayItem = createOverlayItem(context, location.latitude, location.longitude, location.accuracy, location.provider, location.time)
overlayItem.setMarker(newMarker)
overlayItems.add(overlayItem)
@ -88,8 +90,8 @@ class MapOverlay (private var markerListener: MarkerListener) {
/* Creates icon overlay for track */
fun createTrackOverlay(context: Context, track: Track, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
val overlayItems = ArrayList<OverlayItem>()
val wayPoints = track.wayPoints
val overlayItems: ArrayList<OverlayItem> = ArrayList<OverlayItem>()
val wayPoints: MutableList<WayPoint> = track.wayPoints
wayPoints.forEach { wayPoint ->
// create marker
@ -120,7 +122,7 @@ class MapOverlay (private var markerListener: MarkerListener) {
}
// create overlay item and add to list of overlay items
val overlayItem = createOverlayItem(context, wayPoint.latitude, wayPoint.longitude, wayPoint.accuracy, wayPoint.provider, wayPoint.time)
val overlayItem: OverlayItem = createOverlayItem(context, wayPoint.latitude, wayPoint.longitude, wayPoint.accuracy, wayPoint.provider, wayPoint.time)
overlayItem.setMarker(newMarker)
overlayItems.add(overlayItem)
}

View file

@ -161,6 +161,12 @@ object TrackHelper {
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
// add name
gpxString += createGpxName(track)
// add POIs
gpxString += createGpxPois(track)
// add track
gpxString += createGpxTrk(track)
@ -171,6 +177,44 @@ object TrackHelper {
}
/* Creates name for GPX file */
private fun createGpxName(track: Track): String {
val gpxName = StringBuilder("")
gpxName.append("\t<name>")
gpxName.append("Trackbook Recording: ${track.name}")
gpxName.append("</name>\n")
return gpxName.toString()
}
/* Creates GPX formatted points of interest */
private fun createGpxPois(track: Track): String {
val gpxPois = StringBuilder("")
val poiList: List<WayPoint> = track.wayPoints.filter { it.starred }
poiList.forEach { poi ->
gpxPois.append("\t<wpt lat=\"")
gpxPois.append(poi.latitude)
gpxPois.append("\" lon=\"")
gpxPois.append(poi.longitude)
gpxPois.append("\">\n")
// add name to waypoint
gpxPois.append("\t\t<name>")
gpxPois.append("Point of interest")
gpxPois.append("</name>\n")
// add altitude
gpxPois.append("\t\t<ele>")
gpxPois.append(poi.altitude)
gpxPois.append("</ele>\n")
// add closing tag
gpxPois.append("\t</wpt>\n")
}
return gpxPois.toString()
}
/* Creates GPX formatted track */
private fun createGpxTrk(track: Track): String {
val gpxTrack = StringBuilder("")
@ -182,7 +226,7 @@ object TrackHelper {
// add name to track
gpxTrack.append("\t\t<name>")
gpxTrack.append("Trackbook Recording: ${track.name}")
gpxTrack.append("Track")
gpxTrack.append("</name>\n")
// add opening track segment tag

View file

@ -44,14 +44,14 @@ import org.y20k.trackbook.R
import org.y20k.trackbook.core.Track
import org.y20k.trackbook.helpers.AppThemeHelper
import org.y20k.trackbook.helpers.LogHelper
import org.y20k.trackbook.helpers.MapOverlay
import org.y20k.trackbook.helpers.MapOverlayHelper
import org.y20k.trackbook.helpers.PreferencesHelper
/*
* MapFragmentLayoutHolder class
*/
data class MapFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlay.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, private val startLocation: Location, private val trackingState: Int) {
data class MapFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, private val startLocation: Location, private val trackingState: Int) {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(MapFragmentLayoutHolder::class.java)
@ -109,7 +109,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
mapView.overlays.add(compassOverlay)
// add my location overlay
currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, startLocation, trackingState)
currentPositionOverlay = MapOverlayHelper(markerListener).createMyLocationOverlay(context, startLocation, trackingState)
mapView.overlays.add(currentPositionOverlay)
centerMap(startLocation)
@ -157,7 +157,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
/* Mark current position on map */
fun markCurrentPosition(location: Location, trackingState: Int = Keys.STATE_TRACKING_NOT) {
mapView.overlays.remove(currentPositionOverlay)
currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, location, trackingState)
currentPositionOverlay = MapOverlayHelper(markerListener).createMyLocationOverlay(context, location, trackingState)
mapView.overlays.add(currentPositionOverlay)
}
@ -168,7 +168,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
mapView.overlays.remove(currentTrackOverlay)
}
if (track.wayPoints.isNotEmpty()) {
currentTrackOverlay = MapOverlay(markerListener).createTrackOverlay(context, track, trackingState)
currentTrackOverlay = MapOverlayHelper(markerListener).createTrackOverlay(context, track, trackingState)
mapView.overlays.add(currentTrackOverlay)
}
}

View file

@ -50,7 +50,7 @@ import kotlin.math.roundToInt
/*
* TrackFragmentLayoutHolder class
*/
data class TrackFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlay.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, var track: Track) {
data class TrackFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, var track: Track) {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(TrackFragmentLayoutHolder::class.java)
@ -140,7 +140,7 @@ data class TrackFragmentLayoutHolder(private var context: Context, private var m
mapView.overlays.add(compassOverlay)
// create map overlay
trackOverlay = MapOverlay(markerListener).createTrackOverlay(context, track, Keys.STATE_TRACKING_NOT)
trackOverlay = MapOverlayHelper(markerListener).createTrackOverlay(context, track, Keys.STATE_TRACKING_NOT)
if (track.wayPoints.isNotEmpty()) {
mapView.overlays.add(trackOverlay)
}
@ -168,7 +168,7 @@ data class TrackFragmentLayoutHolder(private var context: Context, private var m
mapView.overlays.remove(trackOverlay)
}
if (track.wayPoints.isNotEmpty()) {
trackOverlay = MapOverlay(markerListener).createTrackOverlay(context, track, Keys.STATE_TRACKING_NOT)
trackOverlay = MapOverlayHelper(markerListener).createTrackOverlay(context, track, Keys.STATE_TRACKING_NOT)
mapView.overlays.add(trackOverlay)
}
}

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>