Implementing preservation of impassable roads in progress.
This commit is contained in:
parent
ea373712fe
commit
09e571fcce
5 changed files with 109 additions and 35 deletions
|
@ -141,7 +141,6 @@ public class RoutingConfiguration {
|
||||||
public void removeImpassableRoad(RouteDataObject obj) {
|
public void removeImpassableRoad(RouteDataObject obj) {
|
||||||
impassableRoadLocations.remove(obj.id);
|
impassableRoadLocations.remove(obj.id);
|
||||||
impassableRoads.remove(obj);
|
impassableRoads.remove(obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -15,10 +14,8 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||||
import net.osmand.binary.GeocodingUtilities;
|
import net.osmand.binary.GeocodingUtilities;
|
||||||
import net.osmand.binary.GeocodingUtilities.GeocodingResult;
|
import net.osmand.binary.GeocodingUtilities.GeocodingResult;
|
||||||
import net.osmand.binary.RouteDataObject;
|
import net.osmand.binary.RouteDataObject;
|
||||||
import net.osmand.plus.resources.RegionAddressRepository;
|
|
||||||
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
|
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
|
||||||
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
|
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
|
||||||
import net.osmand.plus.resources.ResourceManager.ResourceListener;
|
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
import net.osmand.router.RoutePlannerFrontEnd;
|
import net.osmand.router.RoutePlannerFrontEnd;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
|
|
|
@ -1609,6 +1609,10 @@ public class OsmandSettings {
|
||||||
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
|
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
|
||||||
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
|
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
|
||||||
|
|
||||||
|
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
|
||||||
|
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
|
||||||
|
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
|
||||||
|
|
||||||
public void backupPointToStart() {
|
public void backupPointToStart() {
|
||||||
settingsAPI.edit(globalPreferences)
|
settingsAPI.edit(globalPreferences)
|
||||||
.putFloat(START_POINT_LAT_BACKUP, settingsAPI.getFloat(globalPreferences, START_POINT_LAT, 0))
|
.putFloat(START_POINT_LAT_BACKUP, settingsAPI.getFloat(globalPreferences, START_POINT_LAT, 0))
|
||||||
|
@ -2041,6 +2045,13 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ImpassableRoadsStorage extends MapPointsStorage {
|
||||||
|
public ImpassableRoadsStorage() {
|
||||||
|
pointsKey = IMPASSABLE_ROAD_POINTS;
|
||||||
|
descriptionsKey = IMPASSABLE_ROADS_DESCRIPTIONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private abstract class MapPointsStorage {
|
private abstract class MapPointsStorage {
|
||||||
|
|
||||||
protected String pointsKey;
|
protected String pointsKey;
|
||||||
|
@ -2119,6 +2130,19 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean deletePoint(LatLon latLon) {
|
||||||
|
List<LatLon> ps = getPoints();
|
||||||
|
List<String> ds = getPointDescriptions(ps.size());
|
||||||
|
int index = ps.indexOf(latLon);
|
||||||
|
if (index != -1) {
|
||||||
|
ps.remove(index);
|
||||||
|
ds.remove(index);
|
||||||
|
return savePoints(ps, ds);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean savePoints(List<LatLon> ps, List<String> ds) {
|
public boolean savePoints(List<LatLon> ps, List<String> ds) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < ps.size(); i++) {
|
for (int i = 0; i < ps.size(); i++) {
|
||||||
|
@ -2143,6 +2167,18 @@ public class OsmandSettings {
|
||||||
.putString(descriptionsKey, tb.toString())
|
.putString(descriptionsKey, tb.toString())
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
|
||||||
|
List<LatLon> ps = getPoints();
|
||||||
|
List<String> ds = getPointDescriptions(ps.size());
|
||||||
|
int i = ps.indexOf(latLonEx);
|
||||||
|
if (i != -1) {
|
||||||
|
ps.set(i, latLonNew);
|
||||||
|
return savePoints(ps, ds);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2292,6 +2328,24 @@ 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() {
|
||||||
|
return mImpassableRoadsStorage.getPoints();
|
||||||
|
}
|
||||||
|
public boolean addImpassableRoad(double latitude, double longitude) {
|
||||||
|
return mImpassableRoadsStorage.insertPoint(latitude, longitude, null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteImpassableRoad(int index) {
|
||||||
|
return mImpassableRoadsStorage.deletePoint(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteImpassableRoad(LatLon latLon) {
|
||||||
|
return mImpassableRoadsStorage.deletePoint(latLon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean moveImpassableRoad(LatLon latLonEx, LatLon latLonNew) {
|
||||||
|
return mImpassableRoadsStorage.movePoint(latLonEx, latLonNew);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the location of a parked car
|
* the location of a parked car
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package net.osmand.plus.helpers;
|
package net.osmand.plus.helpers;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -36,6 +38,10 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
public AvoidSpecificRoads(OsmandApplication app) {
|
public AvoidSpecificRoads(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
List<LatLon> impassibleRoads = app.getSettings().getImpassableRoadPoints();
|
||||||
|
for (LatLon impassibleRoad : impassibleRoads) {
|
||||||
|
addImpassableRoad(null, impassibleRoad, false, null, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RouteDataObject> getMissingRoads() {
|
public List<RouteDataObject> getMissingRoads() {
|
||||||
|
@ -80,6 +86,7 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
app.getSettings().deleteImpassableRoad(getLocation(obj));
|
||||||
remove(obj);
|
remove(obj);
|
||||||
getBuilder().removeImpassableRoad(obj);
|
getBuilder().removeImpassableRoad(obj);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
@ -91,8 +98,6 @@ public class AvoidSpecificRoads {
|
||||||
});
|
});
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +107,7 @@ public class AvoidSpecificRoads {
|
||||||
obj.getRef(), obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get()), app.getString(R.string.towards));
|
obj.getRef(), obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get()), app.getString(R.string.towards));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(final MapActivity mapActivity) {
|
public void showDialog(@NonNull final MapActivity mapActivity) {
|
||||||
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
|
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
|
||||||
bld.setTitle(R.string.impassable_road);
|
bld.setTitle(R.string.impassable_road);
|
||||||
if (getMissingRoads().size() == 0) {
|
if (getMissingRoads().size() == 0) {
|
||||||
|
@ -138,15 +143,18 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean processResult(LatLon result) {
|
public boolean processResult(LatLon result) {
|
||||||
addImpassableRoad(mapActivity, result, true, null);
|
addImpassableRoad(mapActivity, result, true, null, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addImpassableRoad(final MapActivity activity, final LatLon loc,
|
public void addImpassableRoad(@Nullable final MapActivity activity,
|
||||||
final boolean showDialog, final AvoidSpecificRoadsCallback callback) {
|
@NonNull final LatLon loc,
|
||||||
|
final boolean showDialog,
|
||||||
|
@Nullable final AvoidSpecificRoadsCallback callback,
|
||||||
|
final boolean skipWritingSettings) {
|
||||||
final Location ll = new Location("");
|
final Location ll = new Location("");
|
||||||
ll.setLatitude(loc.getLatitude());
|
ll.setLatitude(loc.getLatitude());
|
||||||
ll.setLongitude(loc.getLongitude());
|
ll.setLongitude(loc.getLongitude());
|
||||||
|
@ -155,7 +163,9 @@ public class AvoidSpecificRoads {
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(RouteDataObject object) {
|
public boolean publish(RouteDataObject object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
|
if (activity != null) {
|
||||||
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.onAddImpassableRoad(false, null);
|
callback.onAddImpassableRoad(false, null);
|
||||||
}
|
}
|
||||||
|
@ -171,18 +181,22 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
if (callback != null) {
|
return callback != null && callback.isCancelled();
|
||||||
return callback.isCancelled();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (!skipWritingSettings) {
|
||||||
|
app.getSettings().addImpassableRoad(loc.getLatitude(), loc.getLongitude());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceImpassableRoad(final MapActivity activity, final RouteDataObject currentObject,
|
public void replaceImpassableRoad(final MapActivity activity, final RouteDataObject currentObject,
|
||||||
final LatLon loc, final boolean showDialog,
|
final LatLon loc, final boolean showDialog,
|
||||||
final AvoidSpecificRoadsCallback callback) {
|
final AvoidSpecificRoadsCallback callback) {
|
||||||
|
|
||||||
|
LatLon latLon = getLocation(currentObject);
|
||||||
|
app.getSettings().moveImpassableRoad(latLon, loc);
|
||||||
|
|
||||||
final Location ll = new Location("");
|
final Location ll = new Location("");
|
||||||
ll.setLatitude(loc.getLatitude());
|
ll.setLatitude(loc.getLatitude());
|
||||||
ll.setLongitude(loc.getLongitude());
|
ll.setLongitude(loc.getLongitude());
|
||||||
|
@ -213,16 +227,20 @@ public class AvoidSpecificRoads {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addImpassableRoadInternal(RouteDataObject object, Location ll, boolean showDialog, MapActivity activity, LatLon loc) {
|
private void addImpassableRoadInternal(@NonNull RouteDataObject object,
|
||||||
|
@NonNull Location ll,
|
||||||
|
boolean showDialog,
|
||||||
|
@Nullable MapActivity activity,
|
||||||
|
@NonNull LatLon loc) {
|
||||||
getBuilder().addImpassableRoad(object, ll);
|
getBuilder().addImpassableRoad(object, ll);
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||||
rh.recalculateRouteDueToSettingsChange();
|
rh.recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
|
if (activity != null) {
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
showDialog(activity);
|
showDialog(activity);
|
||||||
}
|
}
|
||||||
|
@ -232,6 +250,7 @@ public class AvoidSpecificRoads {
|
||||||
}
|
}
|
||||||
activity.refreshMap();
|
activity.refreshMap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showOnMap(MapActivity ctx, double lat, double lon, String name,
|
private void showOnMap(MapActivity ctx, double lat, double lon, String name,
|
||||||
DialogInterface dialog) {
|
DialogInterface dialog) {
|
||||||
|
@ -247,6 +266,11 @@ public class AvoidSpecificRoads {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LatLon getLocation(RouteDataObject object) {
|
||||||
|
Location location = app.getDefaultRoutingConfig().getImpassableRoadLocations().get(object.getId());
|
||||||
|
return new LatLon(location.getLatitude(), location.getLongitude());
|
||||||
|
}
|
||||||
|
|
||||||
public interface AvoidSpecificRoadsCallback {
|
public interface AvoidSpecificRoadsCallback {
|
||||||
|
|
||||||
void onAddImpassableRoad(boolean success, RouteDataObject newObject);
|
void onAddImpassableRoad(boolean success, RouteDataObject newObject);
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
|
||||||
if (itemId == R.string.avoid_road) {
|
if (itemId == R.string.avoid_road) {
|
||||||
activity.getMyApplication().getAvoidSpecificRoads().addImpassableRoad(
|
activity.getMyApplication().getAvoidSpecificRoads().addImpassableRoad(
|
||||||
activity, latLon, false, null);
|
activity, latLon, false, null, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue