Plan route point menu - Trim left/Trim right
This commit is contained in:
parent
43fe12c05c
commit
82905381dc
4 changed files with 96 additions and 43 deletions
|
@ -262,22 +262,55 @@ public class MeasurementEditingContext {
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void trimBefore(int selectedPointPosition) {
|
||||||
|
splitSegments(selectedPointPosition);
|
||||||
|
clearBeforeSegments();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void trimAfter(int selectedPointPosition) {
|
||||||
|
splitSegments(selectedPointPosition + 1);
|
||||||
|
clearAfterSegments();
|
||||||
|
}
|
||||||
|
|
||||||
public void clearSegments() {
|
public void clearSegments() {
|
||||||
|
clearBeforeSegments();
|
||||||
|
clearAfterSegments();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearBeforeSegments() {
|
||||||
before.points.clear();
|
before.points.clear();
|
||||||
after.points.clear();
|
|
||||||
if (isInSnapToRoadMode()) {
|
if (isInSnapToRoadMode()) {
|
||||||
if (beforeCacheForSnap != null && afterCacheForSnap != null) {
|
if (beforeCacheForSnap != null) {
|
||||||
beforeCacheForSnap.points.clear();
|
beforeCacheForSnap.points.clear();
|
||||||
afterCacheForSnap.points.clear();
|
|
||||||
}
|
}
|
||||||
needUpdateCacheForSnap = true;
|
needUpdateCacheForSnap = true;
|
||||||
} else {
|
} else {
|
||||||
beforeCacheForSnap = null;
|
beforeCacheForSnap = null;
|
||||||
|
needUpdateCacheForSnap = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAfterSegments() {
|
||||||
|
after.points.clear();
|
||||||
|
if (isInSnapToRoadMode()) {
|
||||||
|
if (afterCacheForSnap != null) {
|
||||||
|
afterCacheForSnap.points.clear();
|
||||||
|
}
|
||||||
|
needUpdateCacheForSnap = true;
|
||||||
|
} else {
|
||||||
afterCacheForSnap = null;
|
afterCacheForSnap = null;
|
||||||
needUpdateCacheForSnap = false;
|
needUpdateCacheForSnap = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFirstPointSelected() {
|
||||||
|
return selectedPointPosition == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLastPointSelected() {
|
||||||
|
return selectedPointPosition == getPoints().size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
public void scheduleRouteCalculateIfNotEmpty() {
|
public void scheduleRouteCalculateIfNotEmpty() {
|
||||||
needUpdateCacheForSnap = true;
|
needUpdateCacheForSnap = true;
|
||||||
if (application == null || (before.points.size() == 0 && after.points.size() == 0)) {
|
if (application == null || (before.points.size() == 0 && after.points.size() == 0)) {
|
||||||
|
|
|
@ -102,6 +102,8 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_
|
||||||
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK;
|
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK;
|
||||||
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener;
|
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener;
|
||||||
import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener;
|
import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener;
|
||||||
|
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.*;
|
||||||
|
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.*;
|
||||||
|
|
||||||
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
|
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
|
||||||
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener {
|
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener {
|
||||||
|
@ -701,7 +703,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
@Override
|
@Override
|
||||||
public void clearAllOnClick() {
|
public void clearAllOnClick() {
|
||||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer));
|
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, ALL));
|
||||||
editingCtx.cancelSnapToRoad();
|
editingCtx.cancelSnapToRoad();
|
||||||
if (pointsListOpened) {
|
if (pointsListOpened) {
|
||||||
hidePointsList();
|
hidePointsList();
|
||||||
|
@ -763,12 +765,25 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrimRouteBefore() {
|
public void onTrimRouteBefore() {
|
||||||
|
trimRoute(BEFORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrimRouteAfter() {
|
public void onTrimRouteAfter() {
|
||||||
|
trimRoute(AFTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trimRoute(ClearCommandMode before) {
|
||||||
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
|
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, before));
|
||||||
|
if (pointsListOpened) {
|
||||||
|
hidePointsList();
|
||||||
|
}
|
||||||
|
editingCtx.setSelectedPointPosition(-1);
|
||||||
|
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
|
||||||
|
updateUndoRedoButton(false, redoBtn);
|
||||||
|
updateDistancePointsText();
|
||||||
|
saved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1009,7 +1024,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
|
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
|
||||||
editingCtx.resetAppMode();
|
editingCtx.resetAppMode();
|
||||||
editingCtx.cancelSnapToRoad();
|
editingCtx.cancelSnapToRoad();
|
||||||
visibleSnapToRoadIcon(false);
|
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
|
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
|
||||||
|
@ -1033,16 +1047,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visibleSnapToRoadIcon(boolean show) {
|
private void hideSnapToRoadIcon() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
if (show) {
|
|
||||||
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
|
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void displayRoutePoints() {
|
private void displayRoutePoints() {
|
||||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
|
@ -1794,9 +1804,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
}
|
}
|
||||||
if (editingCtx.isInSnapToRoadMode()) {
|
if (editingCtx.isInSnapToRoadMode()) {
|
||||||
resetSnapToRoadMode();
|
resetSnapToRoadMode();
|
||||||
} else {
|
|
||||||
visibleSnapToRoadIcon(false);
|
|
||||||
}
|
}
|
||||||
|
hideSnapToRoadIcon();
|
||||||
if (!editingCtx.isNewData() && !planRouteMode) {
|
if (!editingCtx.isNewData() && !planRouteMode) {
|
||||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||||
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
|
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
|
||||||
|
|
|
@ -37,9 +37,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
|
|
||||||
public static final String TAG = SelectedPointBottomSheetDialogFragment.class.getSimpleName();
|
public static final String TAG = SelectedPointBottomSheetDialogFragment.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(SelectedPointBottomSheetDialogFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(SelectedPointBottomSheetDialogFragment.class);
|
||||||
|
private MeasurementEditingContext editingCtx;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
||||||
|
|
||||||
View titleView = UiUtilities.getInflater(getContext(), nightMode)
|
View titleView = UiUtilities.getInflater(getContext(), nightMode)
|
||||||
.inflate(R.layout.bottom_sheet_item_with_descr_pad_32dp, null, false);
|
.inflate(R.layout.bottom_sheet_item_with_descr_pad_32dp, null, false);
|
||||||
|
@ -126,6 +132,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setDisabled(editingCtx.isFirstPointSelected())
|
||||||
.create();
|
.create();
|
||||||
items.add(trimRouteBefore);
|
items.add(trimRouteBefore);
|
||||||
|
|
||||||
|
@ -144,6 +151,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setDisabled(editingCtx.isLastPointSelected())
|
||||||
.create();
|
.create();
|
||||||
items.add(trimRouteAfter);
|
items.add(trimRouteAfter);
|
||||||
|
|
||||||
|
@ -164,6 +172,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setDisabled(editingCtx.isFirstPointSelected())
|
||||||
.create();
|
.create();
|
||||||
items.add(changeRouteTypeBefore);
|
items.add(changeRouteTypeBefore);
|
||||||
|
|
||||||
|
@ -182,6 +191,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setDisabled(editingCtx.isLastPointSelected())
|
||||||
.create();
|
.create();
|
||||||
items.add(changeRouteTypeAfter);
|
items.add(changeRouteTypeAfter);
|
||||||
|
|
||||||
|
@ -249,24 +259,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String getTitle() {
|
private String getTitle() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
|
||||||
if (mapActivity == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
|
||||||
int pos = editingCtx.getSelectedPointPosition();
|
int pos = editingCtx.getSelectedPointPosition();
|
||||||
|
|
||||||
String pointName = editingCtx.getPoints().get(pos).name;
|
String pointName = editingCtx.getPoints().get(pos).name;
|
||||||
if (!TextUtils.isEmpty(pointName)) {
|
if (!TextUtils.isEmpty(pointName)) {
|
||||||
return pointName;
|
return pointName;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewGpxData newGpxData = editingCtx.getNewGpxData();
|
NewGpxData newGpxData = editingCtx.getNewGpxData();
|
||||||
if (newGpxData != null && newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS) {
|
if (newGpxData != null && newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS) {
|
||||||
return getString(R.string.route_point) + " - " + (pos + 1);
|
return getString(R.string.route_point) + " - " + (pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getString(R.string.plugin_distance_point) + " - " + (pos + 1);
|
return getString(R.string.plugin_distance_point) + " - " + (pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,18 +277,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
if (mapActivity == null) {
|
if (mapActivity == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder description = new StringBuilder();
|
StringBuilder description = new StringBuilder();
|
||||||
|
|
||||||
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
||||||
int pos = editingCtx.getSelectedPointPosition();
|
int pos = editingCtx.getSelectedPointPosition();
|
||||||
List<WptPt> points = editingCtx.getPoints();
|
List<WptPt> points = editingCtx.getPoints();
|
||||||
WptPt pt = points.get(pos);
|
WptPt pt = points.get(pos);
|
||||||
|
|
||||||
String pointDesc = pt.desc;
|
String pointDesc = pt.desc;
|
||||||
if (!TextUtils.isEmpty(pointDesc)) {
|
if (!TextUtils.isEmpty(pointDesc)) {
|
||||||
description.append(pointDesc);
|
description.append(pointDesc);
|
||||||
} else if (pos < 1) {
|
} else if (pos < 1 && before) {
|
||||||
description.append(getString(R.string.shared_string_control_start));
|
description.append(getString(R.string.shared_string_control_start));
|
||||||
} else {
|
} else {
|
||||||
float dist = 0;
|
float dist = 0;
|
||||||
|
@ -307,7 +305,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
}
|
}
|
||||||
description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NewGpxData newGpxData = editingCtx.getNewGpxData();
|
NewGpxData newGpxData = editingCtx.getNewGpxData();
|
||||||
if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) {
|
if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) {
|
||||||
double elevation = pt.ele;
|
double elevation = pt.ele;
|
||||||
|
@ -321,22 +318,14 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
description.append(OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication()));
|
description.append(OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return description.toString();
|
return description.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Drawable getRouteTypeIcon(boolean before) {
|
private Drawable getRouteTypeIcon(boolean before) {
|
||||||
Drawable icon = getContentIcon(R.drawable.ic_action_split_interval);
|
Drawable icon = getContentIcon(R.drawable.ic_action_split_interval);
|
||||||
MapActivity mapActivity = getMapActivity();
|
|
||||||
if (mapActivity == null) {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
|
||||||
int pos = editingCtx.getSelectedPointPosition();
|
int pos = editingCtx.getSelectedPointPosition();
|
||||||
pos = before ? pos : Math.max(pos - 1, 0);
|
pos = before ? pos : Math.max(pos - 1, 0);
|
||||||
|
|
||||||
String profileType = editingCtx.getPoints().get(pos).getProfileType();
|
String profileType = editingCtx.getPoints().get(pos).getProfileType();
|
||||||
ApplicationMode routeAppMode = ApplicationMode.valueOfStringKey(profileType, null);
|
ApplicationMode routeAppMode = ApplicationMode.valueOfStringKey(profileType, null);
|
||||||
if (routeAppMode != null) {
|
if (routeAppMode != null) {
|
||||||
|
|
|
@ -4,31 +4,54 @@ import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ClearPointsCommand extends MeasurementModeCommand {
|
public class ClearPointsCommand extends MeasurementModeCommand {
|
||||||
|
|
||||||
private List<WptPt> points;
|
private List<WptPt> points;
|
||||||
private boolean needUpdateCache;
|
private boolean needUpdateCache;
|
||||||
|
ClearCommandMode clearMode;
|
||||||
|
private int pointPosition;
|
||||||
|
|
||||||
public ClearPointsCommand(MeasurementToolLayer measurementLayer) {
|
public enum ClearCommandMode {
|
||||||
|
ALL,
|
||||||
|
BEFORE,
|
||||||
|
AFTER
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClearPointsCommand(MeasurementToolLayer measurementLayer, ClearCommandMode clearMode) {
|
||||||
super(measurementLayer);
|
super(measurementLayer);
|
||||||
|
this.clearMode = clearMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute() {
|
public boolean execute() {
|
||||||
|
pointPosition = getEditingCtx().getSelectedPointPosition();
|
||||||
|
executeCommand();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeCommand() {
|
||||||
List<WptPt> pts = getEditingCtx().getPoints();
|
List<WptPt> pts = getEditingCtx().getPoints();
|
||||||
needUpdateCache = getEditingCtx().isNeedUpdateCacheForSnap();
|
needUpdateCache = getEditingCtx().isNeedUpdateCacheForSnap();
|
||||||
points = new ArrayList<>(pts);
|
points = new ArrayList<>(pts);
|
||||||
|
switch (clearMode) {
|
||||||
|
case ALL:
|
||||||
pts.clear();
|
pts.clear();
|
||||||
getEditingCtx().clearSegments();
|
getEditingCtx().clearSegments();
|
||||||
|
break;
|
||||||
|
case BEFORE:
|
||||||
|
getEditingCtx().trimBefore(pointPosition);
|
||||||
|
break;
|
||||||
|
case AFTER:
|
||||||
|
getEditingCtx().trimAfter(pointPosition);
|
||||||
|
}
|
||||||
refreshMap();
|
refreshMap();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
getEditingCtx().clearSegments();
|
||||||
getEditingCtx().addPoints(points);
|
getEditingCtx().addPoints(points);
|
||||||
if (needUpdateCache) {
|
if (needUpdateCache) {
|
||||||
getEditingCtx().setNeedUpdateCacheForSnap(true);
|
getEditingCtx().setNeedUpdateCacheForSnap(true);
|
||||||
|
@ -38,8 +61,7 @@ public class ClearPointsCommand extends MeasurementModeCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void redo() {
|
public void redo() {
|
||||||
getEditingCtx().clearSegments();
|
executeCommand();
|
||||||
refreshMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue