Fix plan route options

This commit is contained in:
Dima-1 2020-08-12 16:50:54 +03:00
parent 40edfa2a3f
commit 25f564393b
7 changed files with 228 additions and 130 deletions

View file

@ -315,10 +315,14 @@ public class GPXUtilities {
getExtensionsToWrite().put(PROFILE_TYPE_EXTENSION, profileType);
}
public void removeProfileType() {
getExtensionsToWrite().remove(PROFILE_TYPE_EXTENSION);
}
public int getTrkPtIndex() {
try {
return Integer.parseInt(getExtensionsToRead().get(TRKPT_INDEX_EXTENSION));
}catch(NumberFormatException e){
} catch (NumberFormatException e) {
return -1;
}
}

View file

@ -17,7 +17,6 @@ import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RoutePlannerFrontEnd;
import net.osmand.router.RoutePlannerFrontEnd.GpxPoint;
import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import net.osmand.router.RouteSegmentResult;
@ -32,11 +31,11 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType.*;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.*;
public class MeasurementEditingContext {
public enum CalculationType {
public enum CalculationMode {
NEXT_SEGMENT,
WHOLE_TRACK
}
@ -58,8 +57,7 @@ public class MeasurementEditingContext {
private boolean inSnapToRoadMode;
private boolean needUpdateCacheForSnap;
private int calculatedPairs;
private CalculationType calculationType = WHOLE_TRACK;
private CalculationMode calculationMode = WHOLE_TRACK;
private SnapToRoadProgressListener progressListener;
private ApplicationMode snapToRoadAppMode;
private RouteCalculationProgress calculationProgress;
@ -91,7 +89,7 @@ public class MeasurementEditingContext {
updateCacheForSnapIfNeeded(true);
}
int getSelectedPointPosition() {
public int getSelectedPointPosition() {
return selectedPointPosition;
}
@ -111,7 +109,7 @@ public class MeasurementEditingContext {
this.inAddPointMode = inAddPointMode;
}
void setInSnapToRoadMode(boolean inSnapToRoadMode) {
public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
this.inSnapToRoadMode = inSnapToRoadMode;
}
@ -131,12 +129,12 @@ public class MeasurementEditingContext {
return newGpxData != null && newGpxData.getGpxFile() != null && newGpxData.getGpxFile().hasRtePt();
}
public CalculationType getCalculationType() {
return calculationType;
public CalculationMode getCalculationMode() {
return calculationMode;
}
public void setCalculationType(CalculationType calculationType) {
this.calculationType = calculationType;
public void setCalculationMode(CalculationMode calculationMode) {
this.calculationMode = calculationMode;
}
void setProgressListener(SnapToRoadProgressListener progressListener) {
@ -147,17 +145,15 @@ public class MeasurementEditingContext {
return snapToRoadAppMode;
}
void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
if (this.snapToRoadAppMode != null && snapToRoadAppMode != null
&& !this.snapToRoadAppMode.getStringKey().equals(snapToRoadAppMode.getStringKey())) {
if (calculationType == WHOLE_TRACK) {
snappedToRoadPoints.clear();
updateCacheForSnapIfNeeded(true);
}
}
public void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
this.snapToRoadAppMode = snapToRoadAppMode;
}
public void clearSnappedToRoadPoints() {
snappedToRoadPoints.clear();
}
TrkSegment getBeforeTrkSegmentLine() {
if (beforeCacheForSnap != null) {
return beforeCacheForSnap;
@ -241,7 +237,7 @@ public class MeasurementEditingContext {
}
}
void scheduleRouteCalculateIfNotEmpty() {
public void scheduleRouteCalculateIfNotEmpty() {
needUpdateCacheForSnap = true;
if (application == null || (before.points.size() == 0 && after.points.size() == 0)) {
return;
@ -411,9 +407,23 @@ public class MeasurementEditingContext {
final RouteCalculationParams params = new RouteCalculationParams();
params.inSnapToRoadMode = true;
params.start = start;
ApplicationMode currentPointSnapToRoadMode;
if (calculationMode == NEXT_SEGMENT) {
currentPointSnapToRoadMode = ApplicationMode.valueOfStringKey(currentPair.first.getProfileType(),
null);
} else {
currentPointSnapToRoadMode = snapToRoadAppMode;
}
params.end = end;
RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
params.mode = snapToRoadAppMode;
if (currentPointSnapToRoadMode == null) {
ApplicationMode straightLine = ApplicationMode.AIRCRAFT;
RoutingHelper.applyApplicationSettings(params, application.getSettings(), straightLine);
params.mode = straightLine;
} else {
RoutingHelper.applyApplicationSettings(params, application.getSettings(), currentPointSnapToRoadMode);
params.mode = currentPointSnapToRoadMode;
}
params.ctx = application;
params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@ -539,8 +549,14 @@ public class MeasurementEditingContext {
params.start = start;
params.end = end;
params.intermediates = intermediates;
if (snapToRoadAppMode == null) {
ApplicationMode straightLine = ApplicationMode.AIRCRAFT;
RoutingHelper.applyApplicationSettings(params, application.getSettings(), straightLine);
params.mode = straightLine;
} else {
RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
params.mode = snapToRoadAppMode;
}
params.ctx = application;
params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {

View file

@ -16,7 +16,6 @@ import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -69,6 +68,7 @@ import net.osmand.plus.measurementtool.SelectedPointBottomSheetDialogFragment.Se
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener;
import net.osmand.plus.measurementtool.command.AddPointCommand;
import net.osmand.plus.measurementtool.command.ChangeRouteModeCommand;
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
@ -95,7 +95,7 @@ import java.util.Locale;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.plus.measurementtool.GpxApproximationFragment.GpxApproximationFragmentListener;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.ExportAsGpxListener;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.SnapToRoadProgressListener;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_TRACK;
@ -224,7 +224,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
pointsListContainer = view.findViewById(R.id.points_list_container);
if (portrait && pointsListContainer != null) {
final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light);
final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode
? R.color.activity_background_color_dark
: R.color.activity_background_color_light);
pointsListContainer.setBackgroundColor(backgroundColor);
}
@ -311,13 +313,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void onClick(View view) {
editingCtx.getCommandManager().undo();
updateUndoRedoButton(editingCtx.getCommandManager().canUndo(), undoBtn);
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
updateUndoRedoButton(true, redoBtn);
updateDistancePointsText();
updateUndoRedoCommonStuff();
}
});
@ -328,13 +325,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void onClick(View view) {
editingCtx.getCommandManager().redo();
updateUndoRedoButton(editingCtx.getCommandManager().canRedo(), redoBtn);
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
updateUndoRedoButton(true, undoBtn);
updateDistancePointsText();
updateUndoRedoCommonStuff();
}
});
@ -447,14 +439,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
});
toolBarController.setOnSwitchCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (!checked) {
disableSnapToRoadMode();
}
}
});
mapActivity.showTopToolbar(toolBarController);
adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(),
@ -470,6 +454,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
pointsRv.setLayoutManager(new LinearLayoutManager(getContext()));
pointsRv.setAdapter(adapter);
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startSnapToRoad(false);
}
});
snapToRoadBtn.setVisibility(View.VISIBLE);
initMeasurementMode(newGpxData);
if (planRouteMode && savedInstanceState == null) {
@ -479,19 +473,28 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return view;
}
private void updateUndoRedoCommonStuff() {
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
updateDistancePointsText();
updateSnapToRoadControls();
}
private void initMeasurementMode(NewGpxData newGpxData) {
editingCtx.getCommandManager().resetMeasurementLayer(getMapActivity().getMapLayers().getMeasurementToolLayer());
enterMeasurementMode();
showSnapToRoadControls();
updateSnapToRoadControls();
if (newGpxData != null && !gpxPointsAdded) {
List<WptPt> points = newGpxData.getGpxFile().getRoutePoints();
ApplicationMode snapToRoadAppMode = null;
if (!points.isEmpty()) {
ApplicationMode snapToRoadAppMode = ApplicationMode
snapToRoadAppMode = ApplicationMode
.valueOfStringKey(points.get(points.size() - 1).getProfileType(), null);
if (snapToRoadAppMode != null) {
}
enableSnapToRoadMode(snapToRoadAppMode);
}
}
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_ROUTE_POINTS) {
displayRoutePoints();
@ -639,7 +642,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (editingCtx.isNewData() || editingCtx.hasRoutePoints()) {
RouteBetweenPointsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, editingCtx.getCalculationType(),
this, editingCtx.getCalculationMode(),
editingCtx.getSnapToRoadAppMode());
} else {
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
@ -772,9 +775,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void deleteOnClick() {
if (measurementLayer != null) {
removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
}
editingCtx.setSelectedPointPosition(-1);
}
@ -826,21 +827,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
@Override
public void onChangeApplicationMode(ApplicationMode mode) {
if (mode == null) {
disableSnapToRoadMode();
editingCtx.setSnapToRoadAppMode(null);
showSnapToRoadControls();
} else {
enableSnapToRoadMode(mode);
public void onChangeApplicationMode(ApplicationMode mode, CalculationMode calculationMode) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
editingCtx.getCommandManager().execute(new ChangeRouteModeCommand(measurementLayer, mode, calculationMode));
updateUndoRedoButton(false, redoBtn);
disable(upDownBtn);
updateSnapToRoadControls();
updateDistancePointsText();
}
}
@Override
public void onChangeCalculationType(CalculationType calculationType) {
editingCtx.setCalculationType(calculationType);
}
private StartPlanRouteListener createStartPlanRouteListener() {
return new StartPlanRouteListener() {
@Override
@ -946,8 +943,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return null;
}
private void removePoint(MeasurementToolLayer layer, int position) {
editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position));
private void removePoint(MeasurementToolLayer measurementLayer, int position) {
if (measurementLayer != null) {
editingCtx.getCommandManager().execute(new RemovePointCommand(measurementLayer, position));
adapter.notifyDataSetChanged();
updateUndoRedoButton(true, undoBtn);
updateUndoRedoButton(false, redoBtn);
@ -955,6 +953,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
saved = false;
hidePointsListIfNoPoints();
}
}
private SaveAsNewTrackFragmentListener createSaveAsNewTrackFragmentListener() {
return new SaveAsNewTrackFragmentListener() {
@ -980,10 +979,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onRemoveClick(int position) {
if (measurementLayer != null) {
removePoint(measurementLayer, position);
}
}
@Override
public void onItemClick(int position) {
@ -1026,10 +1023,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
editingCtx.setSnapToRoadAppMode(appMode);
editingCtx.setInSnapToRoadMode(true);
editingCtx.scheduleRouteCalculateIfNotEmpty();
showSnapToRoadControls();
updateSnapToRoadControls();
}
private void showSnapToRoadControls() {
private void updateSnapToRoadControls() {
final MapActivity mapActivity = getMapActivity();
final ApplicationMode appMode = editingCtx.getSnapToRoadAppMode();
if (mapActivity != null) {
@ -1040,15 +1037,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
icon = getIcon(appMode.getIconRes(), appMode.getIconColorInfo().getColor(nightMode));
}
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setImageDrawable(icon);
snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startSnapToRoad(false);
}
});
snapToRoadBtn.setVisibility(View.VISIBLE);
mapActivity.refreshMap();
}
}
@ -1124,7 +1113,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void showAddToTrackDialog(final MapActivity mapActivity) {
if (mapActivity != null) {
SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createAddToTrackFileListener(),ADD_TO_TRACK);
createAddToTrackFileListener(), ADD_TO_TRACK);
}
}
@ -1223,7 +1212,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
}
mapActivity.showTopToolbar(toolBarController);
}
markGeneralComponents(enable ? View.GONE : View.VISIBLE);
AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE,
R.id.move_point_text,
@ -1232,6 +1220,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
? R.drawable.ic_action_move_point
: R.drawable.ic_action_ruler));
}
}
private void switchAddPointBeforeAfterMode(boolean enable) {
MapActivity mapActivity = getMapActivity();
@ -1243,15 +1232,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
}
mapActivity.showTopToolbar(toolBarController);
}
markGeneralComponents(enable ? View.GONE : View.VISIBLE);
AndroidUiHelper.setVisibility(mapActivity,enable ? View.VISIBLE : View.GONE,
AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE,
R.id.add_point_before_after_text,
R.id.add_point_before_after_controls);
if (!enable) {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
}
}
}
private void markGeneralComponents(int status) {
MapActivity mapActivity = getMapActivity();

View file

@ -26,7 +26,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType;
import net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode;
import net.osmand.plus.settings.backend.ApplicationMode;
import org.apache.commons.logging.Log;
@ -35,22 +35,22 @@ import java.util.ArrayList;
import java.util.List;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.*;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType.NEXT_SEGMENT;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType.WHOLE_TRACK;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.NEXT_SEGMENT;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK;
public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final Log LOG = PlatformUtil.getLog(RouteBetweenPointsBottomSheetDialogFragment.class);
public static final String TAG = RouteBetweenPointsBottomSheetDialogFragment.class.getSimpleName();
public static final int STRAIGHT_LINE_TAG = -1;
public static final String CALCULATION_TYPE_KEY = "calculation_type";
public static final String CALCULATION_MODE_KEY = "calculation_type";
public static final String ROUTE_APP_MODE_KEY = "route_app_mode";
private boolean nightMode;
private boolean portrait;
private boolean snapToRoadEnabled;
private boolean snapToRoadEnabled = true;
private TextView btnDescription;
private CalculationType calculationType = WHOLE_TRACK;
private CalculationMode calculationMode = WHOLE_TRACK;
private ApplicationMode snapToRoadAppMode;
private LinearLayout customRadioButton;
@ -61,10 +61,10 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
Bundle args = getArguments();
if (args != null) {
snapToRoadAppMode = ApplicationMode.valueOfStringKey(args.getString(ROUTE_APP_MODE_KEY), null);
calculationType = (CalculationType) args.get(CALCULATION_TYPE_KEY);
calculationMode = (CalculationMode) args.get(CALCULATION_MODE_KEY);
}
if (savedInstanceState != null) {
calculationType = (CalculationType) savedInstanceState.get(CALCULATION_TYPE_KEY);
calculationMode = (CalculationMode) savedInstanceState.get(CALCULATION_MODE_KEY);
}
OsmandApplication app = requiredMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
@ -108,7 +108,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
}
Fragment fragment = getTargetFragment();
if (fragment instanceof RouteBetweenPointsFragmentListener) {
((RouteBetweenPointsFragmentListener) fragment).onChangeApplicationMode(mode);
((RouteBetweenPointsFragmentListener) fragment).onChangeApplicationMode(mode, calculationMode);
}
dismiss();
}
@ -137,7 +137,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
updateModeButtons(WHOLE_TRACK);
}
});
updateModeButtons(calculationType);
updateModeButtons(calculationMode);
return mainView;
}
@ -150,19 +150,15 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
container.addView(row);
}
private void updateModeButtons(CalculationType calculationType) {
if (calculationType == NEXT_SEGMENT) {
private void updateModeButtons(CalculationMode calculationMode) {
if (calculationMode == NEXT_SEGMENT) {
UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode, LEFT);
btnDescription.setText(R.string.rourte_between_points_next_segment_button_desc);
} else {
btnDescription.setText(R.string.rourte_between_points_whole_track_button_desc);
UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode, RIGHT);
}
setCalculationType(calculationType);
Fragment fragment = getTargetFragment();
if (fragment instanceof RouteBetweenPointsFragmentListener) {
((RouteBetweenPointsFragmentListener) fragment).onChangeCalculationType(calculationType);
}
setCalculationMode(calculationMode);
}
private void addProfileView(LinearLayout container, View.OnClickListener onClickListener, Object tag,
@ -197,7 +193,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(CALCULATION_TYPE_KEY, calculationType);
outState.putSerializable(CALCULATION_MODE_KEY, calculationMode);
}
@Override
@ -209,18 +205,18 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
super.onDestroyView();
}
public void setCalculationType(CalculationType calculationType) {
this.calculationType = calculationType;
public void setCalculationMode(CalculationMode calculationMode) {
this.calculationMode = calculationMode;
}
public static void showInstance(FragmentManager fm, Fragment targetFragment, CalculationType calculationType,
public static void showInstance(FragmentManager fm, Fragment targetFragment, CalculationMode calculationMode,
ApplicationMode applicationMode) {
try {
if (!fm.isStateSaved()) {
RouteBetweenPointsBottomSheetDialogFragment fragment = new RouteBetweenPointsBottomSheetDialogFragment();
Bundle args = new Bundle();
args.putString(ROUTE_APP_MODE_KEY, applicationMode != null ? applicationMode.getStringKey() : null);
args.putSerializable(CALCULATION_TYPE_KEY, calculationType);
args.putSerializable(CALCULATION_MODE_KEY, calculationMode);
fragment.setArguments(args);
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fm, TAG);
@ -234,8 +230,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial
void onCloseRouteDialog(boolean snapToRoadEnabled);
void onChangeApplicationMode(ApplicationMode mode);
void onChangeApplicationMode(ApplicationMode mode, CalculationMode calculationMode);
void onChangeCalculationType(CalculationType calculationType);
}
}

View file

@ -24,6 +24,7 @@ public class AddPointCommand extends MeasurementModeCommand {
point = new WptPt();
point.lat = latLon.getLatitude();
point.lon = latLon.getLongitude();
point.setProfileType(measurementLayer.getEditingCtx().getSnapToRoadAppMode().getStringKey());
}
this.center = center;
position = measurementLayer.getEditingCtx().getPointsCount();

View file

@ -0,0 +1,92 @@
package net.osmand.plus.measurementtool.command;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.settings.backend.ApplicationMode;
import java.util.LinkedList;
import java.util.List;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.*;
public class ChangeRouteModeCommand extends MeasurementModeCommand {
private List<WptPt> points;
int pointIdx;
ApplicationMode oldMode;
ApplicationMode newMode;
CalculationMode oldCalculationMode;
CalculationMode newCalculationMode;
public ChangeRouteModeCommand(MeasurementToolLayer measurementLayer, ApplicationMode newMode,
CalculationMode newCalculationMode) {
this.measurementLayer = measurementLayer;
this.newMode = newMode;
this.newCalculationMode = newCalculationMode;
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
oldMode = editingCtx.getSnapToRoadAppMode();
oldCalculationMode = editingCtx.getCalculationMode();
}
@Override
public boolean execute() {
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
points = new LinkedList<>(editingCtx.getPoints());
pointIdx = points.size() - 1;
if (pointIdx > 0 && newCalculationMode != CalculationMode.WHOLE_TRACK) {
if (newMode != null) {
points.get(pointIdx).setProfileType(newMode.getStringKey());
} else {
points.get(pointIdx).removeProfileType();
}
}
editingCtx.setCalculationMode(newCalculationMode);
editingCtx.setInSnapToRoadMode(true);
editingCtx.setSnapToRoadAppMode(newMode);
if (newCalculationMode == CalculationMode.WHOLE_TRACK) {
editingCtx.clearSnappedToRoadPoints();
}
editingCtx.setNeedUpdateCacheForSnap(true);
return true;
}
@Override
public void undo() {
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
editingCtx.getPoints().clear();
editingCtx.addPoints(points);
editingCtx.setSnapToRoadAppMode(oldMode);
if (newCalculationMode == CalculationMode.WHOLE_TRACK) {
editingCtx.clearSnappedToRoadPoints();
}
editingCtx.setCalculationMode(oldCalculationMode);
editingCtx.setInSnapToRoadMode(true);
editingCtx.setNeedUpdateCacheForSnap(true);
}
@Override
public void redo() {
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
if (pointIdx > 0) {
if (newMode != null) {
points.get(pointIdx).setProfileType(newMode.getStringKey());
} else {
points.get(pointIdx).removeProfileType();
}
}
editingCtx.setInSnapToRoadMode(true);
editingCtx.setCalculationMode(newCalculationMode);
editingCtx.setSnapToRoadAppMode(newMode);
if (newCalculationMode == CalculationMode.WHOLE_TRACK) {
editingCtx.clearSnappedToRoadPoints();
}
editingCtx.setNeedUpdateCacheForSnap(true);
}
@Override
MeasurementCommandType getType() {
return MeasurementCommandType.CHANGE_ROUTE_MODE;
}
}

View file

@ -18,6 +18,7 @@ public abstract class MeasurementModeCommand implements Command {
MOVE_POINT,
REMOVE_POINT,
REORDER_POINT,
SNAP_TO_ROAD
SNAP_TO_ROAD,
CHANGE_ROUTE_MODE
}
}