Add direction to avoid roads
This commit is contained in:
parent
425b98c6dc
commit
c20c0aa6e7
6 changed files with 114 additions and 29 deletions
|
@ -7,16 +7,18 @@ import net.osmand.aidlapi.AidlParams;
|
||||||
|
|
||||||
public class ABlockedRoadParams extends AidlParams {
|
public class ABlockedRoadParams extends AidlParams {
|
||||||
|
|
||||||
public long roadId;
|
private long roadId;
|
||||||
public double latitude;
|
private double latitude;
|
||||||
public double longitude;
|
private double longitude;
|
||||||
public String name;
|
private double direction;
|
||||||
public String appModeKey;
|
private String name;
|
||||||
|
private String appModeKey;
|
||||||
|
|
||||||
public ABlockedRoadParams(long roadId, double latitude, double longitude, String name, String appModeKey) {
|
public ABlockedRoadParams(long roadId, double latitude, double longitude, double direction, String name, String appModeKey) {
|
||||||
this.roadId = roadId;
|
this.roadId = roadId;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
|
this.direction = direction;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.appModeKey = appModeKey;
|
this.appModeKey = appModeKey;
|
||||||
}
|
}
|
||||||
|
@ -37,11 +39,36 @@ public class ABlockedRoadParams extends AidlParams {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public long getRoadId() {
|
||||||
|
return roadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppModeKey() {
|
||||||
|
return appModeKey;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readFromBundle(Bundle bundle) {
|
protected void readFromBundle(Bundle bundle) {
|
||||||
roadId = bundle.getLong("roadId");
|
roadId = bundle.getLong("roadId");
|
||||||
latitude = bundle.getDouble("latitude");
|
latitude = bundle.getDouble("latitude");
|
||||||
longitude = bundle.getDouble("longitude");
|
longitude = bundle.getDouble("longitude");
|
||||||
|
direction = bundle.getDouble("direction");
|
||||||
name = bundle.getString("name");
|
name = bundle.getString("name");
|
||||||
appModeKey = bundle.getString("appModeKey");
|
appModeKey = bundle.getString("appModeKey");
|
||||||
}
|
}
|
||||||
|
@ -51,6 +78,7 @@ public class ABlockedRoadParams extends AidlParams {
|
||||||
bundle.putLong("roadId", roadId);
|
bundle.putLong("roadId", roadId);
|
||||||
bundle.putDouble("latitude", latitude);
|
bundle.putDouble("latitude", latitude);
|
||||||
bundle.putDouble("longitude", longitude);
|
bundle.putDouble("longitude", longitude);
|
||||||
|
bundle.putDouble("direction", direction);
|
||||||
bundle.putString("name", name);
|
bundle.putString("name", name);
|
||||||
bundle.putString("appModeKey", appModeKey);
|
bundle.putString("appModeKey", appModeKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2379,7 +2379,7 @@ public class OsmandAidlApi {
|
||||||
public boolean getBlockedRoads(List<ABlockedRoadParams> blockedRoads) {
|
public boolean getBlockedRoads(List<ABlockedRoadParams> blockedRoads) {
|
||||||
Map<LatLon, AvoidRoadInfo> impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
Map<LatLon, AvoidRoadInfo> impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
||||||
for (AvoidRoadInfo info : impassableRoads.values()) {
|
for (AvoidRoadInfo info : impassableRoads.values()) {
|
||||||
blockedRoads.add(new ABlockedRoadParams(info.id, info.latitude, info.longitude, info.name, info.appModeKey));
|
blockedRoads.add(new ABlockedRoadParams(info.id, info.latitude, info.longitude, info.direction, info.name, info.appModeKey));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadPoint;
|
import net.osmand.data.QuadPoint;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -35,6 +34,7 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.routing.RoutingHelper.RouteSegmentSearchResult;
|
import net.osmand.plus.routing.RoutingHelper.RouteSegmentSearchResult;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.views.layers.ContextMenuLayer;
|
import net.osmand.plus.views.layers.ContextMenuLayer;
|
||||||
import net.osmand.router.RouteSegmentResult;
|
import net.osmand.router.RouteSegmentResult;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
|
@ -59,7 +59,7 @@ public class AvoidSpecificRoads {
|
||||||
loadImpassableRoads();
|
loadImpassableRoads();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadImpassableRoads(){
|
public void loadImpassableRoads() {
|
||||||
for (AvoidRoadInfo avoidRoadInfo : app.getSettings().getImpassableRoadPoints()) {
|
for (AvoidRoadInfo avoidRoadInfo : app.getSettings().getImpassableRoadPoints()) {
|
||||||
impassableRoads.put(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude), avoidRoadInfo);
|
impassableRoads.put(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude), avoidRoadInfo);
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,13 @@ public class AvoidSpecificRoads {
|
||||||
if (avoidRoadInfo == null) {
|
if (avoidRoadInfo == null) {
|
||||||
avoidRoadInfo = new AvoidRoadInfo();
|
avoidRoadInfo = new AvoidRoadInfo();
|
||||||
}
|
}
|
||||||
avoidRoadInfo.id = object != null ? object.id : 0;
|
if (object != null) {
|
||||||
|
avoidRoadInfo.id = object.id;
|
||||||
|
// avoidRoadInfo.direction = object.directionRoute(0, true);
|
||||||
|
} else {
|
||||||
|
avoidRoadInfo.id = 0;
|
||||||
|
avoidRoadInfo.direction = Double.NaN;
|
||||||
|
}
|
||||||
avoidRoadInfo.latitude = lat;
|
avoidRoadInfo.latitude = lat;
|
||||||
avoidRoadInfo.longitude = lon;
|
avoidRoadInfo.longitude = lon;
|
||||||
avoidRoadInfo.appModeKey = appModeKey;
|
avoidRoadInfo.appModeKey = appModeKey;
|
||||||
|
@ -400,6 +406,7 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
public static class AvoidRoadInfo {
|
public static class AvoidRoadInfo {
|
||||||
public long id;
|
public long id;
|
||||||
|
public double direction;
|
||||||
public double latitude;
|
public double latitude;
|
||||||
public double longitude;
|
public double longitude;
|
||||||
public String name;
|
public String name;
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.StringTokenizer;
|
||||||
class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
|
|
||||||
protected String roadsIdsKey;
|
protected String roadsIdsKey;
|
||||||
|
protected String directionsKey;
|
||||||
protected String appModeKey;
|
protected String appModeKey;
|
||||||
|
|
||||||
public ImpassableRoadsStorage(OsmandSettings osmandSettings) {
|
public ImpassableRoadsStorage(OsmandSettings osmandSettings) {
|
||||||
|
@ -19,6 +20,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
pointsKey = OsmandSettings.IMPASSABLE_ROAD_POINTS;
|
pointsKey = OsmandSettings.IMPASSABLE_ROAD_POINTS;
|
||||||
descriptionsKey = OsmandSettings.IMPASSABLE_ROADS_DESCRIPTIONS;
|
descriptionsKey = OsmandSettings.IMPASSABLE_ROADS_DESCRIPTIONS;
|
||||||
roadsIdsKey = OsmandSettings.IMPASSABLE_ROADS_IDS;
|
roadsIdsKey = OsmandSettings.IMPASSABLE_ROADS_IDS;
|
||||||
|
directionsKey = OsmandSettings.IMPASSABLE_ROADS_DIRECTIONS;
|
||||||
appModeKey = OsmandSettings.IMPASSABLE_ROADS_APP_MODE_KEYS;
|
appModeKey = OsmandSettings.IMPASSABLE_ROADS_APP_MODE_KEYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +39,21 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Double> getDirections(int size) {
|
||||||
|
List<Double> list = new ArrayList<>();
|
||||||
|
String directions = getSettingsAPI().getString(getOsmandSettings().getGlobalPreferences(), directionsKey, "");
|
||||||
|
if (directions.trim().length() > 0) {
|
||||||
|
StringTokenizer tok = new StringTokenizer(directions, ",");
|
||||||
|
while (tok.hasMoreTokens() && list.size() <= size) {
|
||||||
|
list.add(Double.parseDouble(tok.nextToken()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (list.size() < size) {
|
||||||
|
list.add(0.0);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getAppModeKeys(int size) {
|
public List<String> getAppModeKeys(int size) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
String roadIds = getSettingsAPI().getString(getOsmandSettings().getGlobalPreferences(), appModeKey, "");
|
String roadIds = getSettingsAPI().getString(getOsmandSettings().getGlobalPreferences(), appModeKey, "");
|
||||||
|
@ -55,6 +72,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
public List<AvoidRoadInfo> getImpassableRoadsInfo() {
|
public List<AvoidRoadInfo> getImpassableRoadsInfo() {
|
||||||
List<LatLon> points = getPoints();
|
List<LatLon> points = getPoints();
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
|
@ -68,6 +86,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
avoidRoadInfo.id = roadIds.get(i);
|
avoidRoadInfo.id = roadIds.get(i);
|
||||||
avoidRoadInfo.latitude = latLon.getLatitude();
|
avoidRoadInfo.latitude = latLon.getLatitude();
|
||||||
avoidRoadInfo.longitude = latLon.getLongitude();
|
avoidRoadInfo.longitude = latLon.getLongitude();
|
||||||
|
avoidRoadInfo.direction = directions.get(i);
|
||||||
avoidRoadInfo.name = description.getName();
|
avoidRoadInfo.name = description.getName();
|
||||||
avoidRoadInfo.appModeKey = appModeKeys.get(i);
|
avoidRoadInfo.appModeKey = appModeKeys.get(i);
|
||||||
avoidRoadsInfo.add(avoidRoadInfo);
|
avoidRoadsInfo.add(avoidRoadInfo);
|
||||||
|
@ -79,15 +98,17 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
public boolean addImpassableRoadInfo(AvoidRoadInfo avoidRoadInfo) {
|
public boolean addImpassableRoadInfo(AvoidRoadInfo avoidRoadInfo) {
|
||||||
List<LatLon> points = getPoints();
|
List<LatLon> points = getPoints();
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
roadIds.add(0, avoidRoadInfo.id);
|
roadIds.add(0, avoidRoadInfo.id);
|
||||||
|
directions.add(0, avoidRoadInfo.direction);
|
||||||
points.add(0, new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
|
points.add(0, new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
|
||||||
appModeKeys.add(0, avoidRoadInfo.appModeKey);
|
appModeKeys.add(0, avoidRoadInfo.appModeKey);
|
||||||
descriptions.add(0, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
|
descriptions.add(0, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
|
||||||
|
|
||||||
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
|
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateImpassableRoadInfo(AvoidRoadInfo avoidRoadInfo) {
|
public boolean updateImpassableRoadInfo(AvoidRoadInfo avoidRoadInfo) {
|
||||||
|
@ -96,13 +117,15 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
int index = points.indexOf(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
|
int index = points.indexOf(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
roadIds.set(index, avoidRoadInfo.id);
|
roadIds.set(index, avoidRoadInfo.id);
|
||||||
|
directions.set(index, avoidRoadInfo.direction);
|
||||||
appModeKeys.set(index, avoidRoadInfo.appModeKey);
|
appModeKeys.set(index, avoidRoadInfo.appModeKey);
|
||||||
descriptions.set(index, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
|
descriptions.set(index, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
|
||||||
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
|
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -111,15 +134,17 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
public boolean deletePoint(int index) {
|
public boolean deletePoint(int index) {
|
||||||
List<LatLon> points = getPoints();
|
List<LatLon> points = getPoints();
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
if (index < points.size()) {
|
if (index < points.size()) {
|
||||||
points.remove(index);
|
points.remove(index);
|
||||||
roadIds.remove(index);
|
roadIds.remove(index);
|
||||||
|
directions.remove(index);
|
||||||
appModeKeys.remove(index);
|
appModeKeys.remove(index);
|
||||||
descriptions.remove(index);
|
descriptions.remove(index);
|
||||||
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
|
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,6 +153,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
public boolean deletePoint(LatLon latLon) {
|
public boolean deletePoint(LatLon latLon) {
|
||||||
List<LatLon> points = getPoints();
|
List<LatLon> points = getPoints();
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
|
@ -135,9 +161,10 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
points.remove(index);
|
points.remove(index);
|
||||||
roadIds.remove(index);
|
roadIds.remove(index);
|
||||||
|
directions.remove(index);
|
||||||
appModeKeys.remove(index);
|
appModeKeys.remove(index);
|
||||||
descriptions.remove(index);
|
descriptions.remove(index);
|
||||||
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
|
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -146,21 +173,23 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
|
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
|
||||||
List<LatLon> points = getPoints();
|
List<LatLon> points = getPoints();
|
||||||
List<Long> roadIds = getRoadIds(points.size());
|
List<Long> roadIds = getRoadIds(points.size());
|
||||||
|
List<Double> directions = getDirections(points.size());
|
||||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||||
List<String> descriptions = getPointDescriptions(points.size());
|
List<String> descriptions = getPointDescriptions(points.size());
|
||||||
|
|
||||||
int i = points.indexOf(latLonEx);
|
int i = points.indexOf(latLonEx);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
points.set(i, latLonNew);
|
points.set(i, latLonNew);
|
||||||
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
|
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveAvoidRoadData(List<LatLon> points, List<String> descriptions,
|
public boolean saveAvoidRoadData(List<LatLon> points, List<String> descriptions, List<Long> roadIds,
|
||||||
List<Long> roadIds, List<String> appModeKeys) {
|
List<String> appModeKeys, List<Double> directions) {
|
||||||
return savePoints(points, descriptions) && saveRoadIds(roadIds) && saveAppModeKeys(appModeKeys);
|
return savePoints(points, descriptions) && saveRoadIds(roadIds)
|
||||||
|
&& saveAppModeKeys(appModeKeys) && saveDirections(directions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveRoadIds(List<Long> roadIds) {
|
public boolean saveRoadIds(List<Long> roadIds) {
|
||||||
|
@ -177,6 +206,20 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean saveDirections(List<Double> directions) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
Iterator<Double> iterator = directions.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
stringBuilder.append(iterator.next());
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
stringBuilder.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getSettingsAPI().edit(getOsmandSettings().getGlobalPreferences())
|
||||||
|
.putString(directionsKey, stringBuilder.toString())
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean saveAppModeKeys(List<String> appModeKeys) {
|
public boolean saveAppModeKeys(List<String> appModeKeys) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
Iterator<String> iterator = appModeKeys.iterator();
|
Iterator<String> iterator = appModeKeys.iterator();
|
||||||
|
|
|
@ -2106,6 +2106,7 @@ public class OsmandSettings {
|
||||||
public static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
|
public static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
|
||||||
public static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
|
public static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
|
||||||
public static final String IMPASSABLE_ROADS_IDS = "impassable_roads_ids";
|
public static final String IMPASSABLE_ROADS_IDS = "impassable_roads_ids";
|
||||||
|
public static final String IMPASSABLE_ROADS_DIRECTIONS = "impassable_roads_directions";
|
||||||
public static final String IMPASSABLE_ROADS_APP_MODE_KEYS = "impassable_roads_app_mode_keys";
|
public static final String IMPASSABLE_ROADS_APP_MODE_KEYS = "impassable_roads_app_mode_keys";
|
||||||
|
|
||||||
public void backupPointToStart() {
|
public void backupPointToStart() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||||
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
|
||||||
|
@ -19,16 +20,16 @@ import org.json.JSONObject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecificRoads.AvoidRoadInfo> {
|
public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidRoadInfo> {
|
||||||
|
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
private AvoidSpecificRoads specificRoads;
|
private AvoidSpecificRoads specificRoads;
|
||||||
|
|
||||||
public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull List<AvoidSpecificRoads.AvoidRoadInfo> items) {
|
public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull List<AvoidRoadInfo> items) {
|
||||||
super(app, null, items);
|
super(app, null, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @Nullable AvoidRoadsSettingsItem baseItem, @NonNull List<AvoidSpecificRoads.AvoidRoadInfo> items) {
|
public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @Nullable AvoidRoadsSettingsItem baseItem, @NonNull List<AvoidRoadInfo> items) {
|
||||||
super(app, baseItem, items);
|
super(app, baseItem, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,16 +65,16 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
List<AvoidSpecificRoads.AvoidRoadInfo> newItems = getNewItems();
|
List<AvoidRoadInfo> newItems = getNewItems();
|
||||||
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
||||||
appliedItems = new ArrayList<>(newItems);
|
appliedItems = new ArrayList<>(newItems);
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo duplicate : duplicateItems) {
|
for (AvoidRoadInfo duplicate : duplicateItems) {
|
||||||
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
||||||
if (settings.removeImpassableRoad(latLon)) {
|
if (settings.removeImpassableRoad(latLon)) {
|
||||||
settings.addImpassableRoad(duplicate);
|
settings.addImpassableRoad(duplicate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : appliedItems) {
|
for (AvoidRoadInfo avoidRoad : appliedItems) {
|
||||||
settings.addImpassableRoad(avoidRoad);
|
settings.addImpassableRoad(avoidRoad);
|
||||||
}
|
}
|
||||||
specificRoads.loadImpassableRoads();
|
specificRoads.loadImpassableRoads();
|
||||||
|
@ -82,8 +83,8 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDuplicate(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
public boolean isDuplicate(@NonNull AvoidRoadInfo item) {
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo roadInfo : existingItems) {
|
for (AvoidRoadInfo roadInfo : existingItems) {
|
||||||
if (roadInfo.id == item.id) {
|
if (roadInfo.id == item.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AvoidSpecificRoads.AvoidRoadInfo renameItem(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
public AvoidRoadInfo renameItem(@NonNull AvoidRoadInfo item) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +119,15 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
JSONObject object = jsonArray.getJSONObject(i);
|
JSONObject object = jsonArray.getJSONObject(i);
|
||||||
double latitude = object.optDouble("latitude");
|
double latitude = object.optDouble("latitude");
|
||||||
double longitude = object.optDouble("longitude");
|
double longitude = object.optDouble("longitude");
|
||||||
|
double direction = object.optDouble("direction");
|
||||||
String name = object.optString("name");
|
String name = object.optString("name");
|
||||||
String appModeKey = object.optString("appModeKey");
|
String appModeKey = object.optString("appModeKey");
|
||||||
long id = object.optLong("roadId");
|
long id = object.optLong("roadId");
|
||||||
AvoidSpecificRoads.AvoidRoadInfo roadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
|
AvoidRoadInfo roadInfo = new AvoidRoadInfo();
|
||||||
roadInfo.id = id;
|
roadInfo.id = id;
|
||||||
roadInfo.latitude = latitude;
|
roadInfo.latitude = latitude;
|
||||||
roadInfo.longitude = longitude;
|
roadInfo.longitude = longitude;
|
||||||
|
roadInfo.direction = direction;
|
||||||
roadInfo.name = name;
|
roadInfo.name = name;
|
||||||
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
|
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
|
||||||
roadInfo.appModeKey = appModeKey;
|
roadInfo.appModeKey = appModeKey;
|
||||||
|
@ -144,13 +147,16 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
if (!items.isEmpty()) {
|
if (!items.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : items) {
|
for (AvoidRoadInfo avoidRoad : items) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("latitude", avoidRoad.latitude);
|
jsonObject.put("latitude", avoidRoad.latitude);
|
||||||
jsonObject.put("longitude", avoidRoad.longitude);
|
jsonObject.put("longitude", avoidRoad.longitude);
|
||||||
jsonObject.put("name", avoidRoad.name);
|
jsonObject.put("name", avoidRoad.name);
|
||||||
jsonObject.put("appModeKey", avoidRoad.appModeKey);
|
jsonObject.put("appModeKey", avoidRoad.appModeKey);
|
||||||
jsonObject.put("roadId", avoidRoad.id);
|
jsonObject.put("roadId", avoidRoad.id);
|
||||||
|
if (Double.isNaN(avoidRoad.direction)) {
|
||||||
|
jsonObject.put("direction", avoidRoad.direction);
|
||||||
|
}
|
||||||
jsonArray.put(jsonObject);
|
jsonArray.put(jsonObject);
|
||||||
}
|
}
|
||||||
json.put("items", jsonArray);
|
json.put("items", jsonArray);
|
||||||
|
|
Loading…
Reference in a new issue