diff --git a/OsmAnd/res/layout-land/fragment_measurement_tool.xml b/OsmAnd/res/layout-land/fragment_measurement_tool.xml
index c67868f0a9..c211f3148c 100644
--- a/OsmAnd/res/layout-land/fragment_measurement_tool.xml
+++ b/OsmAnd/res/layout-land/fragment_measurement_tool.xml
@@ -121,7 +121,7 @@
android:visibility="gone"/>
-
-
diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml
index 0e0feba970..c1977ac715 100644
--- a/OsmAnd/res/layout/fragment_measurement_tool.xml
+++ b/OsmAnd/res/layout/fragment_measurement_tool.xml
@@ -116,7 +116,7 @@
android:visibility="gone"/>
-
-
diff --git a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml
index 03138ed207..2c16bb4079 100644
--- a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml
+++ b/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml
@@ -52,15 +52,42 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Point 2"/>
-
+ android:layout_height="wrap_content">
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index d0c1793fdf..29df34dfbd 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -9,8 +9,6 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
- Altitude: %1$s
- Speed: %1$s
Line
Save as route points
Save as line
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index 4574a0892e..9feb1be7e1 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -95,6 +95,7 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
+import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.render.RendererRegistry;
@@ -944,7 +945,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
NewGpxData newGpxData = (NewGpxData) toShow;
QuadRect qr = newGpxData.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
- MeasurementToolFragment.showInstance(getSupportFragmentManager(), newGpxData);
+ MeasurementEditingContext editingContext = new MeasurementEditingContext();
+ editingContext.setNewGpxData(newGpxData);
+ MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
} else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index 094a7d1179..cebfc913d3 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -764,7 +764,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) {
- MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), null);
+ MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager());
return true;
}
}).createItem());
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java
new file mode 100644
index 0000000000..415d9716f6
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java
@@ -0,0 +1,315 @@
+package net.osmand.plus.measurementtool;
+
+import android.util.Pair;
+
+import net.osmand.Location;
+import net.osmand.data.LatLon;
+import net.osmand.plus.ApplicationMode;
+import net.osmand.plus.GPXUtilities.TrkSegment;
+import net.osmand.plus.GPXUtilities.WptPt;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandSettings;
+import net.osmand.plus.measurementtool.command.MeasurementCommandManager;
+import net.osmand.plus.routing.RouteCalculationParams;
+import net.osmand.plus.routing.RoutingHelper;
+import net.osmand.router.RouteCalculationProgress;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+public class MeasurementEditingContext {
+
+ private OsmandApplication application;
+ private final MeasurementCommandManager commandManager = new MeasurementCommandManager();
+
+ private TrkSegment before = new TrkSegment();
+ // cache should be deleted if before changed or snappedToRoadPoints
+ private TrkSegment beforeCacheForSnap;
+
+ private TrkSegment after = new TrkSegment();
+ // cache should be deleted if after changed or snappedToRoadPoints
+ private TrkSegment afterCacheForSnap;
+
+ private NewGpxData newGpxData;
+
+ private int selectedPointPosition = -1;
+ private WptPt originalPointToMove;
+
+ private boolean inSnapToRoadMode;
+ private SnapToRoadProgressListener progressListener;
+ private ApplicationMode snapToRoadAppMode;
+ private RouteCalculationProgress calculationProgress;
+ private Queue> snapToRoadPairsToCalculate = new ConcurrentLinkedQueue<>();
+ private Map, List> snappedToRoadPoints = new ConcurrentHashMap<>();
+
+ public void setApplication(OsmandApplication application) {
+ this.application = application;
+ }
+
+ public MeasurementCommandManager getCommandManager() {
+ return commandManager;
+ }
+
+ public boolean isInSnapToRoadMode() {
+ return inSnapToRoadMode;
+ }
+
+ public int getSelectedPointPosition() {
+ return selectedPointPosition;
+ }
+
+ public void setSelectedPointPosition(int selectedPointPosition) {
+ this.selectedPointPosition = selectedPointPosition;
+ }
+
+ public WptPt getOriginalPointToMove() {
+ return originalPointToMove;
+ }
+
+ public void setOriginalPointToMove(WptPt originalPointToMove) {
+ this.originalPointToMove = originalPointToMove;
+ }
+
+ public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
+ this.inSnapToRoadMode = inSnapToRoadMode;
+ }
+
+ public NewGpxData getNewGpxData() {
+ return newGpxData;
+ }
+
+ public void setNewGpxData(NewGpxData newGpxData) {
+ this.newGpxData = newGpxData;
+ }
+
+ public void setProgressListener(SnapToRoadProgressListener progressListener) {
+ this.progressListener = progressListener;
+ }
+
+ public ApplicationMode getSnapToRoadAppMode() {
+ return snapToRoadAppMode;
+ }
+
+ public void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
+ this.snapToRoadAppMode = snapToRoadAppMode;
+ }
+
+ public Map, List> getSnappedPoints() {
+ return snappedToRoadPoints;
+ }
+
+ public TrkSegment getBeforeTrkSegmentLine() {
+ if (beforeCacheForSnap != null) {
+ return beforeCacheForSnap;
+ }
+ return before;
+ }
+
+ public TrkSegment getAfterTrkSegmentLine() {
+ if (afterCacheForSnap != null) {
+ return afterCacheForSnap;
+ }
+ return after;
+ }
+
+ public List getPoints() {
+ return getBeforePoints();
+ }
+
+ public List getBeforePoints() {
+ return before.points;
+ }
+
+ public List getAfterPoints() {
+ return after.points;
+ }
+
+ public int getPointsCount() {
+ return before.points.size();
+ }
+
+ public void splitSegments(int position) {
+ List points = new ArrayList<>();
+ points.addAll(before.points);
+ points.addAll(after.points);
+ before.points.clear();
+ after.points.clear();
+ before.points.addAll(points.subList(0, position));
+ after.points.addAll(points.subList(position, points.size()));
+ updateCacheForSnapIfNeeded(true);
+ }
+
+ public void addPoint(WptPt pt) {
+ before.points.add(pt);
+ updateCacheForSnapIfNeeded(false);
+ }
+
+ public void addPoint(int position, WptPt pt) {
+ before.points.add(position, pt);
+ updateCacheForSnapIfNeeded(false);
+ }
+
+ public void addPoints(List points) {
+ before.points.addAll(points);
+ updateCacheForSnapIfNeeded(false);
+ }
+
+ public WptPt removePoint(int position) {
+ WptPt pt = before.points.remove(position);
+ updateCacheForSnapIfNeeded(false);
+ return pt;
+ }
+
+ public void clearSegments() {
+ before.points.clear();
+ after.points.clear();
+ beforeCacheForSnap = null;
+ afterCacheForSnap = null;
+ }
+
+ void scheduleRouteCalculateIfNotEmpty() {
+ if (application == null || (before.points.size() < 1 && after.points.size() < 1)) {
+ return;
+ }
+ snapToRoadPairsToCalculate.clear();
+ findPointsToCalculate(Arrays.asList(before.points, after.points));
+ RoutingHelper routingHelper = application.getRoutingHelper();
+ if (!snapToRoadPairsToCalculate.isEmpty() && progressListener != null && !routingHelper.isRouteBeingCalculated()) {
+ routingHelper.startRouteCalculationThread(getParams(), true, true);
+ application.runInUIThread(new Runnable() {
+ @Override
+ public void run() {
+ progressListener.showProgressBar();
+ }
+ });
+ }
+ }
+
+ private void findPointsToCalculate(List> pointsList) {
+ for (List points : pointsList) {
+ for (int i = 0; i < points.size() - 1; i++) {
+ Pair pair = new Pair<>(points.get(i), points.get(i + 1));
+ if (snappedToRoadPoints.get(pair) == null) {
+ snapToRoadPairsToCalculate.add(pair);
+ }
+ }
+ }
+ }
+
+ private void recreateCacheForSnap(TrkSegment cache, TrkSegment original) {
+ if (original.points.size() > 1) {
+ for (int i = 0; i < original.points.size() - 1; i++) {
+ Pair pair = new Pair<>(original.points.get(i), original.points.get(i + 1));
+ List pts = snappedToRoadPoints.get(pair);
+ if (pts != null) {
+ cache.points.addAll(pts);
+ } else {
+ if (inSnapToRoadMode) {
+ scheduleRouteCalculateIfNotEmpty();
+ }
+ cache.points.addAll(Arrays.asList(pair.first, pair.second));
+ }
+ }
+ } else {
+ cache.points.addAll(original.points);
+ }
+ }
+
+ private void updateCacheForSnapIfNeeded(boolean both) {
+ if (inSnapToRoadMode) {
+ recreateCacheForSnap(beforeCacheForSnap = new TrkSegment(), before);
+ if (both) {
+ recreateCacheForSnap(afterCacheForSnap = new TrkSegment(), after);
+ }
+ }
+ }
+
+ void cancelSnapToRoad() {
+ progressListener.hideProgressBar();
+ snapToRoadPairsToCalculate.clear();
+ if (calculationProgress != null) {
+ calculationProgress.isCancelled = true;
+ }
+ }
+
+ private RouteCalculationParams getParams() {
+ OsmandSettings settings = application.getSettings();
+
+ final Pair currentPair = snapToRoadPairsToCalculate.poll();
+
+ Location start = new Location("");
+ start.setLatitude(currentPair.first.getLatitude());
+ start.setLongitude(currentPair.first.getLongitude());
+
+ LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
+
+ final RouteCalculationParams params = new RouteCalculationParams();
+ params.start = start;
+ params.end = end;
+ params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
+ params.fast = settings.FAST_ROUTE_MODE.getModeValue(snapToRoadAppMode);
+ params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
+ params.mode = snapToRoadAppMode;
+ params.ctx = application;
+ params.calculationProgress = calculationProgress = new RouteCalculationProgress();
+ params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
+ @Override
+ public void updateProgress(int progress) {
+ progressListener.updateProgress(progress);
+ }
+
+ @Override
+ public void requestPrivateAccessRouting() {
+
+ }
+
+ @Override
+ public void finish() {
+ progressListener.refreshMap();
+ }
+ };
+ params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {
+ @Override
+ public void onRouteCalculated(List locations) {
+ ArrayList pts = new ArrayList<>(locations.size());
+ for (Location loc : locations) {
+ WptPt pt = new WptPt();
+ pt.lat = loc.getLatitude();
+ pt.lon = loc.getLongitude();
+ pts.add(pt);
+ }
+ snappedToRoadPoints.put(currentPair, pts);
+ updateCacheForSnapIfNeeded(true);
+ progressListener.refreshMap();
+ if (!snapToRoadPairsToCalculate.isEmpty()) {
+ application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
+ } else {
+ application.runInUIThread(new Runnable() {
+ @Override
+ public void run() {
+ progressListener.hideProgressBar();
+ }
+ });
+ }
+ }
+ };
+
+ return params;
+ }
+
+ interface SnapToRoadProgressListener {
+
+ void showProgressBar();
+
+ void updateProgress(int progress);
+
+ void hideProgressBar();
+
+ void refreshMap();
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
index dfb3878c7f..4be247dd9c 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
@@ -33,8 +33,6 @@ import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
-import net.osmand.Location;
-import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
@@ -59,25 +57,18 @@ import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.Measuremen
import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback;
import net.osmand.plus.measurementtool.command.AddPointCommand;
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
-import net.osmand.plus.measurementtool.command.MeasurementCommandManager;
-import net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType;
import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
-import net.osmand.plus.measurementtool.command.SnapToRoadCommand;
-import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
-import net.osmand.plus.routing.RoutingHelper;
+import net.osmand.plus.measurementtool.NewGpxData.ActionType;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
-import net.osmand.router.RouteCalculationProgress;
import java.io.File;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -89,9 +80,6 @@ public class MeasurementToolFragment extends Fragment {
public static final String TAG = "MeasurementToolFragment";
- private final MeasurementCommandManager commandManager = new MeasurementCommandManager();
- private List measurementPoints = new LinkedList<>();
- private List snappedToRoadPoints = new LinkedList<>();
private IconsCache iconsCache;
private RecyclerView pointsRv;
private String previousToolBarTitle = "";
@@ -110,36 +98,25 @@ public class MeasurementToolFragment extends Fragment {
private ImageView undoBtn;
private ImageView redoBtn;
private ImageView mainIcon;
- private ProgressBar snapToRoadProgressBar;
- private RouteCalculationProgress calculationProgress;
private boolean wasCollapseButtonVisible;
+ private boolean progressBarVisible;
private boolean pointsListOpened;
private Boolean saved;
private boolean portrait;
private boolean nightMode;
private int previousMapPosition;
- private NewGpxData newGpxData;
private boolean gpxPointsAdded;
- private ApplicationMode snapToRoadAppMode;
- private boolean inMovePointMode;
- private boolean inAddPointAfterMode;
- private boolean inAddPointBeforeMode;
- private boolean isInSnapToRoadMode;
-
- private int selectedPointPos = -1;
- private WptPt selectedCachedPoint;
-
- private int positionToAddPoint = -1;
+ private MeasurementEditingContext editingCtx = new MeasurementEditingContext();
private enum SaveType {
ROUTE_POINT,
LINE
}
- public void setNewGpxData(NewGpxData newGpxData) {
- this.newGpxData = newGpxData;
+ public void setEditingCtx(MeasurementEditingContext editingCtx) {
+ this.editingCtx = editingCtx;
}
@Nullable
@@ -148,19 +125,37 @@ public class MeasurementToolFragment extends Fragment {
final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
- measurementLayer.setMeasurementPoints(measurementPoints);
- measurementLayer.setSnappedToRoadPoints(snappedToRoadPoints);
- if (selectedPointPos != -1 && selectedCachedPoint != null) {
- measurementLayer.setSelectedPointPos(selectedPointPos);
- measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
- }
+ editingCtx.setApplication(mapActivity.getMyApplication());
+ editingCtx.setProgressListener(new MeasurementEditingContext.SnapToRoadProgressListener() {
+ @Override
+ public void showProgressBar() {
+ MeasurementToolFragment.this.showProgressBar();
+ }
+
+ @Override
+ public void updateProgress(int progress) {
+ ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
+ }
+
+ @Override
+ public void hideProgressBar() {
+ ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE);
+ progressBarVisible = false;
+ }
+
+ @Override
+ public void refreshMap() {
+ measurementLayer.refreshMap();
+ }
+ });
+
+ measurementLayer.setEditingCtx(editingCtx);
// Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
if (selectedPointFragment != null) {
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
- fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
fragment.setListener(createSelectedPointFragmentListener());
}
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
@@ -181,7 +176,7 @@ public class MeasurementToolFragment extends Fragment {
hidePointsListFragment();
}
- commandManager.resetMeasurementLayer(measurementLayer);
+ editingCtx.getCommandManager().resetMeasurementLayer(measurementLayer);
iconsCache = mapActivity.getMyApplication().getIconsCache();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@@ -202,14 +197,19 @@ public class MeasurementToolFragment extends Fragment {
pointsListContainer.setBackgroundColor(backgroundColor);
}
+ if (progressBarVisible) {
+ showProgressBar();
+ }
+
distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
- if (newGpxData != null) {
- NewGpxData.ActionType actionType = newGpxData.getActionType();
- if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
+ final NewGpxData newGpxData = editingCtx.getNewGpxData();
+ if (editingCtx.getNewGpxData() != null) {
+ ActionType actionType = newGpxData.getActionType();
+ if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
} else {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
@@ -224,20 +224,14 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (inMovePointMode) {
- cancelMovePointMode();
- }
+ cancelMovePointMode();
}
});
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (inAddPointAfterMode) {
- cancelAddPointAfterMode();
- } else if (inAddPointBeforeMode) {
- cancelAddPointBeforeMode();
- }
+ cancelAddPointBeforeOrAfterMode();
}
});
@@ -245,11 +239,7 @@ public class MeasurementToolFragment extends Fragment {
upDownRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (!pointsListOpened
- && measurementPoints.size() > 0
- && !measurementLayer.isInMovePointMode()
- && !measurementLayer.isInAddPointAfterMode()
- && !measurementLayer.isInAddPointBeforeMode()) {
+ if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
showPointsList();
} else {
hidePointsList();
@@ -260,31 +250,21 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (inMovePointMode) {
- applyMovePointMode();
- }
+ applyMovePointMode();
}
});
mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (inAddPointAfterMode) {
- applyAddPointAfterMode();
- } else if (inAddPointBeforeMode) {
- applyAddPointBeforeMode();
- }
+ applyAddPointBeforeAfterMode();
}
});
mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (inAddPointAfterMode) {
- addPointAfter();
- } else if (inAddPointBeforeMode) {
- addPointBefore();
- }
+ addPointBeforeAfter();
}
});
@@ -292,7 +272,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onClick(View view) {
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
- fragment.setSnapToRoadEnabled(isInSnapToRoadMode);
+ fragment.setSnapToRoadEnabled(editingCtx.isInSnapToRoadMode());
fragment.setListener(createOptionsFragmentListener());
fragment.setAddLineMode(newGpxData != null);
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
@@ -306,17 +286,14 @@ public class MeasurementToolFragment extends Fragment {
undoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- MeasurementCommandType type = commandManager.undo();
- if (type != null && type != MeasurementCommandType.SNAP_TO_ROAD) {
- recalculateSnapToRoadIfNedeed();
- }
- if (commandManager.canUndo()) {
+ editingCtx.getCommandManager().undo();
+ if (editingCtx.getCommandManager().canUndo()) {
enable(undoBtn);
} else {
disable(undoBtn);
}
hidePointsListIfNoPoints();
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
@@ -329,15 +306,14 @@ public class MeasurementToolFragment extends Fragment {
redoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- commandManager.redo();
- recalculateSnapToRoadIfNedeed();
- if (commandManager.canRedo()) {
+ editingCtx.getCommandManager().redo();
+ if (editingCtx.getCommandManager().canRedo()) {
enable(redoBtn);
} else {
disable(redoBtn);
}
hidePointsListIfNoPoints();
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
@@ -360,13 +336,11 @@ public class MeasurementToolFragment extends Fragment {
}
@Override
- public void onSelectPoint(int selectedPointPos, WptPt selectedCachedPoint) {
+ public void onSelectPoint(int selectedPointPos) {
if (pointsListOpened) {
hidePointsList();
}
- MeasurementToolFragment.this.selectedPointPos = selectedPointPos;
- MeasurementToolFragment.this.selectedCachedPoint = selectedCachedPoint;
- if (selectedPointPos != -1 && selectedCachedPoint != null) {
+ if (selectedPointPos != -1) {
openSelectedPointMenu(mapActivity);
}
}
@@ -390,18 +364,18 @@ public class MeasurementToolFragment extends Fragment {
}
});
- if (!commandManager.canUndo()) {
+ if (!editingCtx.getCommandManager().canUndo()) {
disable(undoBtn);
}
- if (!commandManager.canRedo()) {
+ if (!editingCtx.getCommandManager().canRedo()) {
disable(redoBtn);
}
- if (measurementPoints.size() < 1) {
+ if (editingCtx.getPointsCount() < 1) {
disable(upDownBtn);
}
toolBarController = new MeasurementToolBarController(newGpxData);
- if (inMovePointMode || inAddPointAfterMode || inAddPointBeforeMode) {
+ if (editingCtx.getSelectedPointPosition() != -1) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@@ -427,7 +401,7 @@ public class MeasurementToolFragment extends Fragment {
toolBarController.setOnSaveViewClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
addToGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@@ -444,7 +418,7 @@ public class MeasurementToolFragment extends Fragment {
});
mapActivity.showTopToolbar(toolBarController);
- adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints(),
+ adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(),
newGpxData != null ? newGpxData.getActionType() : null);
if (portrait) {
pointsRv = mainView.findViewById(R.id.measure_points_recycler_view);
@@ -459,8 +433,8 @@ public class MeasurementToolFragment extends Fragment {
enterMeasurementMode();
- if (isInSnapToRoadMode) {
- enableSnapToRoadMode(true);
+ if (editingCtx.isInSnapToRoadMode()) {
+ showSnapToRoadControls();
}
if (newGpxData != null && !gpxPointsAdded) {
@@ -481,15 +455,6 @@ public class MeasurementToolFragment extends Fragment {
return view;
}
- private void recalculateSnapToRoadIfNedeed() {
- if (calculationProgress != null) {
- calculationProgress.isCancelled = true;
- }
- if (isInSnapToRoadMode) {
- doSnapToRoad();
- }
- }
-
@Override
public void onDestroyView() {
super.onDestroyView();
@@ -498,20 +463,16 @@ public class MeasurementToolFragment extends Fragment {
if (pointsListOpened) {
hidePointsList();
}
- if (inMovePointMode) {
+ if (editingCtx.getOriginalPointToMove() != null) {
switchMovePointMode(false);
- }
- if (inAddPointAfterMode) {
- switchAddPointAfterMode(false);
- }
- if (inAddPointBeforeMode) {
- switchAddPointBeforeMode(false);
+ } else if (editingCtx.getSelectedPointPosition() != -1) {
+ switchAddPointBeforeAfterMode(false);
}
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
- layer.exitMovePointMode();
- layer.exitAddPointAfterMode();
- layer.exitAddPointBeforeMode();
+ if (editingCtx.getOriginalPointToMove() != null) {
+ layer.exitMovePointMode(true);
+ }
layer.setOnSingleTapListener(null);
layer.setOnEnterMovePointModeListener(null);
}
@@ -537,6 +498,14 @@ public class MeasurementToolFragment extends Fragment {
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
}
+ private void showProgressBar() {
+ ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
+ progressBar.setVisibility(View.VISIBLE);
+ progressBar.setMinimumHeight(0);
+ progressBar.setProgress(0);
+ progressBarVisible = true;
+ }
+
private void showSnapToRoadMenu(boolean rememberPreviousTitle) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@@ -559,7 +528,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void snapToRoadOnCLick() {
- if (!isInSnapToRoadMode) {
+ if (!editingCtx.isInSnapToRoadMode()) {
showSnapToRoadMenu(true);
} else {
disableSnapToRoadMode();
@@ -569,7 +538,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void addToGpxOnClick() {
if (mapActivity != null && measurementLayer != null) {
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
addToGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@@ -580,7 +549,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void saveAsNewTrackOnClick() {
if (mapActivity != null && measurementLayer != null) {
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
openSaveAsNewTrackMenu(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@@ -591,7 +560,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void addToTheTrackOnClick() {
if (mapActivity != null && measurementLayer != null) {
- if (measurementPoints.size() > 0) {
+ if (editingCtx.getPointsCount() > 0) {
showAddToTrackDialog(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@@ -601,10 +570,8 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void clearAllOnClick() {
- commandManager.execute(new ClearPointsCommand(measurementLayer));
- if (calculationProgress != null) {
- calculationProgress.isCancelled = true;
- }
+ editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer));
+ editingCtx.cancelSnapToRoad();
if (pointsListOpened) {
hidePointsList();
}
@@ -630,35 +597,43 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void deleteOnClick() {
- clearSelection();
if (measurementLayer != null) {
- removePoint(measurementLayer, measurementLayer.getSelectedPointPos());
- measurementLayer.clearSelection();
+ removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
}
+ editingCtx.setSelectedPointPosition(-1);
}
@Override
public void addPointAfterOnClick() {
if (measurementLayer != null) {
- positionToAddPoint = measurementLayer.getSelectedPointPos() + 1;
- measurementLayer.enterAddingPointAfterMode();
+ measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
+ editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1);
}
- switchAddPointAfterMode(true);
+ ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after));
+ mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_above));
+ switchAddPointBeforeAfterMode(true);
}
@Override
public void addPointBeforeOnClick() {
if (measurementLayer != null) {
- positionToAddPoint = measurementLayer.getSelectedPointPos();
- measurementLayer.enterAddingPointBeforeMode();
+ measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
+ editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
}
- switchAddPointBeforeMode(true);
+ ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before));
+ mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_below));
+ switchAddPointBeforeAfterMode(true);
}
@Override
public void onCloseMenu() {
setPreviousMapPosition();
}
+
+ @Override
+ public void onClearSelection() {
+ editingCtx.setSelectedPointPosition(-1);
+ }
};
}
@@ -677,15 +652,13 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onApplicationModeItemClick(ApplicationMode mode) {
- snapToRoadAppMode = mode;
- enableSnapToRoadMode(false);
+ enableSnapToRoadMode(mode);
}
};
}
private void removePoint(MeasurementToolLayer layer, int position) {
- commandManager.execute(new RemovePointCommand(layer, position));
- recalculateSnapToRoadIfNedeed();
+ editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position));
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
@@ -725,7 +698,6 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onItemClick(View view) {
if (mapActivity != null && measurementLayer != null) {
- clearSelection();
int position = pointsRv.indexOfChild(view);
if (pointsListOpened) {
hidePointsList();
@@ -752,8 +724,7 @@ public class MeasurementToolFragment extends Fragment {
if (mapActivity != null && measurementLayer != null) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
- commandManager.execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
- recalculateSnapToRoadIfNedeed();
+ editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
@@ -765,112 +736,42 @@ public class MeasurementToolFragment extends Fragment {
};
}
- private void enableSnapToRoadMode(boolean enableAfterRotating) {
- if (snapToRoadAppMode != null) {
- toolBarController.setTopBarSwitchVisible(true);
- toolBarController.setTopBarSwitchChecked(true);
- isInSnapToRoadMode = true;
- mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
- final MapActivity mapActivity = getMapActivity();
- if (mapActivity != null) {
- 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(getActiveIcon(snapToRoadAppMode.getSmallIconDark()));
- snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- showSnapToRoadMenu(false);
- }
- });
- snapToRoadBtn.setVisibility(View.VISIBLE);
-
- snapToRoadProgressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
- snapToRoadProgressBar.setMinimumHeight(0);
-
- if (!enableAfterRotating) {
- snapToRoadProgressBar.setProgress(0);
- doSnapToRoad();
- }
-
- mapActivity.refreshMap();
- }
- }
+ private void enableSnapToRoadMode(ApplicationMode appMode) {
+ editingCtx.setSnapToRoadAppMode(appMode);
+ editingCtx.setInSnapToRoadMode(true);
+ editingCtx.scheduleRouteCalculateIfNotEmpty();
+ showSnapToRoadControls();
}
- private void doSnapToRoad() {
- MapActivity mapActivity = getMapActivity();
- if (mapActivity != null && measurementPoints.size() > 1) {
- Location start = new Location("");
- WptPt first = measurementPoints.get(0);
- start.setLatitude(first.getLatitude());
- start.setLongitude(first.getLongitude());
+ private void showSnapToRoadControls() {
+ final MapActivity mapActivity = getMapActivity();
+ final ApplicationMode appMode = editingCtx.getSnapToRoadAppMode();
+ if (mapActivity != null && appMode != null) {
+ toolBarController.setTopBarSwitchVisible(true);
+ toolBarController.setTopBarSwitchChecked(true);
+ mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
- WptPt last = measurementPoints.get(measurementPoints.size() - 1);
- LatLon end = new LatLon(last.getLatitude(), last.getLongitude());
-
- List intermediates = new ArrayList<>();
- if (measurementPoints.size() > 2) {
- for (int i = 1; i < measurementPoints.size() - 1; i++) {
- WptPt pt = measurementPoints.get(i);
- intermediates.add(new LatLon(pt.getLatitude(), pt.getLongitude()));
- }
- }
-
- final SnapToRoadParams params = new SnapToRoadParams();
- params.applicationMode = snapToRoadAppMode;
- params.calculationProgress = calculationProgress = new RouteCalculationProgress();
- params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
+ 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(getActiveIcon(appMode.getSmallIconDark()));
+ snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
@Override
- public void updateProgress(int progress) {
- snapToRoadProgressBar.setProgress(progress);
+ public void onClick(View view) {
+ showSnapToRoadMenu(false);
}
+ });
+ snapToRoadBtn.setVisibility(View.VISIBLE);
- @Override
- public void requestPrivateAccessRouting() {
-
- }
-
- @Override
- public void finish() {
- snapToRoadProgressBar.setVisibility(View.GONE);
- MapActivity mapActivity = getMapActivity();
- if (mapActivity != null) {
- mapActivity.refreshMap();
- }
- }
- };
- params.listener = new SnapToRoadParams.SnapToRoadListener() {
- @Override
- public void onSnapToRoadDone() {
- ArrayList pts = new ArrayList<>(params.points.size());
- for (Location loc : params.points) {
- WptPt pt = new WptPt();
- pt.lat = loc.getLatitude();
- pt.lon = loc.getLongitude();
- pts.add(pt);
- }
- MeasurementToolLayer layer = getMeasurementLayer();
- if (layer != null) {
- commandManager.execute(new SnapToRoadCommand(layer, pts));
- }
- }
- };
- snapToRoadProgressBar.setVisibility(View.VISIBLE);
-
- mapActivity.getMyApplication().getRoutingHelper().recalculateSnapToRoad(start, end, intermediates, params);
- } else if (calculationProgress != null) {
- calculationProgress.isCancelled = true;
+ mapActivity.refreshMap();
}
}
private void disableSnapToRoadMode() {
toolBarController.setTopBarSwitchVisible(false);
toolBarController.setTitle(previousToolBarTitle);
- isInSnapToRoadMode = false;
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
- if (calculationProgress != null) {
- calculationProgress.isCancelled = true;
- }
+ editingCtx.setInSnapToRoadMode(false);
+ editingCtx.cancelSnapToRoad();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
@@ -882,10 +783,10 @@ public class MeasurementToolFragment extends Fragment {
private void displayRoutePoints() {
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
- GPXFile gpx = newGpxData.getGpxFile();
+ GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
List points = gpx.getRoutePoints();
if (measurementLayer != null) {
- measurementPoints.addAll(points);
+ editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
@@ -894,10 +795,10 @@ public class MeasurementToolFragment extends Fragment {
private void displaySegmentPoints() {
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
- TrkSegment segment = newGpxData.getTrkSegment();
+ TrkSegment segment = editingCtx.getNewGpxData().getTrkSegment();
List points = segment.points;
if (measurementLayer != null) {
- measurementPoints.addAll(points);
+ editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
@@ -905,7 +806,6 @@ public class MeasurementToolFragment extends Fragment {
private void openSelectedPointMenu(MapActivity mapActivity) {
SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment();
- fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
fragment.setListener(createSelectedPointFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG);
}
@@ -935,126 +835,68 @@ public class MeasurementToolFragment extends Fragment {
}
private void applyMovePointMode() {
- if (inMovePointMode) {
- switchMovePointMode(false);
- }
- clearSelection();
+ switchMovePointMode(false);
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
WptPt newPoint = measurementLayer.getMovedPointToApply();
- WptPt oldPoint = measurementLayer.getSelectedCachedPoint();
- int position = measurementLayer.getSelectedPointPos();
- commandManager.execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
+ WptPt oldPoint = editingCtx.getOriginalPointToMove();
+ int position = editingCtx.getSelectedPointPosition();
+ editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
+ editingCtx.addPoint(newPoint);
+ measurementLayer.exitMovePointMode(false);
doAddOrMovePointCommonStuff();
- measurementLayer.exitMovePointMode();
- measurementLayer.clearSelection();
measurementLayer.refreshMap();
}
}
private void cancelMovePointMode() {
- if (inMovePointMode) {
- switchMovePointMode(false);
- }
- clearSelection();
+ switchMovePointMode(false);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
- measurementToolLayer.exitMovePointMode();
- measurementToolLayer.clearSelection();
+ measurementToolLayer.exitMovePointMode(true);
measurementToolLayer.refreshMap();
}
}
- private void addPointAfter() {
- MeasurementToolLayer measurementLayer = getMeasurementLayer();
- if (measurementLayer != null && positionToAddPoint != -1) {
- if (addPointToPosition(positionToAddPoint)) {
- selectedPointPos += 1;
- selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
- measurementLayer.setSelectedPointPos(selectedPointPos);
- measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
- measurementLayer.refreshMap();
- positionToAddPoint += 1;
- }
- }
- }
-
- private void applyAddPointAfterMode() {
- if (inAddPointAfterMode) {
- switchAddPointAfterMode(false);
- }
- clearSelection();
+ private void addPointBeforeAfter() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
- measurementLayer.exitAddPointAfterMode();
- measurementLayer.clearSelection();
- measurementLayer.refreshMap();
- }
- positionToAddPoint = -1;
- }
-
- private void cancelAddPointAfterMode() {
- if (inAddPointAfterMode) {
- switchAddPointAfterMode(false);
- }
- clearSelection();
- MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
- if (measurementToolLayer != null) {
- measurementToolLayer.exitAddPointAfterMode();
- measurementToolLayer.clearSelection();
- measurementToolLayer.refreshMap();
- }
- positionToAddPoint = -1;
- }
-
- private void addPointBefore() {
- MeasurementToolLayer measurementLayer = getMeasurementLayer();
- if (measurementLayer != null && positionToAddPoint != -1) {
- if (addPointToPosition(positionToAddPoint)) {
- selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
- measurementLayer.setSelectedPointPos(selectedPointPos);
- measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
+ int selectedPoint = editingCtx.getSelectedPointPosition(); //after = 1; before = 1;
+ int pointsCount = editingCtx.getPointsCount(); //after = 2; before = 1;
+ if (addCenterPoint()) { //выбрать вторую точку
+ if (selectedPoint == pointsCount) {
+ editingCtx.splitSegments(editingCtx.getPointsCount() - 1);
+ } else {
+ editingCtx.setSelectedPointPosition(selectedPoint + 1);
+ }
measurementLayer.refreshMap();
}
}
}
- private void applyAddPointBeforeMode() {
- if (inAddPointBeforeMode) {
- switchAddPointBeforeMode(false);
- }
- clearSelection();
+ private void applyAddPointBeforeAfterMode() {
+ switchAddPointBeforeAfterMode(false);
+ editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
+ editingCtx.setSelectedPointPosition(-1);
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
- measurementLayer.exitAddPointBeforeMode();
- measurementLayer.clearSelection();
measurementLayer.refreshMap();
}
- positionToAddPoint = -1;
+ updateText();
}
- private void cancelAddPointBeforeMode() {
- if (inAddPointBeforeMode) {
- switchAddPointBeforeMode(false);
- }
- clearSelection();
+ private void cancelAddPointBeforeOrAfterMode() {
+ switchAddPointBeforeAfterMode(false);
+ editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
+ editingCtx.setSelectedPointPosition(-1);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
- measurementToolLayer.exitAddPointBeforeMode();
- measurementToolLayer.clearSelection();
measurementToolLayer.refreshMap();
}
- positionToAddPoint = -1;
- }
-
- private void clearSelection() {
- selectedPointPos = -1;
- selectedCachedPoint = null;
}
private void switchMovePointMode(boolean enable) {
- inMovePointMode = enable;
- if (inMovePointMode) {
+ if (enable) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@@ -1072,9 +914,8 @@ public class MeasurementToolFragment extends Fragment {
: R.drawable.ic_action_ruler));
}
- private void switchAddPointAfterMode(boolean enable) {
- inAddPointAfterMode = enable;
- if (inAddPointAfterMode) {
+ private void switchAddPointBeforeAfterMode(boolean enable) {
+ if (enable) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@@ -1085,31 +926,11 @@ public class MeasurementToolFragment extends Fragment {
}
markGeneralComponents(enable ? View.GONE : View.VISIBLE);
mark(enable ? View.VISIBLE : View.GONE,
- R.id.add_point_after_text,
+ R.id.add_point_before_after_text,
R.id.add_point_before_after_controls);
- mainIcon.setImageDrawable(getActiveIcon(enable
- ? R.drawable.ic_action_addpoint_above
- : R.drawable.ic_action_ruler));
- }
-
- private void switchAddPointBeforeMode(boolean enable) {
- inAddPointBeforeMode = enable;
- if (inAddPointBeforeMode) {
- toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
- } else {
- toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
+ if (!enable) {
+ mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
}
- MapActivity mapActivity = getMapActivity();
- if (mapActivity != null) {
- mapActivity.showTopToolbar(toolBarController);
- }
- markGeneralComponents(enable ? View.GONE : View.VISIBLE);
- mark(enable ? View.VISIBLE : View.GONE,
- R.id.add_point_before_text,
- R.id.add_point_before_after_controls);
- mainIcon.setImageDrawable(getActiveIcon(enable
- ? R.drawable.ic_action_addpoint_below
- : R.drawable.ic_action_ruler));
}
private void markGeneralComponents(int status) {
@@ -1124,31 +945,22 @@ public class MeasurementToolFragment extends Fragment {
private void addPoint() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
- commandManager.execute(new AddPointCommand(measurementLayer, false));
+ editingCtx.getCommandManager().execute(new AddPointCommand(measurementLayer, false));
doAddOrMovePointCommonStuff();
}
}
- private void addCenterPoint() {
- MeasurementToolLayer measurementLayer = getMeasurementLayer();
- if (measurementLayer != null) {
- commandManager.execute(new AddPointCommand(measurementLayer, true));
- doAddOrMovePointCommonStuff();
- }
- }
-
- private boolean addPointToPosition(int position) {
+ private boolean addCenterPoint() {
boolean added = false;
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
- added = commandManager.execute(new AddPointCommand(measurementLayer, position));
+ added = editingCtx.getCommandManager().execute(new AddPointCommand(measurementLayer, true));
doAddOrMovePointCommonStuff();
}
return added;
}
private void doAddOrMovePointCommonStuff() {
- recalculateSnapToRoadIfNedeed();
enable(undoBtn, upDownBtn);
disable(redoBtn);
updateText();
@@ -1191,7 +1003,7 @@ public class MeasurementToolFragment extends Fragment {
private void hidePointsListIfNoPoints() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
- if (measurementPoints.size() < 1) {
+ if (editingCtx.getPointsCount() < 1) {
disable(upDownBtn);
if (pointsListOpened) {
hidePointsList();
@@ -1238,10 +1050,10 @@ public class MeasurementToolFragment extends Fragment {
}
private void addToGpx(MapActivity mapActivity) {
- GPXFile gpx = newGpxData.getGpxFile();
+ GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null;
- NewGpxData.ActionType actionType = newGpxData.getActionType();
+ ActionType actionType = editingCtx.getNewGpxData().getActionType();
saveExistingGpx(gpx, showOnMap, actionType, true);
}
@@ -1353,7 +1165,7 @@ public class MeasurementToolFragment extends Fragment {
toSave = new File(dir, fileName);
GPXFile gpx = new GPXFile();
if (measurementLayer != null) {
- List points = measurementLayer.getMeasurementPoints();
+ List points = editingCtx.getPoints();
if (saveType == SaveType.LINE) {
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
@@ -1377,7 +1189,7 @@ public class MeasurementToolFragment extends Fragment {
} else {
toSave = new File(gpx.path);
if (measurementLayer != null) {
- List points = measurementLayer.getMeasurementPoints();
+ List points = editingCtx.getPoints();
if (actionType != null) {
switch (actionType) {
case ADD_SEGMENT:
@@ -1389,7 +1201,7 @@ public class MeasurementToolFragment extends Fragment {
case EDIT_SEGMENT:
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
- gpx.replaceSegment(newGpxData.getTrkSegment(), segment);
+ gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
break;
}
} else {
@@ -1455,7 +1267,7 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
distanceTv.setText(measurementLayer.getDistanceSt() + ",");
- pointsTv.setText((portrait ? pointsSt + ": " : "") + measurementPoints.size());
+ pointsTv.setText((portrait ? pointsSt + ": " : "") + editingCtx.getPointsCount());
}
}
@@ -1534,16 +1346,11 @@ public class MeasurementToolFragment extends Fragment {
}
public void quit(boolean hidePointsListFirst) {
- if (inMovePointMode) {
+ if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode();
return;
- }
- if (inAddPointAfterMode) {
- cancelAddPointAfterMode();
- return;
- }
- if (inAddPointBeforeMode) {
- cancelAddPointBeforeMode();
+ } else if (editingCtx.getSelectedPointPosition() != -1) {
+ cancelAddPointBeforeOrAfterMode();
return;
}
showQuitDialog(hidePointsListFirst);
@@ -1557,7 +1364,7 @@ public class MeasurementToolFragment extends Fragment {
hidePointsList();
return;
}
- if (measurementPoints.size() < 1 || saved) {
+ if (editingCtx.getPointsCount() < 1 || saved) {
dismiss(mapActivity);
return;
}
@@ -1577,18 +1384,15 @@ public class MeasurementToolFragment extends Fragment {
private void dismiss(MapActivity mapActivity) {
try {
- MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
- if (measurementToolLayer != null) {
- measurementToolLayer.getMeasurementPoints().clear();
- }
+ editingCtx.clearSegments();
if (pointsListOpened) {
hidePointsList();
}
- if (isInSnapToRoadMode) {
+ if (editingCtx.isInSnapToRoadMode()) {
disableSnapToRoadMode();
}
- if (newGpxData != null) {
- GPXFile gpx = newGpxData.getGpxFile();
+ if (editingCtx.getNewGpxData() != null) {
+ GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
newIntent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true);
@@ -1601,10 +1405,23 @@ public class MeasurementToolFragment extends Fragment {
}
}
- public static boolean showInstance(FragmentManager fragmentManager, NewGpxData newGpxData) {
+ public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) {
+ try {
+ MeasurementToolFragment fragment = new MeasurementToolFragment();
+ fragment.setEditingCtx(editingCtx);
+ fragment.setRetainInstance(true);
+ fragmentManager.beginTransaction()
+ .add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
+ .commitAllowingStateLoss();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public static boolean showInstance(FragmentManager fragmentManager) {
try {
MeasurementToolFragment fragment = new MeasurementToolFragment();
- fragment.setNewGpxData(newGpxData);
fragment.setRetainInstance(true);
fragmentManager.beginTransaction()
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
index 3ca9f8402f..22fa156ad9 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
@@ -7,54 +7,49 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
-import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
+import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
+import net.osmand.plus.views.Renderable;
import net.osmand.util.MapUtils;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
+ private static final int POINTS_TO_DRAW = 50;
private OsmandMapTileView view;
private boolean inMeasurementMode;
- private boolean inMovePointMode;
- private boolean inAddPointAfterMode;
- private boolean inAddPointBeforeMode;
- private List measurementPoints = new LinkedList<>();
- private List snappedToRoadPoints = new LinkedList<>();
private Bitmap centerIconDay;
private Bitmap centerIconNight;
private Bitmap pointIcon;
private Bitmap applyingPointIcon;
private Paint bitmapPaint;
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
- private final Path path = new Path();
private int marginPointIconX;
private int marginPointIconY;
private int marginApplyingPointIconX;
private int marginApplyingPointIconY;
- private final TIntArrayList tx = new TIntArrayList();
- private final TIntArrayList ty = new TIntArrayList();
+ private Path path = new Path();
+ private TIntArrayList tx = new TIntArrayList();
+ private TIntArrayList ty = new TIntArrayList();
private OnMeasureDistanceToCenter measureDistanceToCenterListener;
private OnSingleTapListener singleTapListener;
private OnEnterMovePointModeListener enterMovePointModeListener;
- private int selectedPointPos = -1;
- private WptPt selectedCachedPoint;
private LatLon pressedPointLatLon;
private boolean overlapped;
- private int pointsToDraw = 50;
+ private MeasurementEditingContext editingCtx;
@Override
public void initLayer(OsmandMapTileView view) {
@@ -81,6 +76,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.singleTapListener = listener;
}
+ void setEditingCtx(MeasurementEditingContext editingCtx) {
+ this.editingCtx = editingCtx;
+ }
+
void setOnEnterMovePointModeListener(OnEnterMovePointModeListener listener) {
this.enterMovePointModeListener = listener;
}
@@ -89,64 +88,25 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.measureDistanceToCenterListener = listener;
}
- void setSelectedPointPos(int pos) {
- selectedPointPos = pos;
- }
-
- void setSelectedCachedPoint(WptPt selectedCachedPoint) {
- this.selectedCachedPoint = selectedCachedPoint;
- }
-
- WptPt getSelectedCachedPoint() {
- return selectedCachedPoint;
- }
-
- int getSelectedPointPos() {
- return selectedPointPos;
+ public MeasurementEditingContext getEditingCtx() {
+ return editingCtx;
}
public boolean isInMeasurementMode() {
return inMeasurementMode;
}
- boolean isInMovePointMode() {
- return inMovePointMode;
- }
-
- boolean isInAddPointAfterMode() {
- return inAddPointAfterMode;
- }
-
- boolean isInAddPointBeforeMode() {
- return inAddPointBeforeMode;
- }
-
void setInMeasurementMode(boolean inMeasurementMode) {
this.inMeasurementMode = inMeasurementMode;
}
- public List getMeasurementPoints() {
- return measurementPoints;
- }
-
- void setMeasurementPoints(List points) {
- measurementPoints = points;
- }
-
- public List getSnappedToRoadPoints() {
- return snappedToRoadPoints;
- }
-
- public void setSnappedToRoadPoints(List snappedToRoadPoints) {
- this.snappedToRoadPoints = snappedToRoadPoints;
- }
-
String getDistanceSt() {
float dist = 0;
- if (measurementPoints.size() > 0) {
- for (int i = 1; i < measurementPoints.size(); i++) {
- dist += MapUtils.getDistance(measurementPoints.get(i - 1).lat, measurementPoints.get(i - 1).lon,
- measurementPoints.get(i).lat, measurementPoints.get(i).lon);
+ List points = editingCtx.getPoints();
+ if (points.size() > 0) {
+ for (int i = 1; i < points.size(); i++) {
+ dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon,
+ points.get(i).lat, points.get(i).lon);
}
}
return OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
@@ -154,15 +114,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
- if (singleTapListener != null) {
- if (inMeasurementMode && !inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
- if (overlapped) {
- clearSelection();
- } else {
- selectPoint(point.x, point.y, true);
- }
- if (selectedPointPos == -1) {
- pressedPointLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
+ if (inMeasurementMode && editingCtx.getSelectedPointPosition() == -1) {
+ if (!overlapped) {
+ selectPoint(point.x, point.y, true);
+ }
+ if (editingCtx.getSelectedPointPosition() == -1) {
+ pressedPointLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
+ if (singleTapListener != null) {
singleTapListener.onAddPoint();
}
}
@@ -170,19 +128,14 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return false;
}
- void clearSelection() {
- selectedPointPos = -1;
- selectedCachedPoint = null;
- }
-
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode) {
- if (!overlapped && !inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode && measurementPoints.size() > 0) {
+ if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) {
selectPoint(point.x, point.y, false);
- if (selectedCachedPoint != null && selectedPointPos != -1) {
+ if (editingCtx.getSelectedPointPosition() != -1) {
enterMovingPointMode();
- if (inMeasurementMode && inMovePointMode && enterMovePointModeListener != null) {
+ if (enterMovePointModeListener != null) {
enterMovePointModeListener.onEnterMovePointMode();
}
}
@@ -192,48 +145,53 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
void enterMovingPointMode() {
- inMovePointMode = true;
- moveMapToPoint(selectedPointPos);
- }
-
- void enterAddingPointAfterMode() {
- inAddPointAfterMode = true;
- moveMapToPoint(selectedPointPos);
- }
-
- void enterAddingPointBeforeMode() {
- inAddPointBeforeMode = true;
- moveMapToPoint(selectedPointPos);
+ moveMapToPoint(editingCtx.getSelectedPointPosition());
+ WptPt pt = editingCtx.removePoint(editingCtx.getSelectedPointPosition());
+ editingCtx.setOriginalPointToMove(pt);
+ editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
}
private void selectPoint(double x, double y, boolean singleTap) {
- clearSelection();
RotatedTileBox tb = view.getCurrentRotatedTileBox();
double lowestDistance = view.getResources().getDimension(R.dimen.measurement_tool_select_radius);
- for (int i = 0; i < measurementPoints.size(); i++) {
- WptPt pt = measurementPoints.get(i);
+ for (int i = 0; i < editingCtx.getPointsCount(); i++) {
+ WptPt pt = editingCtx.getPoints().get(i);
if (tb.containsLatLon(pt.getLatitude(), pt.getLongitude())) {
double xDiff = tb.getPixXFromLonNoRot(pt.getLongitude()) - x;
double yDiff = tb.getPixYFromLatNoRot(pt.getLatitude()) - y;
double distToPoint = Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
if (distToPoint < lowestDistance) {
lowestDistance = distToPoint;
- selectedCachedPoint = new WptPt(pt);
- selectedPointPos = i;
+ editingCtx.setSelectedPointPosition(i);
}
}
}
if (singleTap && singleTapListener != null) {
- singleTapListener.onSelectPoint(selectedPointPos, selectedCachedPoint);
+ singleTapListener.onSelectPoint(editingCtx.getSelectedPointPosition());
}
}
void selectPoint(int position) {
- clearSelection();
- selectedCachedPoint = new WptPt(measurementPoints.get(position));
- selectedPointPos = position;
+ editingCtx.setSelectedPointPosition(position);
if (singleTapListener != null) {
- singleTapListener.onSelectPoint(selectedPointPos, selectedCachedPoint);
+ singleTapListener.onSelectPoint(editingCtx.getSelectedPointPosition());
+ }
+ }
+
+ @Override
+ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
+ if (inMeasurementMode) {
+ lineAttrs.updatePaints(view, settings, tb);
+
+ TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
+ before.renders.clear();
+ before.renders.add(new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2));
+ before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
+
+ TrkSegment after = editingCtx.getAfterTrkSegmentLine();
+ after.renders.clear();
+ after.renders.add(new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2));
+ after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
}
}
@@ -241,12 +199,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (inMeasurementMode) {
lineAttrs.updatePaints(view, settings, tb);
- if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
+
+ if (editingCtx.getSelectedPointPosition() == -1) {
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
if (measureDistanceToCenterListener != null) {
float distance = 0;
- if (measurementPoints.size() > 0) {
- WptPt lastPoint = measurementPoints.get(measurementPoints.size() - 1);
+ if (editingCtx.getPointsCount() > 0) {
+ WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1);
LatLon centerLatLon = tb.getCenterLatLon();
distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
}
@@ -254,119 +213,101 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
}
- List drawPoints;
- if (snappedToRoadPoints.size() > 0) {
- drawPoints = snappedToRoadPoints;
- } else {
- drawPoints = measurementPoints;
- }
- if (drawPoints.size() > 0) {
+ TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
+ TrkSegment after = editingCtx.getAfterTrkSegmentLine();
+
+ if (before.points.size() > 0 || after.points.size() > 0) {
path.reset();
tx.reset();
ty.reset();
- for (int i = 0; i < drawPoints.size(); i++) {
- WptPt pt = drawPoints.get(i);
- int locX;
- int locY;
- if (selectedPointPos == i && (inMovePointMode || inAddPointAfterMode || inAddPointBeforeMode)) {
- locX = tb.getCenterPixelX();
- locY = tb.getCenterPixelY();
- } else {
- locX = tb.getPixXFromLonNoRot(pt.lon);
- locY = tb.getPixYFromLatNoRot(pt.lat);
- }
- if (inAddPointAfterMode) {
- int previousLocX = tb.getPixXFromLonNoRot(pt.lon);
- int previousLocY = tb.getPixYFromLatNoRot(pt.lat);
- if (i == 0) {
- path.moveTo(previousLocX, previousLocY);
- } else {
- path.lineTo(previousLocX, previousLocY);
- }
- tx.add(previousLocX);
- ty.add(previousLocY);
- path.lineTo(locX, locY);
- tx.add(locX);
- ty.add(locY);
- } else if (inAddPointBeforeMode) {
- if (i == 0) {
- path.moveTo(locX, locY);
- } else {
- path.lineTo(locX, locY);
- }
- tx.add(locX);
- ty.add(locY);
- int followingLocX = tb.getPixXFromLonNoRot(pt.lon);
- int followingLocY = tb.getPixYFromLatNoRot(pt.lat);
- path.lineTo(followingLocX, followingLocY);
- tx.add(followingLocX);
- ty.add(followingLocY);
- } else {
- if (i == 0) {
- path.moveTo(locX, locY);
- } else {
- path.lineTo(locX, locY);
- }
- tx.add(locX);
- ty.add(locY);
- }
- }
- if (!inMovePointMode && !inAddPointAfterMode && !inAddPointBeforeMode) {
+ if (before.points.size() > 0) {
+ WptPt pt = before.points.get(before.points.size() - 1);
+ int locX = tb.getPixXFromLonNoRot(pt.lon);
+ int locY = tb.getPixYFromLatNoRot(pt.lat);
+ path.moveTo(locX, locY);
+ tx.add(locX);
+ ty.add(locY);
path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
}
+ if (after.points.size() > 0) {
+ if (before.points.size() == 0) {
+ path.moveTo(tb.getCenterPixelX(), tb.getCenterPixelY());
+ tx.add(tb.getCenterPixelX());
+ ty.add(tb.getCenterPixelY());
+ }
+ WptPt pt = after.points.get(0);
+ int locX = tb.getPixXFromLonNoRot(pt.lon);
+ int locY = tb.getPixYFromLatNoRot(pt.lat);
+ path.lineTo(locX, locY);
+ tx.add(locX);
+ ty.add(locY);
+ }
+
calculatePath(tb, tx, ty, path);
canvas.drawPath(path, lineAttrs.paint);
+ }
- overlapped = false;
- int drawn = 0;
- for (int i = 0; i < measurementPoints.size(); i++) {
- WptPt pt = measurementPoints.get(i);
+ List points = new ArrayList<>();
+ points.addAll(editingCtx.getBeforePoints());
+ points.addAll(editingCtx.getAfterPoints());
+ overlapped = false;
+ int drawn = 0;
+ for (int i = 0; i < points.size(); i++) {
+ WptPt pt = points.get(i);
+ int locX = tb.getPixXFromLonNoRot(pt.lon);
+ int locY = tb.getPixYFromLatNoRot(pt.lat);
+ if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
+ drawn++;
+ if (drawn > POINTS_TO_DRAW) {
+ overlapped = true;
+ break;
+ }
+ }
+ }
+ if (overlapped) {
+ WptPt pt = points.get(0);
+ int locX = tb.getPixXFromLonNoRot(pt.lon);
+ int locY = tb.getPixYFromLatNoRot(pt.lat);
+ if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
+ canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
+ }
+ pt = points.get(points.size() - 1);
+ locX = tb.getPixXFromLonNoRot(pt.lon);
+ locY = tb.getPixYFromLatNoRot(pt.lat);
+ if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
+ canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
+
+ }
+ } else {
+ for (int i = 0; i < points.size(); i++) {
+ WptPt pt = points.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
- if (!(inMovePointMode && i == selectedPointPos)) {
- drawn++;
- if (drawn > pointsToDraw) {
- overlapped = true;
- break;
- }
- }
+ canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
- if (!overlapped) {
- for (int i = 0; i < measurementPoints.size(); i++) {
- WptPt pt = measurementPoints.get(i);
- int locX = tb.getPixXFromLonNoRot(pt.lon);
- int locY = tb.getPixYFromLatNoRot(pt.lat);
- if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
- if (!(inMovePointMode && i == selectedPointPos)) {
- canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
- }
- }
- }
- }
- if (inAddPointAfterMode || inAddPointBeforeMode || inMovePointMode) {
- int locX = tb.getCenterPixelX();
- int locY = tb.getCenterPixelY();
- canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
- }
+ }
+
+ if (editingCtx.getSelectedPointPosition() != -1) {
+ int locX = tb.getCenterPixelX();
+ int locY = tb.getCenterPixelY();
+ canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
}
}
}
- void exitMovePointMode() {
- inMovePointMode = false;
- }
-
- void exitAddPointAfterMode() {
- inAddPointAfterMode = false;
- }
-
- void exitAddPointBeforeMode() {
- inAddPointBeforeMode = false;
+ void exitMovePointMode(boolean saveOriginalPoint) {
+ if (saveOriginalPoint) {
+ WptPt pt = editingCtx.getOriginalPointToMove();
+ editingCtx.addPoint(pt);
+ }
+ editingCtx.setOriginalPointToMove(null);
+ editingCtx.setSelectedPointPosition(-1);
+ editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
}
private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
@@ -381,30 +322,32 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
canvas.rotate(tb.getRotate(), center.x, center.y);
}
- public WptPt addCenterPoint(int position) {
+ public WptPt addCenterPoint() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
WptPt pt = new WptPt();
pt.lat = l.getLatitude();
pt.lon = l.getLongitude();
- boolean allowed = measurementPoints.size() == 0 || !measurementPoints.get(measurementPoints.size() - 1).equals(pt);
+ boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
- measurementPoints.add(position, pt);
+ editingCtx.addPoint(pt);
return pt;
}
return null;
}
- public WptPt addPoint(int position) {
+ public WptPt addPoint() {
if (pressedPointLatLon != null) {
WptPt pt = new WptPt();
- pt.lat = pressedPointLatLon.getLatitude();
- pt.lon = pressedPointLatLon.getLongitude();
+ double lat = pressedPointLatLon.getLatitude();
+ double lon = pressedPointLatLon.getLongitude();
+ pt.lat = lat;
+ pt.lon = lon;
pressedPointLatLon = null;
- boolean allowed = measurementPoints.size() == 0 || !measurementPoints.get(measurementPoints.size() - 1).equals(pt);
+ boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
- measurementPoints.add(position, pt);
- moveMapToPoint(position);
+ editingCtx.addPoint(pt);
+ moveMapToLatLon(lat, lon);
return pt;
}
}
@@ -414,24 +357,28 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt getMovedPointToApply() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon latLon = tb.getCenterLatLon();
- WptPt pt = measurementPoints.get(selectedPointPos);
+ WptPt pt = new WptPt(editingCtx.getOriginalPointToMove());
pt.lat = latLon.getLatitude();
pt.lon = latLon.getLongitude();
return pt;
}
- public void moveMapToPoint(int pos) {
- if (measurementPoints.size() > 0) {
- if (pos >= measurementPoints.size()) {
- pos = measurementPoints.size() - 1;
- } else if (pos < 0) {
- pos = 0;
- }
- WptPt pt = measurementPoints.get(pos);
- view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
- }
+ private void moveMapToLatLon(double lat, double lon) {
+ view.getAnimatedDraggingThread().startMoving(lat, lon, view.getZoom(), true);
}
+ public void moveMapToPoint(int pos) {
+ if (editingCtx.getPointsCount() > 0) {
+ if (pos >= editingCtx.getPointsCount()) {
+ pos = editingCtx.getPointsCount() - 1;
+ } else if (pos < 0) {
+ pos = 0;
+ }
+ WptPt pt = editingCtx.getPoints().get(pos);
+ moveMapToLatLon(pt.getLatitude(), pt.getLongitude());
+ }
+ }
+
public void refreshMap() {
view.refreshMap();
}
@@ -480,7 +427,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
void onAddPoint();
- void onSelectPoint(int selectedPointPos, WptPt selectedCachedPoint);
+ void onSelectPoint(int selectedPointPos);
}
interface OnEnterMovePointModeListener {
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java
index dbca650225..595f701073 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java
@@ -23,9 +23,9 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
-import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
+import net.osmand.plus.measurementtool.NewGpxData.ActionType;
import net.osmand.util.MapUtils;
import java.util.List;
@@ -37,16 +37,11 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
private SelectedPointFragmentListener listener;
private boolean nightMode;
private boolean portrait;
- private NewGpxData.ActionType actionType;
public void setListener(SelectedPointFragmentListener listener) {
this.listener = listener;
}
- public void setActionType(NewGpxData.ActionType actionType) {
- this.actionType = actionType;
- }
-
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -108,19 +103,28 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
+ if (listener != null) {
+ listener.onClearSelection();
+ }
dismiss();
}
});
- List points = measurementLayer.getMeasurementPoints();
- int pos = measurementLayer.getSelectedPointPos();
+ List points = measurementLayer.getEditingCtx().getPoints();
+ int pos = measurementLayer.getEditingCtx().getSelectedPointPosition();
WptPt pt = points.get(pos);
String pointTitle = pt.name;
if (!TextUtils.isEmpty(pointTitle)) {
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle);
} else {
- if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
- ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
+ NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData();
+ if (newGpxData != null) {
+ ActionType actionType = measurementLayer.getEditingCtx().getNewGpxData().getActionType();
+ if (actionType == ActionType.ADD_ROUTE_POINTS) {
+ ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
+ } else {
+ ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
+ }
} else {
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
}
@@ -139,6 +143,19 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
}
}
+ NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData();
+ if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) {
+ double elevation = pt.ele;
+ if (!Double.isNaN(elevation)) {
+ String eleStr = (mapActivity.getString(R.string.altitude)).substring(0, 1);
+ ((TextView) mainView.findViewById(R.id.selected_point_ele)).setText(eleStr + ": " + OsmAndFormatter.getFormattedAlt(elevation, mapActivity.getMyApplication()));
+ }
+ float speed = (float) pt.speed;
+ if (speed != 0) {
+ String speedStr = (mapActivity.getString(R.string.map_widget_speed)).substring(0, 1);
+ ((TextView) mainView.findViewById(R.id.selected_point_speed)).setText(speedStr + ": " + OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication()));
+ }
+ }
final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
@@ -208,6 +225,7 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
public void onCancel(DialogInterface dialog) {
if (listener != null) {
listener.onCloseMenu();
+ listener.onClearSelection();
}
super.onCancel(dialog);
}
@@ -223,5 +241,7 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
void addPointBeforeOnClick();
void onCloseMenu();
+
+ void onClearSelection();
}
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java
index f5ed512090..507dc7e9e8 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java
@@ -108,13 +108,15 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter points;
- private List snappedToRoadPoints;
public ClearPointsCommand(MeasurementToolLayer measurementLayer) {
this.measurementLayer = measurementLayer;
@@ -17,27 +16,23 @@ public class ClearPointsCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
- List pts = measurementLayer.getMeasurementPoints();
- List snappedPts = measurementLayer.getSnappedToRoadPoints();
+ List pts = measurementLayer.getEditingCtx().getPoints();
points = new LinkedList<>(pts);
- snappedToRoadPoints = new LinkedList<>(snappedPts);
pts.clear();
- snappedPts.clear();
+ measurementLayer.getEditingCtx().clearSegments();
measurementLayer.refreshMap();
return true;
}
@Override
public void undo() {
- measurementLayer.getMeasurementPoints().addAll(points);
- measurementLayer.getSnappedToRoadPoints().addAll(snappedToRoadPoints);
+ measurementLayer.getEditingCtx().addPoints(points);
measurementLayer.refreshMap();
}
@Override
public void redo() {
- measurementLayer.getMeasurementPoints().clear();
- measurementLayer.getSnappedToRoadPoints().clear();
+ measurementLayer.getEditingCtx().clearSegments();
measurementLayer.refreshMap();
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java
index 242f981ea1..3f4d55725e 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java
@@ -23,15 +23,15 @@ public class MovePointCommand extends MeasurementModeCommand {
@Override
public void undo() {
- measurementLayer.getMeasurementPoints().remove(position);
- measurementLayer.getMeasurementPoints().add(position, oldPoint);
+ measurementLayer.getEditingCtx().removePoint(position);
+ measurementLayer.getEditingCtx().addPoint(position, oldPoint);
measurementLayer.refreshMap();
}
@Override
public void redo() {
- measurementLayer.getMeasurementPoints().remove(position);
- measurementLayer.getMeasurementPoints().add(position, newPoint);
+ measurementLayer.getEditingCtx().removePoint(position);
+ measurementLayer.getEditingCtx().addPoint(position, newPoint);
measurementLayer.refreshMap();
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java
index 380e55e331..3c26487acd 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java
@@ -15,21 +15,21 @@ public class RemovePointCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
- point = measurementLayer.getMeasurementPoints().remove(position);
+ point = measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.refreshMap();
return true;
}
@Override
public void undo() {
- measurementLayer.getMeasurementPoints().add(position, point);
+ measurementLayer.getEditingCtx().addPoint(position, point);
measurementLayer.refreshMap();
measurementLayer.moveMapToPoint(position);
}
@Override
public void redo() {
- measurementLayer.getMeasurementPoints().remove(position);
+ measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.refreshMap();
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java
index 69c9218a28..316f007a31 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java
@@ -31,7 +31,7 @@ public class ReorderPointCommand extends MeasurementModeCommand {
}
private void swap() {
- Collections.swap(measurementLayer.getMeasurementPoints(), from, to);
+ Collections.swap(measurementLayer.getEditingCtx().getPoints(), from, to);
measurementLayer.refreshMap();
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/SnapToRoadCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/SnapToRoadCommand.java
index ceb4d1bdd2..61708c9c3c 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/command/SnapToRoadCommand.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/SnapToRoadCommand.java
@@ -16,21 +16,21 @@ public class SnapToRoadCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
- measurementLayer.getSnappedToRoadPoints().clear();
- measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
- measurementLayer.refreshMap();
+// measurementLayer.getSnappedToRoadPoints().clear();
+// measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
+// measurementLayer.refreshMap();
return true;
}
@Override
public void undo() {
- measurementLayer.getSnappedToRoadPoints().clear();
+// measurementLayer.getSnappedToRoadPoints().clear();
measurementLayer.refreshMap();
}
@Override
public void redo() {
- measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
+// measurementLayer.getSnappedToRoadPoints().addAll(snappedPoints);
measurementLayer.refreshMap();
}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
index 1a5654ac7d..b535d0fcfb 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
@@ -6,8 +6,9 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.RouteService;
-import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
+import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
import net.osmand.router.RouteCalculationProgress;
+import net.osmand.router.RoutingContext;
import java.util.List;
@@ -16,16 +17,23 @@ public class RouteCalculationParams {
public Location start;
public LatLon end;
public List intermediates;
-
-
+
+
public OsmandApplication ctx;
+ public RoutingContext cachedRoutingContext;
public ApplicationMode mode;
public RouteService type;
public GPXRouteParams gpxRoute;
- public SnapToRoadParams snapToRoadParams;
public RouteCalculationResult previousToRecalculate;
public boolean onlyStartPointChanged;
public boolean fast;
public boolean leftSide;
+ public boolean inSnapToRoadMode;
public RouteCalculationProgress calculationProgress;
+ public RouteCalculationProgressCallback calculationProgressCallback;
+ public RouteCalculationResultListener resultListener;
+
+ public interface RouteCalculationResultListener {
+ void onRouteCalculated(List locations);
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index 1cb3acc763..57d1ae0e60 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -1,26 +1,9 @@
package net.osmand.plus.routing;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.net.MalformedURLException;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
+import android.content.Context;
+import android.os.Build;
+import android.os.Bundle;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@@ -44,13 +27,11 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.render.NativeOsmandLibrary;
-import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.router.PrecalculatedRouteDirection;
-import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RoutePlannerFrontEnd;
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
import net.osmand.router.RouteSegmentResult;
@@ -59,22 +40,36 @@ import net.osmand.router.RoutingConfiguration.Builder;
import net.osmand.router.RoutingContext;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
-import net.osmand.util.MapUtils;
import net.osmand.util.GeoPolylineParserUtil;
+import net.osmand.util.MapUtils;
-import org.json.JSONObject;
-import org.json.JSONArray;
import org.json.JSONException;
+import org.json.JSONObject;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import android.content.Context;
-import android.os.Build;
-import android.os.Bundle;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+
import btools.routingapp.IBRouterService;
@@ -284,19 +279,6 @@ public class RouteProvider {
}
}
- public static class SnapToRoadParams {
-
- public ApplicationMode applicationMode;
- public RouteCalculationProgress calculationProgress;
- public RouteCalculationProgressCallback calculationProgressCallback;
- public SnapToRoadListener listener;
- public List points;
-
- public interface SnapToRoadListener {
- void onSnapToRoadDone();
- }
- }
-
private static Location createLocation(WptPt pt){
Location loc = new Location("OsmandRouteProvider");
loc.setLatitude(pt.lat);
@@ -769,7 +751,7 @@ public class RouteProvider {
paramsR.put(key, vl);
}
}
- if (params.snapToRoadParams != null) {
+ if (params.inSnapToRoadMode) {
paramsR.put(GeneralRouter.ALLOW_PRIVATE, "true");
}
float mb = (1 << 20);
diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
index dcbad72858..62162f5efd 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
@@ -19,7 +19,6 @@ import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
-import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
@@ -388,7 +387,7 @@ public class RoutingHelper {
if (calculateRoute) {
recalculateRouteInBackground(currentLocation, finalLocation, intermediatePoints, currentGPXRoute,
- previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged, null);
+ previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged);
} else {
Thread job = currentRunningJob;
if(job instanceof RouteRecalculationThread) {
@@ -871,11 +870,8 @@ public class RoutingHelper {
synchronized (RoutingHelper.this) {
if (res.isCalculated()) {
route = res;
- if (params.snapToRoadParams != null) {
- params.snapToRoadParams.points = res.getRouteLocations();
- if (params.snapToRoadParams.listener != null) {
- params.snapToRoadParams.listener.onSnapToRoadDone();
- }
+ if (params.resultListener != null) {
+ params.resultListener.onRouteCalculated(res.getRouteLocations());
}
} else {
evalWaitInterval = Math.max(3000, evalWaitInterval * 3 / 2); // for Issue #3899
@@ -911,18 +907,13 @@ public class RoutingHelper {
}
}
- public void recalculateSnapToRoad(final Location start, final LatLon end, final List intermediates, SnapToRoadParams params) {
- recalculateRouteInBackground(start, end, intermediates, null, route, true, false, params);
- }
-
public void recalculateRouteDueToSettingsChange() {
clearCurrentRoute(finalLocation, intermediatePoints);
- recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false, null);
+ recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false);
}
private void recalculateRouteInBackground(final Location start, final LatLon end, final List intermediates,
- final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged,
- final SnapToRoadParams snapToRoadParams){
+ final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged){
if (start == null || end == null) {
return;
}
@@ -944,42 +935,39 @@ public class RoutingHelper {
recalculateCountInInterval = 0;
}
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
- ApplicationMode mode;
- if (snapToRoadParams != null && snapToRoadParams.applicationMode != null) {
- params.snapToRoadParams = snapToRoadParams;
- mode = snapToRoadParams.applicationMode;
- } else {
- mode = this.mode;
- }
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
params.mode = mode;
params.ctx = app;
+ boolean updateProgress = false;
if (params.type == RouteService.OSMAND) {
- if (snapToRoadParams != null && snapToRoadParams.calculationProgress != null) {
- params.calculationProgress = snapToRoadParams.calculationProgress;
- } else {
- params.calculationProgress = new RouteCalculationProgress();
- }
- updateProgress(params);
+ params.calculationProgress = new RouteCalculationProgress();
+ updateProgress = true;
}
- synchronized (this) {
- final Thread prevRunningJob = currentRunningJob;
- RouteRecalculationThread newThread = new RouteRecalculationThread(
- "Calculating route", params, paramsChanged); //$NON-NLS-1$
- currentRunningJob = newThread;
- if (prevRunningJob != null) {
- newThread.setWaitPrevJob(prevRunningJob);
- }
- currentRunningJob.start();
+ startRouteCalculationThread(params, paramsChanged, updateProgress);
+ }
+ }
+
+ public void startRouteCalculationThread(RouteCalculationParams params, boolean paramsChanged, boolean updateProgress) {
+ if (updateProgress) {
+ updateProgress(params);
+ }
+ synchronized (this) {
+ final Thread prevRunningJob = currentRunningJob;
+ RouteRecalculationThread newThread = new RouteRecalculationThread(
+ "Calculating route", params, paramsChanged); //$NON-NLS-1$
+ currentRunningJob = newThread;
+ if (prevRunningJob != null) {
+ newThread.setWaitPrevJob(prevRunningJob);
}
+ currentRunningJob.start();
}
}
private void updateProgress(final RouteCalculationParams params) {
final RouteCalculationProgressCallback progressRoute;
- if (params.snapToRoadParams != null) {
- progressRoute = params.snapToRoadParams.calculationProgressCallback;
+ if (params.calculationProgressCallback != null) {
+ progressRoute = params.calculationProgressCallback;
} else {
progressRoute = this.progressRoute;
}