Fix few small things

This commit is contained in:
Alex 2017-08-24 17:37:13 +03:00
parent ec0d724f4b
commit f256d9acbb
2 changed files with 13 additions and 14 deletions

View file

@ -11,7 +11,6 @@ import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RouteCalculationParams; import net.osmand.plus.routing.RouteCalculationParams;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.Renderable; import net.osmand.plus.views.Renderable;
@ -26,10 +25,10 @@ import java.util.Queue;
public class MeasurementEditingContext { public class MeasurementEditingContext {
private MapActivity mapActivity; private OsmandApplication application;
private TrkSegment before = new TrkSegment(); private TrkSegment before = new TrkSegment();
// cache should be deleted if after changed or snappedToRoadPoints // cache should be deleted if before changed or snappedToRoadPoints
private TrkSegment beforeCacheForSnap; private TrkSegment beforeCacheForSnap;
private TrkSegment after = new TrkSegment(); private TrkSegment after = new TrkSegment();
@ -49,8 +48,8 @@ public class MeasurementEditingContext {
private List<WptPt> measurementPoints = new LinkedList<>(); private List<WptPt> measurementPoints = new LinkedList<>();
public void setMapActivity(MapActivity mapActivity) { public void setApplication(OsmandApplication application) {
this.mapActivity = mapActivity; this.application = application;
} }
public void setBefore(TrkSegment before) { public void setBefore(TrkSegment before) {
@ -192,7 +191,7 @@ public class MeasurementEditingContext {
} }
public void scheduleRouteCalculateIfNotEmpty(ProgressBar progressBar) { public void scheduleRouteCalculateIfNotEmpty(ProgressBar progressBar) {
if (mapActivity == null || measurementPoints.size() < 1) { if (application == null || measurementPoints.size() < 1) {
return; return;
} }
for (int i = 0; i < measurementPoints.size() - 1; i++) { for (int i = 0; i < measurementPoints.size() - 1; i++) {
@ -203,7 +202,7 @@ public class MeasurementEditingContext {
} }
this.progressBar = progressBar; this.progressBar = progressBar;
if (!snapToRoadPairsToCalculate.isEmpty() && this.progressBar != null) { if (!snapToRoadPairsToCalculate.isEmpty() && this.progressBar != null) {
mapActivity.getMyApplication().getRoutingHelper().startRouteCalculationThread(getParams(), true, true); application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
inSnapToRoadMode = true; inSnapToRoadMode = true;
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
} }
@ -216,8 +215,7 @@ public class MeasurementEditingContext {
} }
private RouteCalculationParams getParams() { private RouteCalculationParams getParams() {
OsmandApplication app = mapActivity.getMyApplication(); OsmandSettings settings = application.getSettings();
OsmandSettings settings = app.getSettings();
final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll(); final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
@ -234,7 +232,7 @@ public class MeasurementEditingContext {
params.fast = settings.FAST_ROUTE_MODE.getModeValue(snapToRoadAppMode); params.fast = settings.FAST_ROUTE_MODE.getModeValue(snapToRoadAppMode);
params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode); params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
params.mode = snapToRoadAppMode; params.mode = snapToRoadAppMode;
params.ctx = app; params.ctx = application;
params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() { params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@Override @Override
@ -249,7 +247,8 @@ public class MeasurementEditingContext {
@Override @Override
public void finish() { public void finish() {
mapActivity.refreshMap(); //todo: create listener, extract progress bar and refresh map
// mapActivity.refreshMap();
} }
}; };
params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() { params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {
@ -265,9 +264,9 @@ public class MeasurementEditingContext {
snappedToRoadPoints.put(currentPair, pts); snappedToRoadPoints.put(currentPair, pts);
if (!snapToRoadPairsToCalculate.isEmpty()) { if (!snapToRoadPairsToCalculate.isEmpty()) {
mapActivity.getMyApplication().getRoutingHelper().startRouteCalculationThread(getParams(), true, true); application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
} else { } else {
mapActivity.getMyApplication().runInUIThread(new Runnable() { application.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);

View file

@ -134,7 +134,7 @@ public class MeasurementToolFragment extends Fragment {
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
editingCtx.setMapActivity(mapActivity); editingCtx.setApplication(mapActivity.getMyApplication());
measurementLayer.setEditingCtx(editingCtx); measurementLayer.setEditingCtx(editingCtx);
if (selectedPointPos != -1 && selectedCachedPoint != null) { if (selectedPointPos != -1 && selectedCachedPoint != null) {