Merge pull request #9620 from osmandapp/fix_plan_route_option
Fix plan route option
This commit is contained in:
commit
6ce4c12842
7 changed files with 214 additions and 127 deletions
|
@ -317,10 +317,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,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.WHOLE_TRACK;
|
||||
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.*;
|
||||
|
||||
public class MeasurementEditingContext {
|
||||
|
||||
public enum CalculationType {
|
||||
public enum CalculationMode {
|
||||
NEXT_SEGMENT,
|
||||
WHOLE_TRACK
|
||||
}
|
||||
|
@ -57,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;
|
||||
|
@ -90,7 +89,7 @@ public class MeasurementEditingContext {
|
|||
updateCacheForSnapIfNeeded(true);
|
||||
}
|
||||
|
||||
int getSelectedPointPosition() {
|
||||
public int getSelectedPointPosition() {
|
||||
return selectedPointPosition;
|
||||
}
|
||||
|
||||
|
@ -130,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,16 +146,14 @@ public class MeasurementEditingContext {
|
|||
}
|
||||
|
||||
public void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
|
||||
if (this.snapToRoadAppMode != null && snapToRoadAppMode != null
|
||||
&& !this.snapToRoadAppMode.getStringKey().equals(snapToRoadAppMode.getStringKey())) {
|
||||
if (calculationType == WHOLE_TRACK) {
|
||||
snappedToRoadPoints.clear();
|
||||
updateCacheForSnapIfNeeded(true);
|
||||
}
|
||||
}
|
||||
this.snapToRoadAppMode = snapToRoadAppMode;
|
||||
}
|
||||
|
||||
public void clearSnappedToRoadPoints() {
|
||||
snappedToRoadPoints.clear();
|
||||
}
|
||||
|
||||
|
||||
TrkSegment getBeforeTrkSegmentLine() {
|
||||
if (beforeCacheForSnap != null) {
|
||||
return beforeCacheForSnap;
|
||||
|
@ -240,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;
|
||||
|
@ -424,9 +421,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() {
|
||||
|
@ -552,8 +563,14 @@ public class MeasurementEditingContext {
|
|||
params.start = start;
|
||||
params.end = end;
|
||||
params.intermediates = intermediates;
|
||||
RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
|
||||
params.mode = snapToRoadAppMode;
|
||||
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() {
|
||||
|
|
|
@ -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;
|
||||
|
@ -70,6 +69,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.ApplyGpxApproximationCommand;
|
||||
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
||||
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
||||
|
@ -94,7 +94,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
import static net.osmand.IndexConstants.GPX_FILE_EXT;
|
||||
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;
|
||||
|
@ -314,13 +314,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();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -331,13 +326,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();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -444,14 +434,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(),
|
||||
|
@ -467,6 +449,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) {
|
||||
|
@ -476,21 +468,30 @@ 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) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
editingCtx.getCommandManager().setMeasurementLayer(mapActivity.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);
|
||||
}
|
||||
}
|
||||
enableSnapToRoadMode(snapToRoadAppMode);
|
||||
ActionType actionType = newGpxData.getActionType();
|
||||
if (actionType == ActionType.ADD_ROUTE_POINTS) {
|
||||
displayRoutePoints();
|
||||
|
@ -606,7 +607,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
|
||||
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode()) {
|
||||
RouteBetweenPointsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
this, editingCtx.getCalculationType(),
|
||||
this, editingCtx.getCalculationMode(),
|
||||
editingCtx.getSnapToRoadAppMode());
|
||||
} else {
|
||||
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
|
||||
|
@ -738,9 +739,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
|
||||
@Override
|
||||
public void deleteOnClick() {
|
||||
if (measurementLayer != null) {
|
||||
removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
|
||||
}
|
||||
removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
|
||||
editingCtx.setSelectedPointPosition(-1);
|
||||
}
|
||||
|
||||
|
@ -792,21 +791,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
|
||||
|
@ -914,14 +909,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
return null;
|
||||
}
|
||||
|
||||
private void removePoint(MeasurementToolLayer layer, int position) {
|
||||
editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position));
|
||||
adapter.notifyDataSetChanged();
|
||||
updateUndoRedoButton(true, undoBtn);
|
||||
updateUndoRedoButton(false, redoBtn);
|
||||
updateDistancePointsText();
|
||||
saved = false;
|
||||
hidePointsListIfNoPoints();
|
||||
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);
|
||||
updateDistancePointsText();
|
||||
saved = false;
|
||||
hidePointsListIfNoPoints();
|
||||
}
|
||||
}
|
||||
|
||||
private SaveAsNewTrackFragmentListener createSaveAsNewTrackFragmentListener() {
|
||||
|
@ -948,9 +945,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
|
||||
@Override
|
||||
public void onRemoveClick(int position) {
|
||||
if (measurementLayer != null) {
|
||||
removePoint(measurementLayer, position);
|
||||
}
|
||||
removePoint(measurementLayer, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -994,10 +989,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) {
|
||||
|
@ -1008,15 +1003,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();
|
||||
}
|
||||
}
|
||||
|
@ -1089,7 +1076,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1188,14 +1175,14 @@ 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,
|
||||
R.id.move_point_controls);
|
||||
mainIcon.setImageDrawable(getActiveIcon(enable
|
||||
? R.drawable.ic_action_move_point
|
||||
: R.drawable.ic_action_ruler));
|
||||
}
|
||||
markGeneralComponents(enable ? View.GONE : View.VISIBLE);
|
||||
AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE,
|
||||
R.id.move_point_text,
|
||||
R.id.move_point_controls);
|
||||
mainIcon.setImageDrawable(getActiveIcon(enable
|
||||
? R.drawable.ic_action_move_point
|
||||
: R.drawable.ic_action_ruler));
|
||||
}
|
||||
|
||||
private void switchAddPointBeforeAfterMode(boolean enable) {
|
||||
|
@ -1208,13 +1195,13 @@ 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.add_point_before_after_text,
|
||||
R.id.add_point_before_after_controls);
|
||||
if (!enable) {
|
||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
|
||||
markGeneralComponents(enable ? View.GONE : View.VISIBLE);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1901,7 +1888,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (pointsListOpened) {
|
||||
hidePointsList();
|
||||
}
|
||||
showSnapToRoadControls();
|
||||
updateSnapToRoadControls();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1913,6 +1900,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
@Override
|
||||
public void onCancelGpxApproximation() {
|
||||
editingCtx.getCommandManager().undo();
|
||||
showSnapToRoadControls();
|
||||
updateSnapToRoadControls();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,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();
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
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) {
|
||||
super(measurementLayer);
|
||||
this.newMode = newMode;
|
||||
this.newCalculationMode = newCalculationMode;
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
oldMode = editingCtx.getSnapToRoadAppMode();
|
||||
oldCalculationMode = editingCtx.getCalculationMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
points = new LinkedList<>(editingCtx.getPoints());
|
||||
pointIdx = points.size() - 1;
|
||||
executeCommand();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MeasurementEditingContext editingCtx = 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() {
|
||||
executeCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
MeasurementCommandType getType() {
|
||||
return MeasurementCommandType.CHANGE_ROUTE_MODE;
|
||||
}
|
||||
|
||||
private void executeCommand() {
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
if (pointIdx > 0 && newCalculationMode != CalculationMode.WHOLE_TRACK) {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ public abstract class MeasurementModeCommand implements Command {
|
|||
REMOVE_POINT,
|
||||
REORDER_POINT,
|
||||
SNAP_TO_ROAD,
|
||||
CHANGE_ROUTE_MODE,
|
||||
APPROXIMATE_POINTS
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue