Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d292b67848
7 changed files with 176 additions and 55 deletions
|
@ -113,11 +113,13 @@ public class RoutingConfiguration {
|
||||||
return impassableRoadLocations;
|
return impassableRoadLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addImpassableRoad(RouteDataObject route, Location location) {
|
public boolean addImpassableRoad(RouteDataObject route, Location location) {
|
||||||
if (!impassableRoadLocations.containsKey(route.id)){
|
if (!impassableRoadLocations.containsKey(route.id)){
|
||||||
impassableRoadLocations.put(route.id, location);
|
impassableRoadLocations.put(route.id, location);
|
||||||
impassableRoads.add(route);
|
impassableRoads.add(route);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +143,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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -59,6 +60,7 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import btools.routingapp.BRouterServiceConnection;
|
import btools.routingapp.BRouterServiceConnection;
|
||||||
|
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
|
||||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
||||||
|
@ -347,8 +349,8 @@ public class AppInitializer implements IProgress {
|
||||||
app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
|
app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
|
||||||
app.resourceManager = startupInit(new ResourceManager(app), ResourceManager.class);
|
app.resourceManager = startupInit(new ResourceManager(app), ResourceManager.class);
|
||||||
app.daynightHelper = startupInit(new DayNightHelper(app), DayNightHelper.class);
|
app.daynightHelper = startupInit(new DayNightHelper(app), DayNightHelper.class);
|
||||||
app.avoidSpecificRoads = startupInit(new AvoidSpecificRoads(app), AvoidSpecificRoads.class);
|
|
||||||
app.locationProvider = startupInit(new OsmAndLocationProvider(app), OsmAndLocationProvider.class);
|
app.locationProvider = startupInit(new OsmAndLocationProvider(app), OsmAndLocationProvider.class);
|
||||||
|
app.avoidSpecificRoads = startupInit(new AvoidSpecificRoads(app), AvoidSpecificRoads.class);
|
||||||
app.savingTrackHelper = startupInit(new SavingTrackHelper(app), SavingTrackHelper.class);
|
app.savingTrackHelper = startupInit(new SavingTrackHelper(app), SavingTrackHelper.class);
|
||||||
app.notificationHelper = startupInit(new NotificationHelper(app), NotificationHelper.class);
|
app.notificationHelper = startupInit(new NotificationHelper(app), NotificationHelper.class);
|
||||||
app.liveMonitoringHelper = startupInit(new LiveMonitoringHelper(app), LiveMonitoringHelper.class);
|
app.liveMonitoringHelper = startupInit(new LiveMonitoringHelper(app), LiveMonitoringHelper.class);
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -89,7 +86,6 @@ public class CurrentPositionHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.execute((Void) null);
|
}.execute((Void) null);
|
||||||
|
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -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 removeImpassableRoad(int index) {
|
||||||
|
return mImpassableRoadsStorage.deletePoint(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeImpassableRoad(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;
|
||||||
|
@ -37,20 +39,27 @@ public class AvoidSpecificRoads {
|
||||||
public AvoidSpecificRoads(OsmandApplication app) {
|
public AvoidSpecificRoads(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initPreservedData() {
|
||||||
|
List<LatLon> impassibleRoads = app.getSettings().getImpassableRoadPoints();
|
||||||
|
for (LatLon impassibleRoad : impassibleRoads) {
|
||||||
|
addImpassableRoad(null, impassibleRoad, false, null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<RouteDataObject> getMissingRoads() {
|
public List<RouteDataObject> getMissingRoads() {
|
||||||
if(missingRoads == null) {
|
if (missingRoads == null) {
|
||||||
missingRoads = app.getDefaultRoutingConfig().getImpassableRoads();
|
missingRoads = app.getDefaultRoutingConfig().getImpassableRoads();
|
||||||
}
|
}
|
||||||
return missingRoads;
|
return missingRoads;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected net.osmand.router.RoutingConfiguration.Builder getBuilder() {
|
protected net.osmand.router.RoutingConfiguration.Builder getBuilder() {
|
||||||
return RoutingConfiguration.getDefault();
|
return RoutingConfiguration.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
|
public ArrayAdapter<RouteDataObject> createAdapter(final MapActivity ctx) {
|
||||||
final ArrayList<RouteDataObject> points = new ArrayList<RouteDataObject>();
|
final ArrayList<RouteDataObject> points = new ArrayList<>();
|
||||||
points.addAll(getMissingRoads());
|
points.addAll(getMissingRoads());
|
||||||
final LatLon mapLocation = ctx.getMapLocation();
|
final LatLon mapLocation = ctx.getMapLocation();
|
||||||
return new ArrayAdapter<RouteDataObject>(ctx,
|
return new ArrayAdapter<RouteDataObject>(ctx,
|
||||||
|
@ -61,7 +70,7 @@ public class AvoidSpecificRoads {
|
||||||
// User super class to create the View
|
// User super class to create the View
|
||||||
View v = convertView;
|
View v = convertView;
|
||||||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
|
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, parent, false);
|
||||||
}
|
}
|
||||||
final RouteDataObject obj = getItem(position);
|
final RouteDataObject obj = getItem(position);
|
||||||
v.findViewById(R.id.all_points).setVisibility(View.GONE);
|
v.findViewById(R.id.all_points).setVisibility(View.GONE);
|
||||||
|
@ -81,7 +90,7 @@ public class AvoidSpecificRoads {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
remove(obj);
|
remove(obj);
|
||||||
getBuilder().removeImpassableRoad(obj);
|
removeImpassableRoad(obj);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||||
|
@ -91,24 +100,27 @@ public class AvoidSpecificRoads {
|
||||||
});
|
});
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeImpassableRoad(RouteDataObject obj) {
|
||||||
|
app.getSettings().removeImpassableRoad(getLocation(obj));
|
||||||
|
getBuilder().removeImpassableRoad(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String getText(RouteDataObject obj) {
|
protected String getText(RouteDataObject obj) {
|
||||||
return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get()),
|
return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get()),
|
||||||
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) {
|
||||||
bld.setMessage(R.string.avoid_roads_msg);
|
bld.setMessage(R.string.avoid_roads_msg);
|
||||||
} else {
|
} else {
|
||||||
final ArrayAdapter<?> listAdapter = createAdapter(mapActivity);
|
final ArrayAdapter<?> listAdapter = createAdapter(mapActivity);
|
||||||
bld.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
bld.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
@ -130,23 +142,26 @@ public class AvoidSpecificRoads {
|
||||||
bld.setNegativeButton(R.string.shared_string_close, null);
|
bld.setNegativeButton(R.string.shared_string_close, null);
|
||||||
bld.show();
|
bld.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void selectFromMap(final MapActivity mapActivity) {
|
protected void selectFromMap(final MapActivity mapActivity) {
|
||||||
ContextMenuLayer cm = mapActivity.getMapLayers().getContextMenuLayer();
|
ContextMenuLayer cm = mapActivity.getMapLayers().getContextMenuLayer();
|
||||||
cm.setSelectOnMap(new CallbackWithObject<LatLon>() {
|
cm.setSelectOnMap(new CallbackWithObject<LatLon>() {
|
||||||
|
|
||||||
@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 +170,9 @@ public class AvoidSpecificRoads {
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(RouteDataObject object) {
|
public boolean publish(RouteDataObject object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
if (activity != null) {
|
||||||
|
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 +188,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());
|
||||||
|
@ -208,33 +229,37 @@ public class AvoidSpecificRoads {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
if (callback != null) {
|
return callback != null && callback.isCancelled();
|
||||||
return callback.isCancelled();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addImpassableRoadInternal(RouteDataObject object, Location ll, boolean showDialog, MapActivity activity, LatLon loc) {
|
private void addImpassableRoadInternal(@NonNull RouteDataObject object,
|
||||||
getBuilder().addImpassableRoad(object, ll);
|
@NonNull Location ll,
|
||||||
|
boolean showDialog,
|
||||||
|
@Nullable MapActivity activity,
|
||||||
|
@NonNull LatLon loc) {
|
||||||
|
if(!getBuilder().addImpassableRoad(object, ll)) {
|
||||||
|
app.getSettings().removeImpassableRoad(getLocation(object));
|
||||||
|
}
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if(rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||||
rh.recalculateRouteDueToSettingsChange();
|
rh.recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
if (showDialog) {
|
if (activity != null) {
|
||||||
showDialog(activity);
|
if (showDialog) {
|
||||||
|
showDialog(activity);
|
||||||
|
}
|
||||||
|
MapContextMenu menu = activity.getContextMenu();
|
||||||
|
if (menu.isActive() && menu.getLatLon().equals(loc)) {
|
||||||
|
menu.close();
|
||||||
|
}
|
||||||
|
activity.refreshMap();
|
||||||
}
|
}
|
||||||
MapContextMenu menu = activity.getContextMenu();
|
|
||||||
if (menu.isActive() && menu.getLatLon().equals(loc)) {
|
|
||||||
menu.close();
|
|
||||||
}
|
|
||||||
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) {
|
||||||
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
|
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
|
||||||
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
|
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
|
||||||
if (thread.isAnimating()) {
|
if (thread.isAnimating()) {
|
||||||
|
@ -247,6 +272,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);
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class ImpassibleRoadsMenuController extends MenuController {
|
||||||
rightTitleButtonController = new TitleButtonController() {
|
rightTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
app.getDefaultRoutingConfig().removeImpassableRoad(
|
app.getAvoidSpecificRoads().removeImpassableRoad(
|
||||||
ImpassibleRoadsMenuController.this.route);
|
ImpassibleRoadsMenuController.this.route);
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
|
||||||
|
|
|
@ -23,8 +23,10 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
ContextMenuLayer.IContextMenuProvider, ContextMenuLayer.IMoveObjectProvider {
|
ContextMenuLayer.IContextMenuProvider, ContextMenuLayer.IMoveObjectProvider {
|
||||||
|
@ -40,6 +42,8 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
|
|
||||||
private ContextMenuLayer contextMenuLayer;
|
private ContextMenuLayer contextMenuLayer;
|
||||||
|
|
||||||
|
private Set<PreservedRoadDataObject> mPreservedRoadDataObjects;
|
||||||
|
|
||||||
public ImpassableRoadsLayer(MapActivity activity) {
|
public ImpassableRoadsLayer(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
@ -52,15 +56,19 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
routingHelper = activity.getRoutingHelper();
|
routingHelper = activity.getRoutingHelper();
|
||||||
|
|
||||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||||
|
|
||||||
|
List<LatLon> impassibleRoads = activity.getMyApplication().getSettings().getImpassableRoadPoints();
|
||||||
|
mPreservedRoadDataObjects = new HashSet<>(impassibleRoads.size());
|
||||||
|
for (LatLon impassibleRoad : impassibleRoads) {
|
||||||
|
mPreservedRoadDataObjects.add(new PreservedRoadDataObject(impassibleRoad));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||||
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
|
||||||
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
||||||
float left = pf.x - roadWorkIcon.getWidth() / 2;
|
drawPoint(canvas, pf.x, pf.y);
|
||||||
float top = pf.y - roadWorkIcon.getHeight();
|
|
||||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,15 +83,29 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location location = getMissingRoadLocations().get(id);
|
Location location = getMissingRoadLocations().get(id);
|
||||||
float x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
final double latitude = location.getLatitude();
|
||||||
float y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
final double longitude = location.getLongitude();
|
||||||
float left = x - roadWorkIcon.getWidth() / 2;
|
drawPoint(canvas, tileBox, latitude, longitude);
|
||||||
float top = y - roadWorkIcon.getHeight();
|
}
|
||||||
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
for (PreservedRoadDataObject preservedRoadDataObject : mPreservedRoadDataObjects) {
|
||||||
|
final LatLon latLon = preservedRoadDataObject.getLatLon();
|
||||||
|
drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, double latitude, double longitude) {
|
||||||
|
float x = tileBox.getPixXFromLatLon(latitude, longitude);
|
||||||
|
float y = tileBox.getPixYFromLatLon(latitude, longitude);
|
||||||
|
drawPoint(canvas, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawPoint(Canvas canvas, float x, float y) {
|
||||||
|
float left = x - roadWorkIcon.getWidth() / 2;
|
||||||
|
float top = y - roadWorkIcon.getHeight();
|
||||||
|
canvas.drawBitmap(roadWorkIcon, left, top, paint);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Long, Location> getMissingRoadLocations() {
|
public Map<Long, Location> getMissingRoadLocations() {
|
||||||
if (missingRoadLocations == null) {
|
if (missingRoadLocations == null) {
|
||||||
missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations();
|
||||||
|
@ -155,6 +177,10 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!mPreservedRoadDataObjects.isEmpty()) {
|
||||||
|
activity.getMyApplication().getAvoidSpecificRoads().initPreservedData();
|
||||||
|
mPreservedRoadDataObjects.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -186,7 +212,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;
|
||||||
}
|
}
|
||||||
|
@ -226,4 +252,16 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class PreservedRoadDataObject {
|
||||||
|
private final LatLon mLatLon;
|
||||||
|
|
||||||
|
private PreservedRoadDataObject(LatLon latLon) {
|
||||||
|
this.mLatLon = latLon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LatLon getLatLon() {
|
||||||
|
return mLatLon;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue