Route points fix and styling

This commit is contained in:
PavelRatushny 2017-08-15 15:01:04 +03:00
parent 865d014caf
commit c3b70afd1c
5 changed files with 57 additions and 5 deletions

View file

@ -824,6 +824,14 @@ public class GPXUtilities {
return g;
}
public List<WptPt> getLastRoutePoints() {
List<WptPt> 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<WptPt> points) {
public void setLastRoutePoints(List<WptPt> 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();

View file

@ -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<WptPt> 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;
}
}

View file

@ -111,6 +111,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return measurementPoints;
}
public void setMeasurementPoints(List<WptPt> points) {
measurementPoints.clear();
measurementPoints.addAll(points);
}
String getDistanceSt() {
float dist = 0;
if (measurementPoints.size() > 0) {

View file

@ -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<WptPt> 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 {

View file

@ -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<MeasurementTool
if (nightMode) {
holder.title.setTextColor(mapActivity.getMyApplication().getResources().getColor(R.color.primary_text_dark));
}
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
WptPt pt = points.get(pos);
String pointTitle = pt.name;
if (!TextUtils.isEmpty(pointTitle)) {
holder.title.setText(pointTitle);
} else {
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
}
if (pos < 1) {
holder.descr.setText(mapActivity.getString(R.string.shared_string_control_start));
} else {