From c3b70afd1c90d6e4f429dbf63882ba08f51bbc66 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 15 Aug 2017 15:01:04 +0300 Subject: [PATCH] Route points fix and styling --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 11 +++++++- .../MeasurementToolFragment.java | 28 +++++++++++++++++-- .../measurementtool/MeasurementToolLayer.java | 5 ++++ ...tedPointMenuBottomSheetDialogFragment.java | 9 +++++- .../adapter/MeasurementToolAdapter.java | 9 +++++- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 3bc4adc94e..407124f2f2 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -824,6 +824,14 @@ public class GPXUtilities { return g; } + public List getLastRoutePoints() { + List points = new ArrayList<>(); + if (routes.size() > 0) { + Route rt = routes.get(routes.size() - 1); + points.addAll(rt.points); + } + return points; + } public boolean hasRtePt() { for (Route r : routes) { @@ -909,11 +917,12 @@ public class GPXUtilities { modifiedTime = System.currentTimeMillis(); } - public void addRtePts(List points) { + public void setLastRoutePoints(List points) { if (routes.size() == 0) { routes.add(new Route()); } Route currentRoute = routes.get(routes.size() - 1); + currentRoute.points.clear(); currentRoute.points.addAll(points); modifiedTime = System.currentTimeMillis(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 41299545ee..2378c8c81f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -327,7 +327,12 @@ public class MeasurementToolFragment extends Fragment { toolBarController = new MeasurementToolBarController(newGpxLine); if (newGpxLine != null) { - toolBarController.setTitle(getString(R.string.add_line)); + LineType lineType = newGpxLine.getLineType(); + if (lineType == LineType.ROUTE_POINTS) { + toolBarController.setTitle(getString(R.string.add_route_points)); + } else if (lineType == LineType.SEGMENT) { + toolBarController.setTitle(getString(R.string.add_line)); + } } else { toolBarController.setTitle(getString(R.string.measurement_tool_action_bar)); } @@ -412,6 +417,13 @@ public class MeasurementToolFragment extends Fragment { enterMeasurementMode(); + if (newGpxLine != null) { + LineType lineType = newGpxLine.getLineType(); + if (lineType == LineType.ROUTE_POINTS) { + displayRoutePoints(mapActivity); + } + } + return view; } @@ -430,6 +442,18 @@ public class MeasurementToolFragment extends Fragment { } } + private void displayRoutePoints(MapActivity mapActivity) { + final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); + + GPXFile gpx = newGpxLine.getGpxFile(); + List points = gpx.getLastRoutePoints(); + if (measurementLayer != null) { + measurementLayer.setMeasurementPoints(points); + adapter.notifyDataSetChanged(); + updateText(); + } + } + private void openSelectedPointMenu(MapActivity mapActivity) { final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); @@ -856,7 +880,7 @@ public class MeasurementToolFragment extends Fragment { gpx.addTrkSegment(points); break; case ROUTE_POINTS: - gpx.addRtePts(points); + gpx.setLastRoutePoints(points); break; } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 0abc4cf423..8daf6992f0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -111,6 +111,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL return measurementPoints; } + public void setMeasurementPoints(List points) { + measurementPoints.clear(); + measurementPoints.addAll(points); + } + String getDistanceSt() { float dist = 0; if (measurementPoints.size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointMenuBottomSheetDialogFragment.java index 6c76da9ad9..f5a1f2fabe 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointMenuBottomSheetDialogFragment.java @@ -6,6 +6,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; +import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -106,7 +107,13 @@ public class SelectedPointMenuBottomSheetDialogFragment extends BottomSheetDialo List points = measurementLayer.getMeasurementPoints(); int pos = measurementLayer.getSelectedPointPos(); - ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " " + (pos + 1)); + WptPt pt = points.get(pos); + String pointTitle = pt.name; + if (!TextUtils.isEmpty(pointTitle)) { + ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle); + } else { + ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); + } if (pos < 1) { ((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(mapActivity.getString(R.string.shared_string_control_start)); } else { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java index cfb87e0df7..4bfab038d1 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java @@ -3,6 +3,7 @@ package net.osmand.plus.measurementtool.adapter; import android.support.v4.content.ContextCompat; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -75,7 +76,13 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter