diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 685036e416..49998fe55b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1553,6 +1553,15 @@ public class OsmandSettings { public final static String INTERMEDIATE_POINTS_DESCRIPTION = "intermediate_points_description"; //$NON-NLS-1$ private IntermediatePointsStorage intermediatePointsStorage = new IntermediatePointsStorage(); + public final static String POINT_NAVIGATE_LAT_BACKUP = "point_navigate_lat_backup"; //$NON-NLS-1$ + public final static String POINT_NAVIGATE_LON_BACKUP = "point_navigate_lon_backup"; //$NON-NLS-1$ + public final static String POINT_NAVIGATE_DESCRIPTION_BACKUP = "point_navigate_description_backup"; //$NON-NLS-1$ + public final static String START_POINT_LAT_BACKUP = "start_point_lat_backup"; //$NON-NLS-1$ + public final static String START_POINT_LON_BACKUP = "start_point_lon_backup"; //$NON-NLS-1$ + public final static String START_POINT_DESCRIPTION_BACKUP = "start_point_description_backup"; //$NON-NLS-1$ + public final static String INTERMEDIATE_POINTS_BACKUP = "intermediate_points_backup"; //$NON-NLS-1$ + public final static String INTERMEDIATE_POINTS_DESCRIPTION_BACKUP = "intermediate_points_description_backup"; //$NON-NLS-1$ + public final static String MAP_MARKERS_POINT = "map_markers_point"; //$NON-NLS-1$ public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$ public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$ @@ -1564,6 +1573,48 @@ public class OsmandSettings { private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage(); private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage(); + private void backupPointToStart() { + settingsAPI.edit(globalPreferences) + .putFloat(START_POINT_LAT_BACKUP, settingsAPI.getFloat(globalPreferences, START_POINT_LAT, 0)) + .putFloat(START_POINT_LON_BACKUP, settingsAPI.getFloat(globalPreferences, START_POINT_LON, 0)) + .putString(START_POINT_DESCRIPTION_BACKUP, settingsAPI.getString(globalPreferences, START_POINT_DESCRIPTION, "")) + .commit(); + } + + private void backupPointToNavigate() { + settingsAPI.edit(globalPreferences) + .putFloat(POINT_NAVIGATE_LAT_BACKUP, settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LAT, 0)) + .putFloat(POINT_NAVIGATE_LON_BACKUP, settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LON, 0)) + .putString(POINT_NAVIGATE_DESCRIPTION_BACKUP, settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION, "")) + .commit(); + } + + private void backupIntermediatePoints() { + settingsAPI.edit(globalPreferences) + .putString(INTERMEDIATE_POINTS_BACKUP, settingsAPI.getString(globalPreferences, INTERMEDIATE_POINTS, "")) + .putString(INTERMEDIATE_POINTS_DESCRIPTION_BACKUP, settingsAPI.getString(globalPreferences, INTERMEDIATE_POINTS_DESCRIPTION, "")) + .commit(); + } + + public void backupTargetPoints() { + backupPointToStart(); + backupPointToNavigate(); + backupIntermediatePoints(); + } + + public void restoreTargetPoints() { + settingsAPI.edit(globalPreferences) + .putFloat(START_POINT_LAT, settingsAPI.getFloat(globalPreferences, START_POINT_LAT_BACKUP, 0)) + .putFloat(START_POINT_LON, settingsAPI.getFloat(globalPreferences, START_POINT_LON_BACKUP, 0)) + .putString(START_POINT_DESCRIPTION, settingsAPI.getString(globalPreferences, START_POINT_DESCRIPTION_BACKUP, "")) + .putFloat(POINT_NAVIGATE_LAT, settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LAT_BACKUP, 0)) + .putFloat(POINT_NAVIGATE_LON, settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LON_BACKUP, 0)) + .putString(POINT_NAVIGATE_DESCRIPTION, settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION_BACKUP, "")) + .putString(INTERMEDIATE_POINTS, settingsAPI.getString(globalPreferences, INTERMEDIATE_POINTS_BACKUP, "")) + .putString(INTERMEDIATE_POINTS_DESCRIPTION, settingsAPI.getString(globalPreferences, INTERMEDIATE_POINTS_DESCRIPTION_BACKUP, "")) + .commit(); + } + public LatLon getPointToNavigate() { float lat = settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LAT, 0); float lon = settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LON, 0); @@ -1634,6 +1685,13 @@ public class OsmandSettings { pointsKey = INTERMEDIATE_POINTS; descriptionsKey = INTERMEDIATE_POINTS_DESCRIPTION; } + + @Override + public boolean savePoints(List ps, List ds) { + boolean res = super.savePoints(ps, ds); + backupTargetPoints(); + return res; + } } private class MapMarkersHistoryStorage extends MapPointsStorage { @@ -1642,6 +1700,15 @@ public class OsmandSettings { pointsKey = MAP_MARKERS_HISTORY_POINT; descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION; } + + @Override + public boolean savePoints(List ps, List ds) { + while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) { + ps.remove(ps.size() - 1); + ds.remove(ds.size() - 1); + } + return super.savePoints(ps, ds); + } } private class MapMarkersStorage extends MapPointsStorage { @@ -2103,12 +2170,14 @@ public class OsmandSettings { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, p); } } + backupTargetPoints(); return add; } public boolean setPointToStart(double latitude, double longitude, PointDescription p) { boolean add = settingsAPI.edit(globalPreferences).putFloat(START_POINT_LAT, (float) latitude).putFloat(START_POINT_LON, (float) longitude).commit(); settingsAPI.edit(globalPreferences).putString(START_POINT_DESCRIPTION, PointDescription.serializeToString(p)).commit(); + backupTargetPoints(); return add; } diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index ad90215be8..8ce63691fd 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -257,10 +257,16 @@ public class TargetPointsHelper { return null; } - /** - * Clear the local and persistent waypoints list and destination. - */ - public void removeAllWayPoints(boolean updateRoute){ + public void restoreTargetPoints(boolean updateRoute) { + settings.restoreTargetPoints(); + readFromSettings(); + updateRouteAndRefresh(updateRoute); + } + + /** + * Clear the local and persistent waypoints list and destination. + */ + public void removeAllWayPoints(boolean updateRoute, boolean clearBackup){ cancelStartPointAddressRequest(); cancelTargetPointAddressRequest(); cancelAllIntermediatePointsAddressRequests(); @@ -268,6 +274,9 @@ public class TargetPointsHelper { settings.clearIntermediatePoints(); settings.clearPointToNavigate(); settings.clearPointToStart(); + if (clearBackup) { + settings.backupTargetPoints(); + } pointToNavigate = null; pointToStart = null; intermediatePoints.clear(); diff --git a/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java index dd7da97335..34e8de5f01 100644 --- a/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java @@ -283,7 +283,7 @@ public class IntermediatePointsDialog { boolean changeDestinationFlag = !checkedIntermediates[checkedIntermediates.length - 1]; if (cnt == checkedIntermediates.length) { // there is no alternative destination if all points are to be // removed? - app.getTargetPointsHelper().removeAllWayPoints(true); + app.getTargetPointsHelper().removeAllWayPoints(true, true); } else { for (int i = checkedIntermediates.length - 2; i >= 0; i--) { // skip the destination until a retained // waypoint is found diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 589f5d1f13..7ae7df8322 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -256,7 +256,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents, && !settings.FOLLOW_THE_ROUTE.get() && app.getTargetPointsHelper().getAllPoints().size() > 0) { app.getRoutingHelper().clearCurrentRoute(null, new ArrayList()); - app.getTargetPointsHelper().removeAllWayPoints(false); + app.getTargetPointsHelper().removeAllWayPoints(false, false); } if (!settings.isLastKnownMapLocation()) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index d6e80a58a4..048de69abf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -813,7 +813,7 @@ public class MapActivityActions implements DialogProvider { settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get(); settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); if (settings.USE_MAP_MARKERS.get()) { - getMyApplication().getTargetPointsHelper().removeAllWayPoints(false); + getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, false); } mapActivity.updateApplicationModeSettings(); mapActivity.getDashboard().clearDeletedPoints(); diff --git a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java index 8a853e4f88..76956f5579 100644 --- a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java +++ b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java @@ -184,7 +184,7 @@ public class FailSafeFuntions { ma.updateApplicationModeSettings(); app.getRoutingHelper().clearCurrentRoute(null, new ArrayList()); if (app.getSettings().USE_MAP_MARKERS.get()) { - app.getTargetPointsHelper().removeAllWayPoints(false); + app.getTargetPointsHelper().removeAllWayPoints(false, false); } ma.refreshMap(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 8175fcb692..9bc84658b4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -492,7 +492,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL @Override public void onClick(DialogInterface dialog, int which) { if (defaultVls[0] == 0) { - targets.removeAllWayPoints(false); + targets.removeAllWayPoints(false, true); targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget()); mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true); close(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 0192ba2ea8..f47783c372 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -391,10 +391,13 @@ public class MapControlsLayer extends OsmandMapLayer { RoutingHelper routingHelper = mapActivity.getRoutingHelper(); if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) { if (settings.USE_MAP_MARKERS.get() && !hasTargets) { - mapActivity.getMapActions().setFirstMapMarkerAsTarget(); + getTargets().restoreTargetPoints(false); + if (getTargets().getPointToNavigate() == null) { + mapActivity.getMapActions().setFirstMapMarkerAsTarget(); + } } TargetPoint start = getTargets().getPointToStart(); - if (hasTargets && start != null) { + if (start != null) { mapActivity.getMapActions().enterRoutePlanningMode( new LatLon(start.getLatitude(), start.getLongitude()), start.getOriginalPointDescription()); } else {