Merge pull request #10427 from osmandapp/aidl_blocked_roads
Aidl blocked roads
This commit is contained in:
commit
5f1f35b486
14 changed files with 358 additions and 26 deletions
|
@ -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<AProfile> profiles);
|
||||
|
||||
boolean getBlockedRoads(out List<ABlockedRoad> blockedRoads);
|
||||
|
||||
boolean addRoadBlock(in AddBlockedRoadParams params);
|
||||
|
||||
boolean removeRoadBlock(in RemoveBlockedRoadParams params);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.navigation;
|
||||
|
||||
parcelable ABlockedRoad;
|
|
@ -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<ABlockedRoad> CREATOR = new Creator<ABlockedRoad>() {
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.navigation;
|
||||
|
||||
parcelable AddBlockedRoadParams;
|
|
@ -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<AddBlockedRoadParams> CREATOR = new Creator<AddBlockedRoadParams>() {
|
||||
@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");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.navigation;
|
||||
|
||||
parcelable RemoveBlockedRoadParams;
|
|
@ -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<RemoveBlockedRoadParams> CREATOR = new Creator<RemoveBlockedRoadParams>() {
|
||||
@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");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -2368,6 +2376,25 @@ public class OsmandAidlApi {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean getBlockedRoads(List<ABlockedRoad> blockedRoads) {
|
||||
Map<LatLon, AvoidRoadInfo> 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;
|
||||
|
|
|
@ -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<ABlockedRoad> 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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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<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) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String roadIds = getSettingsAPI().getString(getOsmandSettings().getGlobalPreferences(), appModeKey, "");
|
||||
|
@ -55,6 +72,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
|||
public List<AvoidRoadInfo> getImpassableRoadsInfo() {
|
||||
List<LatLon> points = getPoints();
|
||||
List<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<LatLon> points = getPoints();
|
||||
List<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<LatLon> points = getPoints();
|
||||
List<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<LatLon> points = getPoints();
|
||||
List<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<LatLon> points = getPoints();
|
||||
List<Long> roadIds = getRoadIds(points.size());
|
||||
List<Double> directions = getDirections(points.size());
|
||||
List<String> appModeKeys = getAppModeKeys(points.size());
|
||||
List<String> 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<LatLon> points, List<String> descriptions,
|
||||
List<Long> roadIds, List<String> appModeKeys) {
|
||||
return savePoints(points, descriptions) && saveRoadIds(roadIds) && saveAppModeKeys(appModeKeys);
|
||||
public boolean saveAvoidRoadData(List<LatLon> points, List<String> descriptions, List<Long> roadIds,
|
||||
List<String> appModeKeys, List<Double> directions) {
|
||||
return savePoints(points, descriptions) && saveRoadIds(roadIds)
|
||||
&& saveAppModeKeys(appModeKeys) && saveDirections(directions);
|
||||
}
|
||||
|
||||
public boolean saveRoadIds(List<Long> roadIds) {
|
||||
|
@ -177,6 +206,20 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage {
|
|||
.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) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
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_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() {
|
||||
|
|
|
@ -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<AvoidSpecificRoads.AvoidRoadInfo> {
|
||||
public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidRoadInfo> {
|
||||
|
||||
private OsmandSettings settings;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -64,16 +65,16 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
|||
|
||||
@Override
|
||||
public void apply() {
|
||||
List<AvoidSpecificRoads.AvoidRoadInfo> newItems = getNewItems();
|
||||
List<AvoidRoadInfo> 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<AvoidSpecific
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isDuplicate(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
||||
for (AvoidSpecificRoads.AvoidRoadInfo roadInfo : existingItems) {
|
||||
public boolean isDuplicate(@NonNull AvoidRoadInfo item) {
|
||||
for (AvoidRoadInfo roadInfo : existingItems) {
|
||||
if (roadInfo.id == item.id) {
|
||||
return true;
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public AvoidSpecificRoads.AvoidRoadInfo renameItem(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
||||
public AvoidRoadInfo renameItem(@NonNull AvoidRoadInfo item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -118,13 +119,15 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
|||
JSONObject object = jsonArray.getJSONObject(i);
|
||||
double latitude = object.optDouble("latitude");
|
||||
double longitude = object.optDouble("longitude");
|
||||
double direction = object.optDouble("direction");
|
||||
String name = object.optString("name");
|
||||
String appModeKey = object.optString("appModeKey");
|
||||
long id = object.optLong("roadId");
|
||||
AvoidSpecificRoads.AvoidRoadInfo roadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
|
||||
AvoidRoadInfo roadInfo = new AvoidRoadInfo();
|
||||
roadInfo.id = id;
|
||||
roadInfo.latitude = latitude;
|
||||
roadInfo.longitude = longitude;
|
||||
roadInfo.direction = direction;
|
||||
roadInfo.name = name;
|
||||
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
|
||||
roadInfo.appModeKey = appModeKey;
|
||||
|
@ -144,13 +147,16 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
|||
JSONArray jsonArray = new JSONArray();
|
||||
if (!items.isEmpty()) {
|
||||
try {
|
||||
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : items) {
|
||||
for (AvoidRoadInfo avoidRoad : items) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("latitude", avoidRoad.latitude);
|
||||
jsonObject.put("longitude", avoidRoad.longitude);
|
||||
jsonObject.put("name", avoidRoad.name);
|
||||
jsonObject.put("appModeKey", avoidRoad.appModeKey);
|
||||
jsonObject.put("roadId", avoidRoad.id);
|
||||
if (Double.isNaN(avoidRoad.direction)) {
|
||||
jsonObject.put("direction", avoidRoad.direction);
|
||||
}
|
||||
jsonArray.put(jsonObject);
|
||||
}
|
||||
json.put("items", jsonArray);
|
||||
|
|
Loading…
Reference in a new issue