Avoid saved roads initial commit
This commit is contained in:
parent
5a731b8b04
commit
bd0d4a9c9e
8 changed files with 91 additions and 84 deletions
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.router;
|
package net.osmand.router;
|
||||||
|
|
||||||
import net.osmand.Location;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.binary.RouteDataObject;
|
import net.osmand.binary.RouteDataObject;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
|
@ -13,8 +12,10 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public class RoutingConfiguration {
|
||||||
private String defaultRouter = "";
|
private String defaultRouter = "";
|
||||||
private Map<String, GeneralRouter> routers = new LinkedHashMap<>();
|
private Map<String, GeneralRouter> routers = new LinkedHashMap<>();
|
||||||
private Map<String, String> attributes = new LinkedHashMap<>();
|
private Map<String, String> attributes = new LinkedHashMap<>();
|
||||||
private HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
|
private List<Long> impassableRoadLocations = new ArrayList<>();
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ public class RoutingConfiguration {
|
||||||
i.initialDirection = direction;
|
i.initialDirection = direction;
|
||||||
i.recalculateDistance = parseSilentFloat(getAttribute(i.router, "recalculateDistanceHelp"), i.recalculateDistance) ;
|
i.recalculateDistance = parseSilentFloat(getAttribute(i.router, "recalculateDistanceHelp"), i.recalculateDistance) ;
|
||||||
i.heuristicCoefficient = parseSilentFloat(getAttribute(i.router, "heuristicCoefficient"), i.heuristicCoefficient);
|
i.heuristicCoefficient = parseSilentFloat(getAttribute(i.router, "heuristicCoefficient"), i.heuristicCoefficient);
|
||||||
i.router.addImpassableRoads(impassableRoadLocations.keySet());
|
i.router.addImpassableRoads(new HashSet<>(impassableRoadLocations));
|
||||||
i.ZOOM_TO_LOAD_TILES = parseSilentInt(getAttribute(i.router, "zoomToLoadTiles"), i.ZOOM_TO_LOAD_TILES);
|
i.ZOOM_TO_LOAD_TILES = parseSilentInt(getAttribute(i.router, "zoomToLoadTiles"), i.ZOOM_TO_LOAD_TILES);
|
||||||
int desirable = parseSilentInt(getAttribute(i.router, "memoryLimitInMB"), 0);
|
int desirable = parseSilentInt(getAttribute(i.router, "memoryLimitInMB"), 0);
|
||||||
if(desirable != 0) {
|
if(desirable != 0) {
|
||||||
|
@ -111,13 +112,13 @@ public class RoutingConfiguration {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, Location> getImpassableRoadLocations() {
|
public List<Long> getImpassableRoadLocations() {
|
||||||
return impassableRoadLocations;
|
return impassableRoadLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addImpassableRoad(RouteDataObject route, Location location) {
|
public boolean addImpassableRoad(RouteDataObject route) {
|
||||||
if (!impassableRoadLocations.containsKey(route.id)){
|
if (!impassableRoadLocations.contains(route.id)) {
|
||||||
impassableRoadLocations.put(route.id, location);
|
impassableRoadLocations.add(route.id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -159,8 +160,8 @@ public class RoutingConfiguration {
|
||||||
return routers;
|
return routers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeImpassableRoad(RouteDataObject obj) {
|
public void removeImpassableRoad(long routeId) {
|
||||||
impassableRoadLocations.remove(obj.id);
|
impassableRoadLocations.remove(routeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -739,7 +739,7 @@ public class AppInitializer implements IProgress {
|
||||||
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
||||||
app.mapMarkersHelper.syncAllGroupsAsync();
|
app.mapMarkersHelper.syncAllGroupsAsync();
|
||||||
app.searchUICore.initSearchUICore();
|
app.searchUICore.initSearchUICore();
|
||||||
app.avoidSpecificRoads.initRouteObjects();
|
app.avoidSpecificRoads.initRouteObjects(false);
|
||||||
|
|
||||||
checkLiveUpdatesAlerts();
|
checkLiveUpdatesAlerts();
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import net.osmand.plus.api.SettingsAPI;
|
||||||
import net.osmand.plus.api.SettingsAPI.SettingsEditor;
|
import net.osmand.plus.api.SettingsAPI.SettingsEditor;
|
||||||
import net.osmand.plus.api.SettingsAPIImpl;
|
import net.osmand.plus.api.SettingsAPIImpl;
|
||||||
import net.osmand.plus.dialogs.RateUsBottomSheetDialogFragment;
|
import net.osmand.plus.dialogs.RateUsBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||||
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
|
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
|
||||||
|
@ -2627,6 +2628,7 @@ public class OsmandSettings {
|
||||||
|
|
||||||
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
|
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
|
||||||
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
|
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
|
||||||
|
private static final String IMPASSABLE_ROADS_IDS = "impassable_roads_ids";
|
||||||
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
|
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
|
||||||
|
|
||||||
public void backupPointToStart() {
|
public void backupPointToStart() {
|
||||||
|
@ -2989,11 +2991,11 @@ public class OsmandSettings {
|
||||||
return settingsAPI.edit(globalPreferences).putInt(POINT_NAVIGATE_ROUTE, NAVIGATE).commit();
|
return settingsAPI.edit(globalPreferences).putInt(POINT_NAVIGATE_ROUTE, NAVIGATE).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LatLon> getImpassableRoadPoints() {
|
public List<AvoidRoadInfo> getImpassableRoadPoints() {
|
||||||
return mImpassableRoadsStorage.getPoints();
|
return mImpassableRoadsStorage.getImpassableRoadsInfo();
|
||||||
}
|
}
|
||||||
public boolean addImpassableRoad(double latitude, double longitude) {
|
public boolean addImpassableRoad(AvoidRoadInfo avoidRoadInfo) {
|
||||||
return mImpassableRoadsStorage.insertPoint(latitude, longitude, null, 0);
|
return mImpassableRoadsStorage.addImpassableRoadInfo(avoidRoadInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeImpassableRoad(int index) {
|
public boolean removeImpassableRoad(int index) {
|
||||||
|
|
|
@ -50,22 +50,24 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
private Map<LatLon, RouteDataObject> impassableRoads = new LinkedHashMap<>();
|
private Map<LatLon, AvoidRoadInfo> impassableRoads = new LinkedHashMap<>();
|
||||||
|
|
||||||
public AvoidSpecificRoads(final OsmandApplication app) {
|
public AvoidSpecificRoads(final OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
for (LatLon latLon : app.getSettings().getImpassableRoadPoints()) {
|
for (AvoidRoadInfo avoidRoadInfo : app.getSettings().getImpassableRoadPoints()) {
|
||||||
impassableRoads.put(latLon, null);
|
impassableRoads.put(new LatLon(avoidRoadInfo.lat, avoidRoadInfo.lon), avoidRoadInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<LatLon, RouteDataObject> getImpassableRoads() {
|
public Map<LatLon, AvoidRoadInfo> getImpassableRoads() {
|
||||||
return impassableRoads;
|
return impassableRoads;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initRouteObjects() {
|
public void initRouteObjects(boolean force) {
|
||||||
for (LatLon latLon : impassableRoads.keySet()) {
|
for (Map.Entry<LatLon, AvoidRoadInfo> entry : impassableRoads.entrySet()) {
|
||||||
addImpassableRoad(null, latLon, false, true);
|
if (force || entry.getValue().id == 0) {
|
||||||
|
addImpassableRoad(null, entry.getKey(), false, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,25 +119,15 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
public String getText(@Nullable LatLon point) {
|
public String getText(@Nullable LatLon point) {
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
RouteDataObject obj = impassableRoads.get(point);
|
AvoidRoadInfo obj = impassableRoads.get(point);
|
||||||
if (obj != null) {
|
if (obj != null && !TextUtils.isEmpty(obj.name)) {
|
||||||
String locale = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
return obj.name;
|
||||||
boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
|
||||||
String name = RoutingHelper.formatStreetName(
|
|
||||||
obj.getName(locale, transliterate),
|
|
||||||
obj.getRef(locale, transliterate, true),
|
|
||||||
obj.getDestinationName(locale, transliterate, true),
|
|
||||||
app.getString(R.string.towards)
|
|
||||||
);
|
|
||||||
if (!TextUtils.isEmpty(name)) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return app.getString(R.string.shared_string_road);
|
return app.getString(R.string.shared_string_road);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText(@Nullable RouteDataObject obj) {
|
public String getRoadName(@Nullable RouteDataObject obj) {
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
String locale = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
String locale = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
||||||
boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
||||||
|
@ -347,21 +339,35 @@ public class AvoidSpecificRoads {
|
||||||
MapActivity.launchMapActivityMoveToTop(ctx);
|
MapActivity.launchMapActivityMoveToTop(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LatLon getLocation(RouteDataObject object) {
|
public LatLon getLocation(AvoidRoadInfo avoidRoadInfo) {
|
||||||
Location location = null;
|
|
||||||
for (RoutingConfiguration.Builder builder : app.getAllRoutingConfigs()) {
|
for (RoutingConfiguration.Builder builder : app.getAllRoutingConfigs()) {
|
||||||
location = builder.getImpassableRoadLocations().get(object.getId());
|
if (builder.getImpassableRoadLocations().contains(avoidRoadInfo.id)) {
|
||||||
if (location != null) {
|
return new LatLon(avoidRoadInfo.lat, avoidRoadInfo.lon);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return location == null ? null : new LatLon(location.getLatitude(), location.getLongitude());
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface AvoidSpecificRoadsCallback {
|
public interface AvoidSpecificRoadsCallback {
|
||||||
|
|
||||||
void onAddImpassableRoad(boolean success, RouteDataObject newObject);
|
void onAddImpassableRoad(boolean success, AvoidRoadInfo avoidRoadInfo);
|
||||||
|
|
||||||
boolean isCancelled();
|
boolean isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AvoidRoadInfo createAvoidRoadInfo(@Nullable RouteDataObject object, double lat, double lon) {
|
||||||
|
AvoidRoadInfo avoidRoadInfo = new AvoidRoadInfo();
|
||||||
|
avoidRoadInfo.id = object != null ? object.id : 0;
|
||||||
|
avoidRoadInfo.lat = lat;
|
||||||
|
avoidRoadInfo.lon = lon;
|
||||||
|
avoidRoadInfo.name = getRoadName(object);
|
||||||
|
return avoidRoadInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AvoidRoadInfo {
|
||||||
|
public long id;
|
||||||
|
public double lat;
|
||||||
|
public double lon;
|
||||||
|
public String name;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,6 @@ import net.osmand.PlatformUtil;
|
||||||
import net.osmand.aidl.AidlMapPointWrapper;
|
import net.osmand.aidl.AidlMapPointWrapper;
|
||||||
import net.osmand.binary.BinaryMapDataObject;
|
import net.osmand.binary.BinaryMapDataObject;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||||
import net.osmand.binary.RouteDataObject;
|
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -45,6 +44,7 @@ import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread;
|
import net.osmand.plus.download.DownloadIndexesThread;
|
||||||
import net.osmand.plus.download.DownloadValidationManager;
|
import net.osmand.plus.download.DownloadValidationManager;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener;
|
||||||
|
@ -220,8 +220,8 @@ public abstract class MenuController extends BaseMenuController implements Colla
|
||||||
} else if (pointDescription.isMyLocation()) {
|
} else if (pointDescription.isMyLocation()) {
|
||||||
menuController = new MyLocationMenuController(mapActivity, pointDescription);
|
menuController = new MyLocationMenuController(mapActivity, pointDescription);
|
||||||
}
|
}
|
||||||
} else if (object instanceof RouteDataObject) {
|
} else if (object instanceof AvoidSpecificRoads.AvoidRoadInfo) {
|
||||||
menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object);
|
menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (AvoidSpecificRoads.AvoidRoadInfo) object);
|
||||||
} else if (object instanceof RenderedObject) {
|
} else if (object instanceof RenderedObject) {
|
||||||
menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
|
menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
|
||||||
} else if (object instanceof MapillaryImage) {
|
} else if (object instanceof MapillaryImage) {
|
||||||
|
|
|
@ -4,24 +4,24 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
import net.osmand.binary.RouteDataObject;
|
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
|
|
||||||
public class ImpassibleRoadsMenuController extends MenuController {
|
public class ImpassibleRoadsMenuController extends MenuController {
|
||||||
|
|
||||||
private RouteDataObject route;
|
private AvoidRoadInfo avoidRoadInfo;
|
||||||
|
|
||||||
public ImpassibleRoadsMenuController(@NonNull MapActivity mapActivity,
|
public ImpassibleRoadsMenuController(@NonNull MapActivity mapActivity,
|
||||||
@NonNull PointDescription pointDescription,
|
@NonNull PointDescription pointDescription,
|
||||||
@NonNull RouteDataObject route) {
|
@NonNull AvoidRoadInfo avoidRoadInfo) {
|
||||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||||
this.route = route;
|
this.avoidRoadInfo = avoidRoadInfo;
|
||||||
final OsmandApplication app = mapActivity.getMyApplication();
|
final OsmandApplication app = mapActivity.getMyApplication();
|
||||||
leftTitleButtonController = new TitleButtonController() {
|
leftTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,7 +29,7 @@ public class ImpassibleRoadsMenuController extends MenuController {
|
||||||
MapActivity activity = getMapActivity();
|
MapActivity activity = getMapActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
app.getAvoidSpecificRoads().removeImpassableRoad(
|
app.getAvoidSpecificRoads().removeImpassableRoad(
|
||||||
ImpassibleRoadsMenuController.this.route);
|
ImpassibleRoadsMenuController.this.avoidRoadInfo);
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||||
rh.recalculateRouteDueToSettingsChange();
|
rh.recalculateRouteDueToSettingsChange();
|
||||||
|
@ -44,12 +44,12 @@ public class ImpassibleRoadsMenuController extends MenuController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setObject(Object object) {
|
protected void setObject(Object object) {
|
||||||
route = (RouteDataObject) object;
|
avoidRoadInfo = (AvoidRoadInfo) object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object getObject() {
|
protected Object getObject() {
|
||||||
return route;
|
return avoidRoadInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -38,7 +38,6 @@ import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
import net.osmand.binary.RouteDataObject;
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
|
@ -67,6 +66,7 @@ import net.osmand.plus.base.ContextMenuFragment.MenuState;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.helpers.WaypointHelper;
|
import net.osmand.plus.helpers.WaypointHelper;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
|
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
|
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
|
@ -110,13 +110,13 @@ import org.apache.commons.logging.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener, FavoritesListener {
|
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener, FavoritesListener {
|
||||||
|
|
||||||
|
@ -1204,7 +1204,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
||||||
final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
|
final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
|
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
|
||||||
Map<LatLon, RouteDataObject> impassableRoads = new TreeMap<>();
|
Map<LatLon, AvoidRoadInfo> impassableRoads = new HashMap<>();
|
||||||
if (parameter instanceof AvoidRoadsRoutingParameter) {
|
if (parameter instanceof AvoidRoadsRoutingParameter) {
|
||||||
impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
||||||
}
|
}
|
||||||
|
@ -1232,22 +1232,19 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
||||||
return avoidedParameters;
|
return avoidedParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createImpassableRoadsItems(MapActivity mapActivity, Map<LatLon, RouteDataObject> impassableRoads, final LocalRoutingParameter parameter, final RouteMenuAppModes mode, final LinearLayout item) {
|
private void createImpassableRoadsItems(MapActivity mapActivity, Map<LatLon, AvoidRoadInfo> impassableRoads,
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
final LocalRoutingParameter parameter, final RouteMenuAppModes mode, final LinearLayout item) {
|
||||||
Iterator<RouteDataObject> it = impassableRoads.values().iterator();
|
Iterator<AvoidRoadInfo> it = impassableRoads.values().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final RouteDataObject routeDataObject = it.next();
|
final AvoidRoadInfo avoidRoadInfo = it.next();
|
||||||
final View container = createToolbarSubOptionView(false, app.getAvoidSpecificRoads().getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
|
final View container = createToolbarSubOptionView(false, avoidRoadInfo.name, R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
app.getAvoidSpecificRoads().removeImpassableRoad(avoidRoadInfo);
|
||||||
if (routeDataObject != null) {
|
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||||
app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject);
|
|
||||||
}
|
|
||||||
routingHelper.recalculateRouteDueToSettingsChange();
|
|
||||||
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && getAvoidedParameters(app).isEmpty()) {
|
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && getAvoidedParameters(app).isEmpty()) {
|
||||||
mode.parameters.remove(parameter);
|
mode.parameters.remove(parameter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.graphics.PointF;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.binary.RouteDataObject;
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
|
@ -18,6 +17,7 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback;
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback;
|
||||||
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||||
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
if (contextMenuLayer.getMoveableObject() instanceof AvoidRoadInfo) {
|
||||||
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
||||||
drawPoint(canvas, pf.x, pf.y, true);
|
drawPoint(canvas, pf.x, pf.y, true);
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,11 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
@Override
|
@Override
|
||||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||||
if (tileBox.getZoom() >= START_ZOOM) {
|
if (tileBox.getZoom() >= START_ZOOM) {
|
||||||
for (Map.Entry<LatLon, RouteDataObject> entry : avoidSpecificRoads.getImpassableRoads().entrySet()) {
|
for (Map.Entry<LatLon, AvoidRoadInfo> entry : avoidSpecificRoads.getImpassableRoads().entrySet()) {
|
||||||
LatLon location = entry.getKey();
|
LatLon location = entry.getKey();
|
||||||
RouteDataObject road = entry.getValue();
|
AvoidRoadInfo road = entry.getValue();
|
||||||
if (road != null && contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
if (road != null && contextMenuLayer.getMoveableObject() instanceof AvoidRoadInfo) {
|
||||||
RouteDataObject object = (RouteDataObject) contextMenuLayer.getMoveableObject();
|
AvoidRoadInfo object = (AvoidRoadInfo) contextMenuLayer.getMoveableObject();
|
||||||
if (object.id == road.id) {
|
if (object.id == road.id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -146,9 +146,9 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
int compare = getRadiusPoi(tileBox);
|
int compare = getRadiusPoi(tileBox);
|
||||||
int radius = compare * 3 / 2;
|
int radius = compare * 3 / 2;
|
||||||
|
|
||||||
for (Map.Entry<LatLon, RouteDataObject> entry : avoidSpecificRoads.getImpassableRoads().entrySet()) {
|
for (Map.Entry<LatLon, AvoidRoadInfo> entry : avoidSpecificRoads.getImpassableRoads().entrySet()) {
|
||||||
LatLon location = entry.getKey();
|
LatLon location = entry.getKey();
|
||||||
RouteDataObject road = entry.getValue();
|
AvoidRoadInfo road = entry.getValue();
|
||||||
if (location != null && road != null) {
|
if (location != null && road != null) {
|
||||||
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
||||||
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
||||||
|
@ -163,36 +163,37 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LatLon getObjectLocation(Object o) {
|
public LatLon getObjectLocation(Object o) {
|
||||||
if (o instanceof RouteDataObject) {
|
if (o instanceof AvoidRoadInfo) {
|
||||||
return avoidSpecificRoads.getLocation((RouteDataObject) o);
|
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) o;
|
||||||
|
return new LatLon(avoidRoadInfo.lat, avoidRoadInfo.lon);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PointDescription getObjectName(Object o) {
|
public PointDescription getObjectName(Object o) {
|
||||||
if (o instanceof RouteDataObject) {
|
if (o instanceof AvoidRoadInfo) {
|
||||||
RouteDataObject route = (RouteDataObject) o;
|
AvoidRoadInfo route = (AvoidRoadInfo) o;
|
||||||
return new PointDescription(PointDescription.POINT_TYPE_BLOCKED_ROAD, route.getName());
|
return new PointDescription(PointDescription.POINT_TYPE_BLOCKED_ROAD, route.name);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isObjectMovable(Object o) {
|
public boolean isObjectMovable(Object o) {
|
||||||
return o instanceof RouteDataObject;
|
return o instanceof AvoidRoadInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyNewObjectPosition(@NonNull Object o,
|
public void applyNewObjectPosition(@NonNull Object o,
|
||||||
@NonNull LatLon position,
|
@NonNull LatLon position,
|
||||||
@Nullable final ApplyMovedObjectCallback callback) {
|
@Nullable final ApplyMovedObjectCallback callback) {
|
||||||
if (o instanceof RouteDataObject) {
|
if (o instanceof AvoidRoadInfo) {
|
||||||
final RouteDataObject object = (RouteDataObject) o;
|
final AvoidRoadInfo object = (AvoidRoadInfo) o;
|
||||||
final OsmandApplication application = activity.getMyApplication();
|
final OsmandApplication application = activity.getMyApplication();
|
||||||
application.getAvoidSpecificRoads().replaceImpassableRoad(activity, object, position, false, new AvoidSpecificRoadsCallback() {
|
application.getAvoidSpecificRoads().replaceImpassableRoad(activity, object, position, false, new AvoidSpecificRoadsCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onAddImpassableRoad(boolean success, RouteDataObject newObject) {
|
public void onAddImpassableRoad(boolean success, AvoidRoadInfo newObject) {
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.onApplyMovedObject(success, newObject);
|
callback.onApplyMovedObject(success, newObject);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue