From 594b233cffc8114b08ad474aca60e0ad484f5959 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 25 Aug 2017 12:35:16 +0300 Subject: [PATCH] Fix snap to road after screen rotating --- .../MeasurementEditingContext.java | 21 ++++--------------- .../MeasurementToolFragment.java | 19 +++++++++++++---- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 63bf521f24..dc086c2914 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -16,11 +16,11 @@ import net.osmand.router.RouteCalculationProgress; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; public class MeasurementEditingContext { @@ -46,7 +46,7 @@ public class MeasurementEditingContext { private ApplicationMode snapToRoadAppMode; private RouteCalculationProgress calculationProgress; private Queue> snapToRoadPairsToCalculate = new LinkedList<>(); - private Map, List> snappedToRoadPoints = new HashMap<>(); + private Map, List> snappedToRoadPoints = new ConcurrentHashMap<>(); private List measurementPoints = new LinkedList<>(); @@ -117,11 +117,7 @@ public class MeasurementEditingContext { } public void setInSnapToRoadMode(boolean inSnapToRoadMode) { - inSnapToRoadMode = inSnapToRoadMode; - } - - public SnapToRoadProgressListener getProgressListener() { - return progressListener; + this.inSnapToRoadMode = inSnapToRoadMode; } public void setProgressListener(SnapToRoadProgressListener progressListener) { @@ -136,14 +132,6 @@ public class MeasurementEditingContext { this.snapToRoadAppMode = snapToRoadAppMode; } - public Queue> getSnapToRoadPairsToCalculate() { - return snapToRoadPairsToCalculate; - } - - public void setSnapToRoadPairsToCalculate(Queue> snapToRoadPairsToCalculate) { - this.snapToRoadPairsToCalculate = snapToRoadPairsToCalculate; - } - public Map, List> getSnappedPoints() { return snappedToRoadPoints; } @@ -229,6 +217,7 @@ public class MeasurementEditingContext { void cancelSnapToRoad() { progressListener.hideProgressBar(); + snapToRoadPairsToCalculate.clear(); if (calculationProgress != null) { calculationProgress.isCancelled = true; } @@ -281,8 +270,6 @@ public class MeasurementEditingContext { pts.add(pt); } snappedToRoadPoints.put(currentPair, pts); - // todo change logic - // todo fix strange exceptions when snap to road calculates recreateSegments(); progressListener.refreshMap(); if (!snapToRoadPairsToCalculate.isEmpty()) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index ecb8c2dbfa..70a3472f57 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -101,6 +101,7 @@ public class MeasurementToolFragment extends Fragment { private ImageView mainIcon; private boolean wasCollapseButtonVisible; + private boolean progressBarVisible; private boolean pointsListOpened; private Boolean saved; private boolean portrait; @@ -130,10 +131,7 @@ public class MeasurementToolFragment extends Fragment { editingCtx.setProgressListener(new MeasurementEditingContext.SnapToRoadProgressListener() { @Override public void showProgressBar() { - ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar); - progressBar.setVisibility(View.VISIBLE); - progressBar.setMinimumHeight(0); - progressBar.setProgress(0); + MeasurementToolFragment.this.showProgressBar(); } @Override @@ -144,6 +142,7 @@ public class MeasurementToolFragment extends Fragment { @Override public void hideProgressBar() { ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE); + progressBarVisible = false; } @Override @@ -201,6 +200,10 @@ 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); @@ -521,6 +524,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) {