diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index ca19b48c83..92115f873b 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -92,6 +92,9 @@ import net.osmand.aidlapi.copyfile.CopyFileParams; import net.osmand.aidlapi.navigation.ANavigationUpdateParams; import net.osmand.aidlapi.navigation.ANavigationVoiceRouterMessageParams; +import net.osmand.aidlapi.navigation.ABlockedRoad; +import net.osmand.aidlapi.navigation.AddBlockedRoadParams; +import net.osmand.aidlapi.navigation.RemoveBlockedRoadParams; import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams; @@ -892,4 +895,10 @@ interface IOsmAndAidlInterface { boolean selectProfile(in SelectProfileParams params); boolean getProfiles(out List profiles); + + boolean getBlockedRoads(out List blockedRoads); + + boolean addRoadBlock(in AddBlockedRoadParams params); + + boolean removeRoadBlock(in RemoveBlockedRoadParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl new file mode 100644 index 0000000000..23c31596d5 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable ABlockedRoad; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java new file mode 100644 index 0000000000..e83f64334b --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/ABlockedRoad.java @@ -0,0 +1,85 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class ABlockedRoad extends AidlParams { + + private long roadId; + private double latitude; + private double longitude; + private double direction; + private String name; + private String appModeKey; + + public ABlockedRoad(long roadId, double latitude, double longitude, double direction, String name, String appModeKey) { + this.roadId = roadId; + this.latitude = latitude; + this.longitude = longitude; + this.direction = direction; + this.name = name; + this.appModeKey = appModeKey; + } + + protected ABlockedRoad(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public ABlockedRoad createFromParcel(Parcel in) { + return new ABlockedRoad(in); + } + + @Override + public ABlockedRoad[] newArray(int size) { + return new ABlockedRoad[size]; + } + }; + + 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 + protected void readFromBundle(Bundle bundle) { + roadId = bundle.getLong("roadId"); + latitude = bundle.getDouble("latitude"); + longitude = bundle.getDouble("longitude"); + direction = bundle.getDouble("direction"); + name = bundle.getString("name"); + appModeKey = bundle.getString("appModeKey"); + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putLong("roadId", roadId); + bundle.putDouble("latitude", latitude); + bundle.putDouble("longitude", longitude); + bundle.putDouble("direction", direction); + bundle.putString("name", name); + bundle.putString("appModeKey", appModeKey); + } +} \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl new file mode 100644 index 0000000000..5eb74b0b53 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable AddBlockedRoadParams; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java new file mode 100644 index 0000000000..b64a9d32ce --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/AddBlockedRoadParams.java @@ -0,0 +1,46 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class AddBlockedRoadParams extends AidlParams { + + private ABlockedRoad blockedRoad; + + public AddBlockedRoadParams(ABlockedRoad blockedRoad) { + this.blockedRoad = blockedRoad; + } + + public AddBlockedRoadParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AddBlockedRoadParams createFromParcel(Parcel in) { + return new AddBlockedRoadParams(in); + } + + @Override + public AddBlockedRoadParams[] newArray(int size) { + return new AddBlockedRoadParams[size]; + } + }; + + public ABlockedRoad getBlockedRoad() { + return blockedRoad; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putParcelable("blockedRoad", blockedRoad); + } + + @Override + protected void readFromBundle(Bundle bundle) { + bundle.setClassLoader(ABlockedRoad.class.getClassLoader()); + blockedRoad = bundle.getParcelable("blockedRoad"); + } +} \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl new file mode 100644 index 0000000000..02c9f36f0c --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable RemoveBlockedRoadParams; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java new file mode 100644 index 0000000000..1cb4e2e6a5 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/RemoveBlockedRoadParams.java @@ -0,0 +1,46 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class RemoveBlockedRoadParams extends AidlParams { + + private ABlockedRoad blockedRoad; + + public RemoveBlockedRoadParams(ABlockedRoad blockedRoad) { + this.blockedRoad = blockedRoad; + } + + public RemoveBlockedRoadParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RemoveBlockedRoadParams createFromParcel(Parcel in) { + return new RemoveBlockedRoadParams(in); + } + + @Override + public RemoveBlockedRoadParams[] newArray(int size) { + return new RemoveBlockedRoadParams[size]; + } + }; + + public ABlockedRoad getBlockedRoad() { + return blockedRoad; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putParcelable("blockedRoad", blockedRoad); + } + + @Override + protected void readFromBundle(Bundle bundle) { + bundle.setClassLoader(ABlockedRoad.class.getClassLoader()); + blockedRoad = bundle.getParcelable("blockedRoad"); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 6b9bb29dea..2f105a7318 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -43,6 +43,7 @@ import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidlapi.customization.AProfile; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -62,6 +63,7 @@ import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.dialogs.GpxAppearanceAdapter; +import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.helpers.LockHelper; @@ -138,8 +140,11 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE; import static net.osmand.plus.FavouritesDbHelper.FILE_TO_SAVE; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_ANGLE; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_POSSIBLY_LEFT; +import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_POSSIBLY_RIGHT; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT; @@ -208,7 +213,7 @@ public class OsmandAidlApi { private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; - private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ + private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] { ApplicationMode.CAR, ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN @@ -287,7 +292,7 @@ public class OsmandAidlApi { } private void initOsmandTelegram() { - String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"}; + String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"}; Intent intent = new Intent("net.osmand.telegram.InitApp"); for (String pack : packages) { intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver")); @@ -1791,6 +1796,9 @@ public class OsmandAidlApi { RouteDirectionInfo a = ni.directionInfo; bundle.putString(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), "")); bundle.putString(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString()); + bundle.putFloat(prefix + PARAM_NT_DIRECTION_ANGLE, tt.getTurnAngle()); + bundle.putBoolean(prefix + PARAM_NT_DIRECTION_POSSIBLY_LEFT, tt.isPossibleLeftTurn()); + bundle.putBoolean(prefix + PARAM_NT_DIRECTION_POSSIBLY_RIGHT, tt.isPossibleRightTurn()); if (tt.getLanes() != null) { bundle.putString(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes())); } @@ -1798,7 +1806,7 @@ public class OsmandAidlApi { } boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude, - final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { + final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) { return false; } @@ -2167,7 +2175,7 @@ public class OsmandAidlApi { } boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, - final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { + final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { if (gpxUri == null || callback == null) { return false; } @@ -2368,6 +2376,25 @@ public class OsmandAidlApi { return true; } + public boolean getBlockedRoads(List blockedRoads) { + Map impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); + for (AvoidRoadInfo info : impassableRoads.values()) { + blockedRoads.add(new ABlockedRoad(info.id, info.latitude, info.longitude, info.direction, info.name, info.appModeKey)); + } + return true; + } + + public boolean addRoadBlock(ABlockedRoad road) { + LatLon latLon = new LatLon(road.getLatitude(), road.getLongitude()); + app.getAvoidSpecificRoads().addImpassableRoad(null, latLon, false, false, null); + return true; + } + + public boolean removeRoadBlock(ABlockedRoad road) { + app.getAvoidSpecificRoads().removeImpassableRoad(new LatLon(road.getLatitude(), road.getLongitude())); + return true; + } + private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 9943257c03..2cd422873d 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -73,13 +73,16 @@ import net.osmand.aidlapi.navdrawer.NavDrawerFooterParams; import net.osmand.aidlapi.navdrawer.NavDrawerHeaderParams; import net.osmand.aidlapi.navdrawer.NavDrawerItem; import net.osmand.aidlapi.navdrawer.SetNavDrawerItemsParams; +import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.aidlapi.navigation.ANavigationUpdateParams; import net.osmand.aidlapi.navigation.ANavigationVoiceRouterMessageParams; +import net.osmand.aidlapi.navigation.AddBlockedRoadParams; import net.osmand.aidlapi.navigation.MuteNavigationParams; import net.osmand.aidlapi.navigation.NavigateGpxParams; import net.osmand.aidlapi.navigation.NavigateParams; import net.osmand.aidlapi.navigation.NavigateSearchParams; import net.osmand.aidlapi.navigation.PauseNavigationParams; +import net.osmand.aidlapi.navigation.RemoveBlockedRoadParams; import net.osmand.aidlapi.navigation.ResumeNavigationParams; import net.osmand.aidlapi.navigation.StopNavigationParams; import net.osmand.aidlapi.navigation.UnmuteNavigationParams; @@ -1396,6 +1399,49 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener return false; } } + + @Override + public boolean getBlockedRoads(List blockedRoads) { + try { + OsmandAidlApi api = getApi("getBlockedRoads"); + return api != null && api.getBlockedRoads(blockedRoads); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean addRoadBlock(AddBlockedRoadParams params) { + try { + OsmandAidlApi api = getApi("addRoadBlock"); + if (params != null && api != null) { + ABlockedRoad road = params.getBlockedRoad(); + if (road != null) { + return api.addRoadBlock(road); + } + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public boolean removeRoadBlock(RemoveBlockedRoadParams params) { + try { + OsmandAidlApi api = getApi("removeRoadBlock"); + if (params != null && api != null) { + ABlockedRoad road = params.getBlockedRoad(); + if (road != null) { + return api.removeRoadBlock(road); + } + } + } catch (Exception e) { + handleException(e); + } + return false; + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index 22e0607c7f..bfa84b8474 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -26,7 +26,6 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; import net.osmand.data.RotatedTileBox; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; 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.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.RouteSegmentSearchResult; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.router.RouteSegmentResult; import net.osmand.router.RoutingConfiguration; @@ -59,7 +59,7 @@ public class AvoidSpecificRoads { loadImpassableRoads(); } - public void loadImpassableRoads(){ + public void loadImpassableRoads() { for (AvoidRoadInfo avoidRoadInfo : app.getSettings().getImpassableRoadPoints()) { impassableRoads.put(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude), avoidRoadInfo); } @@ -390,7 +390,14 @@ public class AvoidSpecificRoads { if (avoidRoadInfo == null) { avoidRoadInfo = new AvoidRoadInfo(); } - avoidRoadInfo.id = object != null ? object.id : 0; + if (object != null) { + avoidRoadInfo.id = object.id; +// avoidRoadInfo.direction = object.directionRoute(0, true); + avoidRoadInfo.direction = Double.NaN; + } else { + avoidRoadInfo.id = 0; + avoidRoadInfo.direction = Double.NaN; + } avoidRoadInfo.latitude = lat; avoidRoadInfo.longitude = lon; avoidRoadInfo.appModeKey = appModeKey; @@ -400,6 +407,7 @@ public class AvoidSpecificRoads { public static class AvoidRoadInfo { public long id; + public double direction = Double.NaN; public double latitude; public double longitude; public String name; diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 57d6039145..8212d0ab26 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -151,6 +151,9 @@ public class ExternalApiHelper { public static final String PARAM_NT_DIRECTION_NAME = "turn_name"; public static final String PARAM_NT_DIRECTION_TURN = "turn_type"; public static final String PARAM_NT_DIRECTION_LANES = "turn_lanes"; + public static final String PARAM_NT_DIRECTION_ANGLE = "turn_angle"; + public static final String PARAM_NT_DIRECTION_POSSIBLY_LEFT = "turn_possibly_left"; + public static final String PARAM_NT_DIRECTION_POSSIBLY_RIGHT = "turn_possibly_right"; public static final String PARAM_CLOSE_AFTER_COMMAND = "close_after_command"; @@ -690,6 +693,9 @@ public class ExternalApiHelper { RouteDirectionInfo a = ni.directionInfo; result.putExtra(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), "")); result.putExtra(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString()); + result.putExtra(prefix + PARAM_NT_DIRECTION_ANGLE, tt.getTurnAngle()); + result.putExtra(prefix + PARAM_NT_DIRECTION_POSSIBLY_LEFT, tt.isPossibleLeftTurn()); + result.putExtra(prefix + PARAM_NT_DIRECTION_POSSIBLY_RIGHT, tt.isPossibleRightTurn()); if (tt.getLanes() != null) { result.putExtra(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes())); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java b/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java index 80242478e5..25586ef35a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java @@ -12,6 +12,7 @@ import java.util.StringTokenizer; class ImpassableRoadsStorage extends SettingsMapPointsStorage { protected String roadsIdsKey; + protected String directionsKey; protected String appModeKey; public ImpassableRoadsStorage(OsmandSettings osmandSettings) { @@ -19,6 +20,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { pointsKey = OsmandSettings.IMPASSABLE_ROAD_POINTS; descriptionsKey = OsmandSettings.IMPASSABLE_ROADS_DESCRIPTIONS; roadsIdsKey = OsmandSettings.IMPASSABLE_ROADS_IDS; + directionsKey = OsmandSettings.IMPASSABLE_ROADS_DIRECTIONS; appModeKey = OsmandSettings.IMPASSABLE_ROADS_APP_MODE_KEYS; } @@ -37,6 +39,21 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { return list; } + public List getDirections(int size) { + List 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 getAppModeKeys(int size) { List list = new ArrayList<>(); String roadIds = getSettingsAPI().getString(getOsmandSettings().getGlobalPreferences(), appModeKey, ""); @@ -55,6 +72,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public List getImpassableRoadsInfo() { List points = getPoints(); List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); @@ -68,6 +86,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { avoidRoadInfo.id = roadIds.get(i); avoidRoadInfo.latitude = latLon.getLatitude(); avoidRoadInfo.longitude = latLon.getLongitude(); + avoidRoadInfo.direction = directions.get(i); avoidRoadInfo.name = description.getName(); avoidRoadInfo.appModeKey = appModeKeys.get(i); avoidRoadsInfo.add(avoidRoadInfo); @@ -79,15 +98,17 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public boolean addImpassableRoadInfo(AvoidRoadInfo avoidRoadInfo) { List points = getPoints(); List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); roadIds.add(0, avoidRoadInfo.id); + directions.add(0, avoidRoadInfo.direction); points.add(0, new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude)); appModeKeys.add(0, avoidRoadInfo.appModeKey); 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) { @@ -96,13 +117,15 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { int index = points.indexOf(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude)); if (index != -1) { List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); roadIds.set(index, avoidRoadInfo.id); + directions.set(index, avoidRoadInfo.direction); appModeKeys.set(index, avoidRoadInfo.appModeKey); descriptions.set(index, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name))); - return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys); + return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions); } return false; } @@ -111,15 +134,17 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public boolean deletePoint(int index) { List points = getPoints(); List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); if (index < points.size()) { points.remove(index); roadIds.remove(index); + directions.remove(index); appModeKeys.remove(index); descriptions.remove(index); - return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys); + return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions); } return false; } @@ -128,6 +153,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public boolean deletePoint(LatLon latLon) { List points = getPoints(); List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); @@ -135,9 +161,10 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { if (index != -1) { points.remove(index); roadIds.remove(index); + directions.remove(index); appModeKeys.remove(index); descriptions.remove(index); - return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys); + return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions); } return false; } @@ -146,21 +173,23 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public boolean movePoint(LatLon latLonEx, LatLon latLonNew) { List points = getPoints(); List roadIds = getRoadIds(points.size()); + List directions = getDirections(points.size()); List appModeKeys = getAppModeKeys(points.size()); List descriptions = getPointDescriptions(points.size()); int i = points.indexOf(latLonEx); if (i != -1) { points.set(i, latLonNew); - return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys); + return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys, directions); } else { return false; } } - public boolean saveAvoidRoadData(List points, List descriptions, - List roadIds, List appModeKeys) { - return savePoints(points, descriptions) && saveRoadIds(roadIds) && saveAppModeKeys(appModeKeys); + public boolean saveAvoidRoadData(List points, List descriptions, List roadIds, + List appModeKeys, List directions) { + return savePoints(points, descriptions) && saveRoadIds(roadIds) + && saveAppModeKeys(appModeKeys) && saveDirections(directions); } public boolean saveRoadIds(List roadIds) { @@ -177,6 +206,20 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { .commit(); } + public boolean saveDirections(List directions) { + StringBuilder stringBuilder = new StringBuilder(); + Iterator 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 appModeKeys) { StringBuilder stringBuilder = new StringBuilder(); Iterator iterator = appModeKeys.iterator(); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 554b96fc63..fbac3348e8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2106,6 +2106,7 @@ public class OsmandSettings { 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_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 void backupPointToStart() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java index 6507ab874e..0f88f0e961 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java @@ -9,6 +9,7 @@ import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; 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.OsmandSettings; @@ -19,16 +20,16 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.List; -public class AvoidRoadsSettingsItem extends CollectionSettingsItem { +public class AvoidRoadsSettingsItem extends CollectionSettingsItem { private OsmandSettings settings; private AvoidSpecificRoads specificRoads; - public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { + public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { super(app, null, items); } - public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @Nullable AvoidRoadsSettingsItem baseItem, @NonNull List items) { + public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @Nullable AvoidRoadsSettingsItem baseItem, @NonNull List items) { super(app, baseItem, items); } @@ -64,16 +65,16 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem newItems = getNewItems(); + List newItems = getNewItems(); if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { appliedItems = new ArrayList<>(newItems); - for (AvoidSpecificRoads.AvoidRoadInfo duplicate : duplicateItems) { + for (AvoidRoadInfo duplicate : duplicateItems) { LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude); if (settings.removeImpassableRoad(latLon)) { settings.addImpassableRoad(duplicate); } } - for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : appliedItems) { + for (AvoidRoadInfo avoidRoad : appliedItems) { settings.addImpassableRoad(avoidRoad); } specificRoads.loadImpassableRoads(); @@ -82,8 +83,8 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem