GPX output adapted for new "starred" feature
This commit is contained in:
parent
7d47068bb0
commit
2531a36f20
7 changed files with 71 additions and 27 deletions
|
@ -44,7 +44,7 @@ import org.y20k.trackbook.ui.MapFragmentLayoutHolder
|
||||||
/*
|
/*
|
||||||
* MapFragment class
|
* MapFragment class
|
||||||
*/
|
*/
|
||||||
class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.MarkerListener {
|
class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelper.MarkerListener {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(MapFragment::class.java)
|
private val TAG: String = LogHelper.makeLogTag(MapFragment::class.java)
|
||||||
|
@ -75,7 +75,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.Mark
|
||||||
/* Overrides onStop from Fragment */
|
/* Overrides onStop from Fragment */
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
// initialize layout
|
// 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
|
// set up buttons
|
||||||
layout.currentLocationButton.setOnClickListener {
|
layout.currentLocationButton.setOnClickListener {
|
||||||
|
|
|
@ -41,12 +41,12 @@ import org.y20k.trackbook.core.Track
|
||||||
import org.y20k.trackbook.dialogs.RenameTrackDialog
|
import org.y20k.trackbook.dialogs.RenameTrackDialog
|
||||||
import org.y20k.trackbook.helpers.FileHelper
|
import org.y20k.trackbook.helpers.FileHelper
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
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.helpers.TrackHelper
|
||||||
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
|
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 */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackFragment::class.java)
|
private val TAG: String = LogHelper.makeLogTag(TrackFragment::class.java)
|
||||||
|
@ -73,7 +73,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
|
||||||
/* Overrides onCreateView from Fragment */
|
/* Overrides onCreateView from Fragment */
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
// initialize layout
|
// 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
|
// set up share button
|
||||||
layout.shareButton.setOnClickListener {
|
layout.shareButton.setOnClickListener {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* MapHelper.kt
|
* MapHelper.kt
|
||||||
* Implements the MapHelper object
|
* Implements the MapOverlayHelper class
|
||||||
* A MapHelper offers helper methods for manipulating osmdroid maps
|
* A MapOverlayHelper offers helper methods for creating osmdroid map overlays
|
||||||
*
|
*
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
|
@ -30,15 +30,17 @@ import org.osmdroid.views.overlay.OverlayItem
|
||||||
import org.y20k.trackbook.Keys
|
import org.y20k.trackbook.Keys
|
||||||
import org.y20k.trackbook.R
|
import org.y20k.trackbook.R
|
||||||
import org.y20k.trackbook.core.Track
|
import org.y20k.trackbook.core.Track
|
||||||
|
import org.y20k.trackbook.core.WayPoint
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
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 used to communicate back to activity/fragment */
|
||||||
interface MarkerListener {
|
interface MarkerListener {
|
||||||
|
@ -47,14 +49,14 @@ class MapOverlay (private var markerListener: MarkerListener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Define log tag */
|
/* 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) */
|
/* Creates icon overlay for current position (used in MapFragment) */
|
||||||
fun createMyLocationOverlay(context: Context, location: Location, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
|
fun createMyLocationOverlay(context: Context, location: Location, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
|
||||||
|
|
||||||
val overlayItems = ArrayList<OverlayItem>()
|
val overlayItems: ArrayList<OverlayItem> = ArrayList<OverlayItem>()
|
||||||
val locationIsOld = LocationHelper.isOldLocation(location)
|
val locationIsOld:Boolean = LocationHelper.isOldLocation(location)
|
||||||
|
|
||||||
// create marker
|
// create marker
|
||||||
val newMarker: Drawable
|
val newMarker: Drawable
|
||||||
|
@ -76,7 +78,7 @@ class MapOverlay (private var markerListener: MarkerListener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add marker to list of overlay items
|
// 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)
|
overlayItem.setMarker(newMarker)
|
||||||
overlayItems.add(overlayItem)
|
overlayItems.add(overlayItem)
|
||||||
|
|
||||||
|
@ -88,8 +90,8 @@ class MapOverlay (private var markerListener: MarkerListener) {
|
||||||
/* Creates icon overlay for track */
|
/* Creates icon overlay for track */
|
||||||
fun createTrackOverlay(context: Context, track: Track, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
|
fun createTrackOverlay(context: Context, track: Track, trackingState: Int): ItemizedIconOverlay<OverlayItem> {
|
||||||
|
|
||||||
val overlayItems = ArrayList<OverlayItem>()
|
val overlayItems: ArrayList<OverlayItem> = ArrayList<OverlayItem>()
|
||||||
val wayPoints = track.wayPoints
|
val wayPoints: MutableList<WayPoint> = track.wayPoints
|
||||||
|
|
||||||
wayPoints.forEach { wayPoint ->
|
wayPoints.forEach { wayPoint ->
|
||||||
// create marker
|
// create marker
|
||||||
|
@ -120,7 +122,7 @@ class MapOverlay (private var markerListener: MarkerListener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create overlay item and add to list of overlay items
|
// 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)
|
overlayItem.setMarker(newMarker)
|
||||||
overlayItems.add(overlayItem)
|
overlayItems.add(overlayItem)
|
||||||
}
|
}
|
|
@ -161,6 +161,12 @@ object TrackHelper {
|
||||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
" 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"
|
" 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
|
// add track
|
||||||
gpxString += createGpxTrk(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 */
|
/* Creates GPX formatted track */
|
||||||
private fun createGpxTrk(track: Track): String {
|
private fun createGpxTrk(track: Track): String {
|
||||||
val gpxTrack = StringBuilder("")
|
val gpxTrack = StringBuilder("")
|
||||||
|
@ -182,7 +226,7 @@ object TrackHelper {
|
||||||
|
|
||||||
// add name to track
|
// add name to track
|
||||||
gpxTrack.append("\t\t<name>")
|
gpxTrack.append("\t\t<name>")
|
||||||
gpxTrack.append("Trackbook Recording: ${track.name}")
|
gpxTrack.append("Track")
|
||||||
gpxTrack.append("</name>\n")
|
gpxTrack.append("</name>\n")
|
||||||
|
|
||||||
// add opening track segment tag
|
// add opening track segment tag
|
||||||
|
|
|
@ -44,14 +44,14 @@ import org.y20k.trackbook.R
|
||||||
import org.y20k.trackbook.core.Track
|
import org.y20k.trackbook.core.Track
|
||||||
import org.y20k.trackbook.helpers.AppThemeHelper
|
import org.y20k.trackbook.helpers.AppThemeHelper
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
import org.y20k.trackbook.helpers.LogHelper
|
||||||
import org.y20k.trackbook.helpers.MapOverlay
|
import org.y20k.trackbook.helpers.MapOverlayHelper
|
||||||
import org.y20k.trackbook.helpers.PreferencesHelper
|
import org.y20k.trackbook.helpers.PreferencesHelper
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MapFragmentLayoutHolder class
|
* 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 */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(MapFragmentLayoutHolder::class.java)
|
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)
|
mapView.overlays.add(compassOverlay)
|
||||||
|
|
||||||
// add my location overlay
|
// add my location overlay
|
||||||
currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, startLocation, trackingState)
|
currentPositionOverlay = MapOverlayHelper(markerListener).createMyLocationOverlay(context, startLocation, trackingState)
|
||||||
mapView.overlays.add(currentPositionOverlay)
|
mapView.overlays.add(currentPositionOverlay)
|
||||||
centerMap(startLocation)
|
centerMap(startLocation)
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
|
||||||
/* Mark current position on map */
|
/* Mark current position on map */
|
||||||
fun markCurrentPosition(location: Location, trackingState: Int = Keys.STATE_TRACKING_NOT) {
|
fun markCurrentPosition(location: Location, trackingState: Int = Keys.STATE_TRACKING_NOT) {
|
||||||
mapView.overlays.remove(currentPositionOverlay)
|
mapView.overlays.remove(currentPositionOverlay)
|
||||||
currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, location, trackingState)
|
currentPositionOverlay = MapOverlayHelper(markerListener).createMyLocationOverlay(context, location, trackingState)
|
||||||
mapView.overlays.add(currentPositionOverlay)
|
mapView.overlays.add(currentPositionOverlay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
|
||||||
mapView.overlays.remove(currentTrackOverlay)
|
mapView.overlays.remove(currentTrackOverlay)
|
||||||
}
|
}
|
||||||
if (track.wayPoints.isNotEmpty()) {
|
if (track.wayPoints.isNotEmpty()) {
|
||||||
currentTrackOverlay = MapOverlay(markerListener).createTrackOverlay(context, track, trackingState)
|
currentTrackOverlay = MapOverlayHelper(markerListener).createTrackOverlay(context, track, trackingState)
|
||||||
mapView.overlays.add(currentTrackOverlay)
|
mapView.overlays.add(currentTrackOverlay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ import kotlin.math.roundToInt
|
||||||
/*
|
/*
|
||||||
* TrackFragmentLayoutHolder class
|
* 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 */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackFragmentLayoutHolder::class.java)
|
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)
|
mapView.overlays.add(compassOverlay)
|
||||||
|
|
||||||
// create map overlay
|
// 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()) {
|
if (track.wayPoints.isNotEmpty()) {
|
||||||
mapView.overlays.add(trackOverlay)
|
mapView.overlays.add(trackOverlay)
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ data class TrackFragmentLayoutHolder(private var context: Context, private var m
|
||||||
mapView.overlays.remove(trackOverlay)
|
mapView.overlays.remove(trackOverlay)
|
||||||
}
|
}
|
||||||
if (track.wayPoints.isNotEmpty()) {
|
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)
|
mapView.overlays.add(trackOverlay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources></resources>
|
|
Loading…
Reference in a new issue