Add some refactoring
This commit is contained in:
parent
60bfd28830
commit
f09fe36214
9 changed files with 56 additions and 100 deletions
|
@ -27,12 +27,9 @@ public class MeasurementEditingContext {
|
||||||
private OsmandApplication application;
|
private OsmandApplication application;
|
||||||
private final MeasurementCommandManager commandManager = new MeasurementCommandManager();
|
private final MeasurementCommandManager commandManager = new MeasurementCommandManager();
|
||||||
|
|
||||||
private TrkSegment before = new TrkSegment();
|
private final TrkSegment before = new TrkSegment();
|
||||||
// cache should be deleted if before changed or snappedToRoadPoints
|
|
||||||
private TrkSegment beforeCacheForSnap;
|
private TrkSegment beforeCacheForSnap;
|
||||||
|
private final TrkSegment after = new TrkSegment();
|
||||||
private TrkSegment after = new TrkSegment();
|
|
||||||
// cache should be deleted if after changed or snappedToRoadPoints
|
|
||||||
private TrkSegment afterCacheForSnap;
|
private TrkSegment afterCacheForSnap;
|
||||||
|
|
||||||
private NewGpxData newGpxData;
|
private NewGpxData newGpxData;
|
||||||
|
@ -44,42 +41,42 @@ public class MeasurementEditingContext {
|
||||||
private SnapToRoadProgressListener progressListener;
|
private SnapToRoadProgressListener progressListener;
|
||||||
private ApplicationMode snapToRoadAppMode;
|
private ApplicationMode snapToRoadAppMode;
|
||||||
private RouteCalculationProgress calculationProgress;
|
private RouteCalculationProgress calculationProgress;
|
||||||
private Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new ConcurrentLinkedQueue<>();
|
private final Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new ConcurrentLinkedQueue<>();
|
||||||
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
|
private final Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public void setApplication(OsmandApplication application) {
|
public void setApplication(OsmandApplication application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MeasurementCommandManager getCommandManager() {
|
MeasurementCommandManager getCommandManager() {
|
||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSnapToRoadMode() {
|
boolean isInSnapToRoadMode() {
|
||||||
return inSnapToRoadMode;
|
return inSnapToRoadMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSelectedPointPosition() {
|
int getSelectedPointPosition() {
|
||||||
return selectedPointPosition;
|
return selectedPointPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedPointPosition(int selectedPointPosition) {
|
void setSelectedPointPosition(int selectedPointPosition) {
|
||||||
this.selectedPointPosition = selectedPointPosition;
|
this.selectedPointPosition = selectedPointPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WptPt getOriginalPointToMove() {
|
WptPt getOriginalPointToMove() {
|
||||||
return originalPointToMove;
|
return originalPointToMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOriginalPointToMove(WptPt originalPointToMove) {
|
void setOriginalPointToMove(WptPt originalPointToMove) {
|
||||||
this.originalPointToMove = originalPointToMove;
|
this.originalPointToMove = originalPointToMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
|
void setInSnapToRoadMode(boolean inSnapToRoadMode) {
|
||||||
this.inSnapToRoadMode = inSnapToRoadMode;
|
this.inSnapToRoadMode = inSnapToRoadMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NewGpxData getNewGpxData() {
|
NewGpxData getNewGpxData() {
|
||||||
return newGpxData;
|
return newGpxData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,30 +84,26 @@ public class MeasurementEditingContext {
|
||||||
this.newGpxData = newGpxData;
|
this.newGpxData = newGpxData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressListener(SnapToRoadProgressListener progressListener) {
|
void setProgressListener(SnapToRoadProgressListener progressListener) {
|
||||||
this.progressListener = progressListener;
|
this.progressListener = progressListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationMode getSnapToRoadAppMode() {
|
ApplicationMode getSnapToRoadAppMode() {
|
||||||
return snapToRoadAppMode;
|
return snapToRoadAppMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
|
void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
|
||||||
this.snapToRoadAppMode = snapToRoadAppMode;
|
this.snapToRoadAppMode = snapToRoadAppMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedPoints() {
|
TrkSegment getBeforeTrkSegmentLine() {
|
||||||
return snappedToRoadPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrkSegment getBeforeTrkSegmentLine() {
|
|
||||||
if (beforeCacheForSnap != null) {
|
if (beforeCacheForSnap != null) {
|
||||||
return beforeCacheForSnap;
|
return beforeCacheForSnap;
|
||||||
}
|
}
|
||||||
return before;
|
return before;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrkSegment getAfterTrkSegmentLine() {
|
TrkSegment getAfterTrkSegmentLine() {
|
||||||
if (afterCacheForSnap != null) {
|
if (afterCacheForSnap != null) {
|
||||||
return afterCacheForSnap;
|
return afterCacheForSnap;
|
||||||
}
|
}
|
||||||
|
@ -121,11 +114,11 @@ public class MeasurementEditingContext {
|
||||||
return getBeforePoints();
|
return getBeforePoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WptPt> getBeforePoints() {
|
List<WptPt> getBeforePoints() {
|
||||||
return before.points;
|
return before.points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WptPt> getAfterPoints() {
|
List<WptPt> getAfterPoints() {
|
||||||
return after.points;
|
return after.points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +126,7 @@ public class MeasurementEditingContext {
|
||||||
return before.points.size();
|
return before.points.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void splitSegments(int position) {
|
void splitSegments(int position) {
|
||||||
List<WptPt> points = new ArrayList<>();
|
List<WptPt> points = new ArrayList<>();
|
||||||
points.addAll(before.points);
|
points.addAll(before.points);
|
||||||
points.addAll(after.points);
|
points.addAll(after.points);
|
||||||
|
|
|
@ -48,6 +48,7 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.TrackActivity;
|
import net.osmand.plus.activities.TrackActivity;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
|
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
||||||
import net.osmand.plus.measurementtool.OptionsBottomSheetDialogFragment.OptionsFragmentListener;
|
import net.osmand.plus.measurementtool.OptionsBottomSheetDialogFragment.OptionsFragmentListener;
|
||||||
import net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener;
|
import net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener;
|
||||||
import net.osmand.plus.measurementtool.SelectedPointBottomSheetDialogFragment.SelectedPointFragmentListener;
|
import net.osmand.plus.measurementtool.SelectedPointBottomSheetDialogFragment.SelectedPointFragmentListener;
|
||||||
|
@ -60,7 +61,6 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
||||||
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||||
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||||
|
@ -115,7 +115,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
LINE
|
LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEditingCtx(MeasurementEditingContext editingCtx) {
|
private void setEditingCtx(MeasurementEditingContext editingCtx) {
|
||||||
this.editingCtx = editingCtx;
|
this.editingCtx = editingCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,9 +861,9 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private void addPointBeforeAfter() {
|
private void addPointBeforeAfter() {
|
||||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
if (measurementLayer != null) {
|
if (measurementLayer != null) {
|
||||||
int selectedPoint = editingCtx.getSelectedPointPosition(); //after = 1; before = 1;
|
int selectedPoint = editingCtx.getSelectedPointPosition(); // after = 1; before = 1;
|
||||||
int pointsCount = editingCtx.getPointsCount(); //after = 2; before = 1;
|
int pointsCount = editingCtx.getPointsCount(); // after = 2; before = 1;
|
||||||
if (addCenterPoint()) { //выбрать вторую точку
|
if (addCenterPoint()) { // select second point
|
||||||
if (selectedPoint == pointsCount) {
|
if (selectedPoint == pointsCount) {
|
||||||
editingCtx.splitSegments(editingCtx.getPointsCount() - 1);
|
editingCtx.splitSegments(editingCtx.getPointsCount() - 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,9 +41,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
private int marginPointIconY;
|
private int marginPointIconY;
|
||||||
private int marginApplyingPointIconX;
|
private int marginApplyingPointIconX;
|
||||||
private int marginApplyingPointIconY;
|
private int marginApplyingPointIconY;
|
||||||
private Path path = new Path();
|
private final Path path = new Path();
|
||||||
private TIntArrayList tx = new TIntArrayList();
|
private final TIntArrayList tx = new TIntArrayList();
|
||||||
private TIntArrayList ty = new TIntArrayList();
|
private final TIntArrayList ty = new TIntArrayList();
|
||||||
private OnMeasureDistanceToCenter measureDistanceToCenterListener;
|
private OnMeasureDistanceToCenter measureDistanceToCenterListener;
|
||||||
private OnSingleTapListener singleTapListener;
|
private OnSingleTapListener singleTapListener;
|
||||||
private OnEnterMovePointModeListener enterMovePointModeListener;
|
private OnEnterMovePointModeListener enterMovePointModeListener;
|
||||||
|
|
|
@ -4,7 +4,12 @@ import net.osmand.data.QuadRect;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
|
|
||||||
public class NewGpxData {
|
public class NewGpxData {
|
||||||
public enum ActionType { ADD_SEGMENT, ADD_ROUTE_POINTS, EDIT_SEGMENT }
|
|
||||||
|
public enum ActionType {
|
||||||
|
ADD_SEGMENT,
|
||||||
|
ADD_ROUTE_POINTS,
|
||||||
|
EDIT_SEGMENT
|
||||||
|
}
|
||||||
|
|
||||||
private GPXUtilities.GPXFile gpxFile;
|
private GPXUtilities.GPXFile gpxFile;
|
||||||
private GPXUtilities.TrkSegment trkSegment;
|
private GPXUtilities.TrkSegment trkSegment;
|
||||||
|
|
|
@ -18,7 +18,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
|
||||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.measurementtool.NewGpxData;
|
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -30,9 +30,9 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
||||||
private final List<WptPt> points;
|
private final List<WptPt> points;
|
||||||
private MeasurementAdapterListener listener;
|
private MeasurementAdapterListener listener;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
private NewGpxData.ActionType actionType;
|
private final ActionType actionType;
|
||||||
|
|
||||||
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points, NewGpxData.ActionType actionType) {
|
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points, ActionType actionType) {
|
||||||
this.mapActivity = mapActivity;
|
this.mapActivity = mapActivity;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.actionType = actionType;
|
this.actionType = actionType;
|
||||||
|
@ -77,14 +77,14 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
||||||
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point,
|
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point,
|
||||||
nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color));
|
nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color));
|
||||||
if (nightMode) {
|
if (nightMode) {
|
||||||
holder.title.setTextColor(mapActivity.getMyApplication().getResources().getColor(R.color.primary_text_dark));
|
holder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.primary_text_dark));
|
||||||
}
|
}
|
||||||
WptPt pt = points.get(pos);
|
WptPt pt = points.get(pos);
|
||||||
String pointTitle = pt.name;
|
String pointTitle = pt.name;
|
||||||
if (!TextUtils.isEmpty(pointTitle)) {
|
if (!TextUtils.isEmpty(pointTitle)) {
|
||||||
holder.title.setText(pointTitle);
|
holder.title.setText(pointTitle);
|
||||||
} else {
|
} else {
|
||||||
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
|
if (actionType == ActionType.ADD_ROUTE_POINTS) {
|
||||||
holder.title.setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
holder.title.setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
||||||
} else {
|
} else {
|
||||||
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||||
|
@ -105,7 +105,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
||||||
holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
|
if (actionType == ActionType.EDIT_SEGMENT) {
|
||||||
double elevation = pt.ele;
|
double elevation = pt.ele;
|
||||||
if (!Double.isNaN(elevation)) {
|
if (!Double.isNaN(elevation)) {
|
||||||
String eleStr = (mapActivity.getString(R.string.altitude)).substring(0, 1);
|
String eleStr = (mapActivity.getString(R.string.altitude)).substring(0, 1);
|
||||||
|
|
|
@ -7,7 +7,7 @@ public class AddPointCommand extends MeasurementModeCommand {
|
||||||
|
|
||||||
private final int position;
|
private final int position;
|
||||||
private WptPt point;
|
private WptPt point;
|
||||||
private boolean center;
|
private final boolean center;
|
||||||
|
|
||||||
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
|
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
|
||||||
this.measurementLayer = measurementLayer;
|
this.measurementLayer = measurementLayer;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.osmand.plus.measurementtool.command;
|
package net.osmand.plus.measurementtool.command;
|
||||||
|
|
||||||
public interface Command {
|
interface Command {
|
||||||
|
|
||||||
boolean execute();
|
boolean execute();
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package net.osmand.plus.measurementtool.command;
|
|
||||||
|
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
|
||||||
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SnapToRoadCommand extends MeasurementModeCommand {
|
|
||||||
|
|
||||||
private List<WptPt> snappedPoints;
|
|
||||||
|
|
||||||
public SnapToRoadCommand(MeasurementToolLayer measurementLayer, List<WptPt> points) {
|
|
||||||
this.measurementLayer = measurementLayer;
|
|
||||||
this.snappedPoints = points;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute() {
|
|
||||||
// measurementLayer.getSnappedToRoadPoints().clear();
|
|
||||||
// measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
|
|
||||||
// measurementLayer.refreshMap();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
// measurementLayer.getSnappedToRoadPoints().clear();
|
|
||||||
measurementLayer.refreshMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void redo() {
|
|
||||||
// measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
|
|
||||||
measurementLayer.refreshMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
MeasurementCommandType getType() {
|
|
||||||
return MeasurementCommandType.SNAP_TO_ROAD;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue