Do some refactoring

This commit is contained in:
Alexander Sytnyk 2017-08-22 11:59:06 +03:00
parent 53e20809e1
commit 8e391b1925

View file

@ -122,12 +122,12 @@ public class MeasurementToolFragment extends Fragment {
private int previousMapPosition; private int previousMapPosition;
private NewGpxLine newGpxLine; private NewGpxLine newGpxLine;
private boolean gpxPointsAdded; private boolean gpxPointsAdded;
private boolean snapToRoadEnabled;
private ApplicationMode snapToRoadAppMode; private ApplicationMode snapToRoadAppMode;
private boolean inMovePointMode; private boolean inMovePointMode;
private boolean inAddPointAfterMode; private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode; private boolean inAddPointBeforeMode;
private boolean isInSnapToRoadMode;
private int selectedPointPos = -1; private int selectedPointPos = -1;
private WptPt selectedCachedPoint; private WptPt selectedCachedPoint;
@ -293,7 +293,7 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment(); OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setSnapToRoadEnabled(snapToRoadEnabled); fragment.setSnapToRoadEnabled(isInSnapToRoadMode);
fragment.setListener(createOptionsFragmentListener()); fragment.setListener(createOptionsFragmentListener());
fragment.setAddLineMode(newGpxLine != null); fragment.setAddLineMode(newGpxLine != null);
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
@ -456,7 +456,7 @@ public class MeasurementToolFragment extends Fragment {
enterMeasurementMode(); enterMeasurementMode();
if (snapToRoadEnabled) { if (isInSnapToRoadMode) {
enableSnapToRoadMode(true); enableSnapToRoadMode(true);
} }
@ -547,7 +547,7 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void snapToRoadOnCLick() { public void snapToRoadOnCLick() {
if (!snapToRoadEnabled) { if (!isInSnapToRoadMode) {
showSnapToRoadMenu(true); showSnapToRoadMenu(true);
} else { } else {
disableSnapToRoadMode(); disableSnapToRoadMode();
@ -754,7 +754,7 @@ public class MeasurementToolFragment extends Fragment {
if (snapToRoadAppMode != null) { if (snapToRoadAppMode != null) {
toolBarController.setTopBarSwitchVisible(true); toolBarController.setTopBarSwitchVisible(true);
toolBarController.setTopBarSwitchChecked(true); toolBarController.setTopBarSwitchChecked(true);
snapToRoadEnabled = true; isInSnapToRoadMode = true;
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road)); mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
@ -775,7 +775,7 @@ public class MeasurementToolFragment extends Fragment {
if (measurementPoints.size() > 1) { if (measurementPoints.size() > 1) {
if (!enableAfterRotating) { if (!enableAfterRotating) {
snapToRoadProgressBar.setProgress(0); snapToRoadProgressBar.setProgress(0);
doSnapToRoad(mapActivity); doSnapToRoad();
} }
} }
@ -784,71 +784,74 @@ public class MeasurementToolFragment extends Fragment {
} }
} }
private void doSnapToRoad(final MapActivity mapActivity) { private void doSnapToRoad() {
Location start = new Location(""); MapActivity mapActivity = getMapActivity();
WptPt first = measurementPoints.get(0); if (mapActivity != null) {
start.setLatitude(first.getLatitude()); Location start = new Location("");
start.setLongitude(first.getLongitude()); WptPt first = measurementPoints.get(0);
start.setLatitude(first.getLatitude());
start.setLongitude(first.getLongitude());
WptPt last = measurementPoints.get(measurementPoints.size() - 1); WptPt last = measurementPoints.get(measurementPoints.size() - 1);
LatLon end = new LatLon(last.getLatitude(), last.getLongitude()); LatLon end = new LatLon(last.getLatitude(), last.getLongitude());
List<LatLon> intermediates = new ArrayList<>(); List<LatLon> intermediates = new ArrayList<>();
if (measurementPoints.size() > 2) { if (measurementPoints.size() > 2) {
for (int i = 1; i < measurementPoints.size() - 1; i++) { for (int i = 1; i < measurementPoints.size() - 1; i++) {
WptPt pt = measurementPoints.get(i); WptPt pt = measurementPoints.get(i);
intermediates.add(new LatLon(pt.getLatitude(), pt.getLongitude())); 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() {
@Override
public void updateProgress(int progress) {
snapToRoadProgressBar.setVisibility(View.VISIBLE);
snapToRoadProgressBar.setProgress(progress);
}
@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<WptPt> 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));
}
}
};
mapActivity.getMyApplication().getRoutingHelper().recalculateSnapToRoad(start, end, intermediates, params);
} }
final SnapToRoadParams params = new SnapToRoadParams();
params.applicationMode = snapToRoadAppMode;
params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@Override
public void updateProgress(int progress) {
snapToRoadProgressBar.setVisibility(View.VISIBLE);
snapToRoadProgressBar.setProgress(progress);
}
@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<WptPt> 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));
}
}
};
mapActivity.getMyApplication().getRoutingHelper().recalculateSnapToRoad(start, end, intermediates, params);
} }
private void disableSnapToRoadMode() { private void disableSnapToRoadMode() {
toolBarController.setTopBarSwitchVisible(false); toolBarController.setTopBarSwitchVisible(false);
toolBarController.setTitle(previousToolBarTitle); toolBarController.setTitle(previousToolBarTitle);
snapToRoadEnabled = false; isInSnapToRoadMode = false;
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler)); mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
calculationProgress.isCancelled = true; calculationProgress.isCancelled = true;
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
@ -1571,7 +1574,7 @@ public class MeasurementToolFragment extends Fragment {
if (pointsListOpened) { if (pointsListOpened) {
hidePointsList(); hidePointsList();
} }
if (snapToRoadEnabled) { if (isInSnapToRoadMode) {
disableSnapToRoadMode(); disableSnapToRoadMode();
} }
if (newGpxLine != null) { if (newGpxLine != null) {