Implemented preservation of impassable roads.
This commit is contained in:
parent
d21f313a22
commit
7e814fdb4a
5 changed files with 67 additions and 21 deletions
|
@ -113,11 +113,13 @@ public class RoutingConfiguration {
|
|||
return impassableRoadLocations;
|
||||
}
|
||||
|
||||
public void addImpassableRoad(RouteDataObject route, Location location) {
|
||||
public boolean addImpassableRoad(RouteDataObject route, Location location) {
|
||||
if (!impassableRoadLocations.containsKey(route.id)){
|
||||
impassableRoadLocations.put(route.id, location);
|
||||
impassableRoads.add(route);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2335,11 +2335,11 @@ public class OsmandSettings {
|
|||
return mImpassableRoadsStorage.insertPoint(latitude, longitude, null, 0);
|
||||
}
|
||||
|
||||
public boolean deleteImpassableRoad(int index) {
|
||||
public boolean removeImpassableRoad(int index) {
|
||||
return mImpassableRoadsStorage.deletePoint(index);
|
||||
}
|
||||
|
||||
public boolean deleteImpassableRoad(LatLon latLon) {
|
||||
public boolean removeImpassableRoad(LatLon latLon) {
|
||||
return mImpassableRoadsStorage.deletePoint(latLon);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ public class AvoidSpecificRoads {
|
|||
|
||||
public AvoidSpecificRoads(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public void initPreservedData() {
|
||||
List<LatLon> impassibleRoads = app.getSettings().getImpassableRoadPoints();
|
||||
for (LatLon impassibleRoad : impassibleRoads) {
|
||||
addImpassableRoad(null, impassibleRoad, false, null, true);
|
||||
|
@ -56,7 +59,7 @@ public class AvoidSpecificRoads {
|
|||
}
|
||||
|
||||
public ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
|
||||
final ArrayList<RouteDataObject> points = new ArrayList<RouteDataObject>();
|
||||
final ArrayList<RouteDataObject> points = new ArrayList<>();
|
||||
points.addAll(getMissingRoads());
|
||||
final LatLon mapLocation = ctx.getMapLocation();
|
||||
return new ArrayAdapter<RouteDataObject>(ctx,
|
||||
|
@ -67,7 +70,7 @@ public class AvoidSpecificRoads {
|
|||
// User super class to create the View
|
||||
View v = convertView;
|
||||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
|
||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, parent, false);
|
||||
}
|
||||
final RouteDataObject obj = getItem(position);
|
||||
v.findViewById(R.id.all_points).setVisibility(View.GONE);
|
||||
|
@ -86,9 +89,8 @@ public class AvoidSpecificRoads {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().deleteImpassableRoad(getLocation(obj));
|
||||
remove(obj);
|
||||
getBuilder().removeImpassableRoad(obj);
|
||||
removeImpassableRoad(obj);
|
||||
notifyDataSetChanged();
|
||||
RoutingHelper rh = app.getRoutingHelper();
|
||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||
|
@ -101,6 +103,11 @@ public class AvoidSpecificRoads {
|
|||
};
|
||||
}
|
||||
|
||||
public void removeImpassableRoad(RouteDataObject obj) {
|
||||
app.getSettings().removeImpassableRoad(getLocation(obj));
|
||||
getBuilder().removeImpassableRoad(obj);
|
||||
}
|
||||
|
||||
|
||||
protected String getText(RouteDataObject obj) {
|
||||
return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get()),
|
||||
|
@ -222,10 +229,7 @@ public class AvoidSpecificRoads {
|
|||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
if (callback != null) {
|
||||
return callback.isCancelled();
|
||||
}
|
||||
return false;
|
||||
return callback != null && callback.isCancelled();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -235,7 +239,9 @@ public class AvoidSpecificRoads {
|
|||
boolean showDialog,
|
||||
@Nullable MapActivity activity,
|
||||
@NonNull LatLon loc) {
|
||||
getBuilder().addImpassableRoad(object, ll);
|
||||
if(!getBuilder().addImpassableRoad(object, ll)) {
|
||||
app.getSettings().removeImpassableRoad(getLocation(object));
|
||||
}
|
||||
RoutingHelper rh = app.getRoutingHelper();
|
||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||
rh.recalculateRouteDueToSettingsChange();
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ImpassibleRoadsMenuController extends MenuController {
|
|||
rightTitleButtonController = new TitleButtonController() {
|
||||
@Override
|
||||
public void buttonPressed() {
|
||||
app.getDefaultRoutingConfig().removeImpassableRoad(
|
||||
app.getAvoidSpecificRoads().removeImpassableRoad(
|
||||
ImpassibleRoadsMenuController.this.route);
|
||||
RoutingHelper rh = app.getRoutingHelper();
|
||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||
|
|
|
@ -23,8 +23,10 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||
ContextMenuLayer.IContextMenuProvider, ContextMenuLayer.IMoveObjectProvider {
|
||||
|
@ -40,6 +42,8 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
||||
private Set<PreservedRoadDataObject> mPreservedRoadDataObjects;
|
||||
|
||||
public ImpassableRoadsLayer(MapActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
@ -52,15 +56,19 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
routingHelper = activity.getRoutingHelper();
|
||||
|
||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
|
||||
List<LatLon> impassibleRoads = activity.getMyApplication().getSettings().getImpassableRoadPoints();
|
||||
mPreservedRoadDataObjects = new HashSet<>(impassibleRoads.size());
|
||||
for (LatLon impassibleRoad : impassibleRoads) {
|
||||
mPreservedRoadDataObjects.add(new PreservedRoadDataObject(impassibleRoad));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
||||
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
||||
float left = pf.x - roadWorkIcon.getWidth() / 2;
|
||||
float top = pf.y - roadWorkIcon.getHeight();
|
||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||
drawPoint(canvas, pf.x, pf.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,15 +83,29 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
}
|
||||
}
|
||||
Location location = getMissingRoadLocations().get(id);
|
||||
float x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||
float left = x - roadWorkIcon.getWidth() / 2;
|
||||
float top = y - roadWorkIcon.getHeight();
|
||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||
final double latitude = location.getLatitude();
|
||||
final double longitude = location.getLongitude();
|
||||
drawPoint(canvas, tileBox, latitude, longitude);
|
||||
}
|
||||
for (PreservedRoadDataObject preservedRoadDataObject : mPreservedRoadDataObjects) {
|
||||
final LatLon latLon = preservedRoadDataObject.getLatLon();
|
||||
drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, double latitude, double longitude) {
|
||||
float x = tileBox.getPixXFromLatLon(latitude, longitude);
|
||||
float y = tileBox.getPixYFromLatLon(latitude, longitude);
|
||||
drawPoint(canvas, x, y);
|
||||
}
|
||||
|
||||
private void drawPoint(Canvas canvas, float x, float y) {
|
||||
float left = x - roadWorkIcon.getWidth() / 2;
|
||||
float top = y - roadWorkIcon.getHeight();
|
||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||
}
|
||||
|
||||
public Map<Long, Location> getMissingRoadLocations() {
|
||||
if (missingRoadLocations == null) {
|
||||
missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||
|
@ -155,6 +177,10 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!mPreservedRoadDataObjects.isEmpty()) {
|
||||
activity.getMyApplication().getAvoidSpecificRoads().initPreservedData();
|
||||
mPreservedRoadDataObjects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,4 +252,16 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static class PreservedRoadDataObject {
|
||||
private final LatLon mLatLon;
|
||||
|
||||
private PreservedRoadDataObject(LatLon latLon) {
|
||||
this.mLatLon = latLon;
|
||||
}
|
||||
|
||||
public LatLon getLatLon() {
|
||||
return mLatLon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue