forked from upstream-mirrors/OpenTracks
Cleanup: TrackPoint exposes Position.
This commit is contained in:
@@ -784,8 +784,8 @@ public class ContentProviderUtils {
|
||||
values.put(TrackPointsColumns.TYPE, trackPoint.getType().type_db);
|
||||
|
||||
if (trackPoint.hasLocation()) {
|
||||
values.put(TrackPointsColumns.LONGITUDE, (int) (trackPoint.getLongitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LATITUDE, (int) (trackPoint.getLatitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LATITUDE, (int) (trackPoint.getPosition().latitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LONGITUDE, (int) (trackPoint.getPosition().longitude() * 1E6));
|
||||
}
|
||||
values.put(TrackPointsColumns.TIME, trackPoint.getTime().toEpochMilli());
|
||||
if (trackPoint.hasAltitude()) {
|
||||
|
||||
@@ -132,14 +132,6 @@ public final class Marker {
|
||||
return position;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return position.latitude();
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return position.longitude();
|
||||
}
|
||||
|
||||
public boolean hasAccuracy() {
|
||||
return position.hasHorizontalAccuracy();
|
||||
}
|
||||
|
||||
@@ -147,18 +147,6 @@ public class TrackPoint {
|
||||
return position.hasLocation();
|
||||
}
|
||||
|
||||
//TODO Should be double
|
||||
@Deprecated //Use getPosition()
|
||||
public Double getLatitude() {
|
||||
return position.latitude();
|
||||
}
|
||||
|
||||
//TODO Should be double
|
||||
@Deprecated //Use getPosition()
|
||||
public Double getLongitude() {
|
||||
return position.longitude();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -91,8 +91,8 @@ public class CSVTrackExporter implements TrackExporter {
|
||||
List<Column> columns = List.of(
|
||||
new Column("time", null),
|
||||
new Column("trackpoint_type", t -> quote(t.getType().name())),
|
||||
new Column("latitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getLatitude()) : ""),
|
||||
new Column("longitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getLongitude()) : ""),
|
||||
new Column("latitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getPosition().latitude()) : ""),
|
||||
new Column("longitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getPosition().longitude()) : ""),
|
||||
new Column("altitude", t -> t.hasAltitude() ? ALTITUDE_FORMAT.format(t.getAltitude().toM()) : ""),
|
||||
new Column("accuracy_horizontal", t -> t.hasHorizontalAccuracy() ? DISTANCE_FORMAT.format(t.getHorizontalAccuracy().toM()) : ""),
|
||||
new Column("accuracy_vertical", t -> t.hasVerticalAccuracy() ? DISTANCE_FORMAT.format(t.getVerticalAccuracy().toM()) : ""),
|
||||
|
||||
@@ -36,6 +36,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.TrackPointIterator;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Position;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
@@ -253,7 +254,7 @@ public class GPXTrackExporter implements TrackExporter {
|
||||
}
|
||||
|
||||
private void writeMarker(ZoneOffset zoneOffset, Marker marker) {
|
||||
printWriter.println("<wpt " + formatLocation(marker.getLatitude(), marker.getLongitude()) + ">");
|
||||
printWriter.println("<wpt " + formatLocation(marker.getPosition()) + ">");
|
||||
if (marker.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>");
|
||||
}
|
||||
@@ -311,7 +312,7 @@ public class GPXTrackExporter implements TrackExporter {
|
||||
private Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) {
|
||||
Distance cumulativeDistance;
|
||||
|
||||
printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">");
|
||||
printWriter.println("<trkpt " + formatLocation(trackPoint.getPosition()) + ">");
|
||||
|
||||
if (trackPoint.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(trackPoint.getAltitude().toM()) + "</ele>");
|
||||
@@ -395,7 +396,7 @@ public class GPXTrackExporter implements TrackExporter {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private String formatLocation(double latitude, double longitude) {
|
||||
return "lat=\"" + COORDINATE_FORMAT.format(latitude) + "\" lon=\"" + COORDINATE_FORMAT.format(longitude) + "\"";
|
||||
private String formatLocation(Position position) {
|
||||
return "lat=\"" + COORDINATE_FORMAT.format(position.latitude()) + "\" lon=\"" + COORDINATE_FORMAT.format(position.longitude()) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,8 +432,8 @@ public class KMLTrackExporter implements TrackExporter {
|
||||
printWriter.println("<name>" + StringUtils.formatCData(marker.getName()) + "</name>");
|
||||
printWriter.println("<description>" + StringUtils.formatCData(marker.getDescription()) + "</description>");
|
||||
printWriter.print("<Camera>");
|
||||
printWriter.print("<longitude>" + marker.getLongitude() + "</longitude>");
|
||||
printWriter.print("<latitude>" + marker.getLatitude() + "</latitude>");
|
||||
printWriter.print("<longitude>" + marker.getPosition().longitude() + "</longitude>");
|
||||
printWriter.print("<latitude>" + marker.getPosition().latitude() + "</latitude>");
|
||||
printWriter.print("<altitude>20</altitude>");
|
||||
printWriter.print("<tilt>90</tilt>");
|
||||
printWriter.println("</Camera>");
|
||||
|
||||
@@ -178,10 +178,10 @@ public class TrackImporter {
|
||||
|
||||
if (current.hasLocation()) {
|
||||
Instant time = current.getTime();
|
||||
if (current.getLatitude() == 100) {
|
||||
if (current.getPosition().latitude() == 100) {
|
||||
//TODO Remove by 31st December 2021.
|
||||
trackPoints.set(i, new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, time));
|
||||
} else if (current.getLatitude() == 200) {
|
||||
} else if (current.getPosition().latitude() == 200) {
|
||||
//TODO Remove by 31st December 2021.
|
||||
trackPoints.set(i, new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, time));
|
||||
//TODO Delete location
|
||||
|
||||
@@ -254,9 +254,9 @@ public class MarkerDetailFragment extends Fragment {
|
||||
|
||||
private void setLocation(boolean addShadow) {
|
||||
String value = "[" + getString(R.string.stats_latitude) + " "
|
||||
+ StringUtils.formatCoordinate(getContext(), marker.getLatitude()) + ", "
|
||||
+ StringUtils.formatCoordinate(getContext(), marker.getPosition().latitude()) + ", "
|
||||
+ getString(R.string.stats_longitude) + " "
|
||||
+ StringUtils.formatCoordinate(getContext(), marker.getLongitude()) + "]";
|
||||
+ StringUtils.formatCoordinate(getContext(), marker.getPosition().longitude()) + "]";
|
||||
|
||||
ListItemUtils.setTextView(getActivity(), viewBinding.markerDetailMarkerLocation, value, addShadow);
|
||||
}
|
||||
|
||||
@@ -50,23 +50,14 @@ public class IntentUtils {
|
||||
return new Intent(context, cls).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
public static void showCoordinateOnMap(Context context, Marker marker) {
|
||||
showCoordinateOnMap(context, marker.getLatitude(), marker.getLongitude(), marker.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send intent to show coordinates on a map (needs an another app).
|
||||
*
|
||||
* @param context the context
|
||||
* @param latitude the latitude
|
||||
* @param longitude the longitude
|
||||
* @param label the label
|
||||
*/
|
||||
private static void showCoordinateOnMap(Context context, double latitude, double longitude, String label) {
|
||||
public static void showCoordinateOnMap(Context context, Marker marker) {
|
||||
//SEE https://developer.android.com/guide/components/intents-common.html#Maps
|
||||
String uri = "geo:0,0?q=" + latitude + "," + longitude;
|
||||
if (label != null && label.length() > 0) {
|
||||
uri += "(" + label + ")";
|
||||
String uri = "geo:0,0?q=" + marker.getPosition().latitude() + "," + marker.getPosition().longitude();
|
||||
if (marker.getName() != null && !marker.getName().isEmpty()) {
|
||||
uri += "(" + marker.getName() + ")";
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(uri));
|
||||
|
||||
@@ -45,6 +45,7 @@ import de.dennisguse.opentracks.data.models.Cadence;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.DistanceFormatter;
|
||||
import de.dennisguse.opentracks.data.models.HeartRate;
|
||||
import de.dennisguse.opentracks.data.models.Position;
|
||||
import de.dennisguse.opentracks.data.models.Power;
|
||||
import de.dennisguse.opentracks.settings.UnitSystem;
|
||||
|
||||
@@ -154,13 +155,9 @@ public class StringUtils {
|
||||
|
||||
/**
|
||||
* Formats a complete coordinate (latitude, longitude)
|
||||
*
|
||||
* @param context the context's object.
|
||||
* @param latitude the coordinate's latitude.
|
||||
* @param longitude the coordinate's longitude.
|
||||
*/
|
||||
public static String formatCoordinate(Context context, double latitude, double longitude) {
|
||||
return context.getString(R.string.location_latitude_longitude, Location.convert(latitude, Location.FORMAT_DEGREES), Location.convert(longitude, Location.FORMAT_DEGREES));
|
||||
public static String formatCoordinate(Context context, Position position) {
|
||||
return context.getString(R.string.location_latitude_longitude, Location.convert(position.latitude(), Location.FORMAT_DEGREES), Location.convert(position.longitude(), Location.FORMAT_DEGREES));
|
||||
}
|
||||
|
||||
public static Pair<String, String> getHeartRateParts(Context context, HeartRate heartrate) {
|
||||
|
||||
@@ -265,7 +265,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
|
||||
TrackPoint latestTrackPoint = data.latestTrackPoint();
|
||||
String value;
|
||||
if (latestTrackPoint != null && latestTrackPoint.hasLocation()) {
|
||||
value = StringUtils.formatCoordinate(getContext(), latestTrackPoint.getLatitude(), latestTrackPoint.getLongitude());
|
||||
value = StringUtils.formatCoordinate(getContext(), latestTrackPoint.getPosition());
|
||||
} else {
|
||||
value = getContext().getString(R.string.value_unknown);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user