Fix snap to road after screen rotating

This commit is contained in:
Alexander Sytnyk 2017-08-25 12:35:16 +03:00
parent 4b23255899
commit 594b233cff
2 changed files with 19 additions and 21 deletions

View file

@ -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<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new LinkedList<>();
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new HashMap<>();
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
private List<WptPt> 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<Pair<WptPt, WptPt>> getSnapToRoadPairsToCalculate() {
return snapToRoadPairsToCalculate;
}
public void setSnapToRoadPairsToCalculate(Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate) {
this.snapToRoadPairsToCalculate = snapToRoadPairsToCalculate;
}
public Map<Pair<WptPt, WptPt>, List<WptPt>> 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()) {

View file

@ -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) {