diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index abd958b898..18daff693a 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
+ Do you want to clear markers history?
Active markers
Map markers
Map marker
diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
index 452d5cc3c9..57638217c1 100644
--- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
+++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
@@ -17,7 +17,6 @@ import java.util.List;
public class MapMarkersHelper {
public static final int MAP_MARKERS_COLORS_COUNT = 5;
- public static final int MAP_MARKERS_HISTORY_LIMIT = 30;
private List mapMarkers = new ArrayList<>();
private List mapMarkersHistory = new ArrayList<>();
@@ -30,12 +29,7 @@ public class MapMarkersHelper {
private PointDescription pointDescription;
public int colorIndex;
public int index;
-
- public MapMarker(LatLon point, PointDescription name, int colorIndex) {
- this.point = point;
- this.pointDescription = name;
- this.colorIndex = colorIndex;
- }
+ public boolean history;
public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) {
this.point = point;
@@ -61,13 +55,6 @@ public class MapMarkersHelper {
return pointDescription != null && pointDescription.isSearchingAddress(ctx);
}
- public static MapMarker create(LatLon point, PointDescription name, int color) {
- if (point != null) {
- return new MapMarker(point, name, color);
- }
- return null;
- }
-
public double getLatitude() {
return point.getLatitude();
}
@@ -76,10 +63,6 @@ public class MapMarkersHelper {
return point.getLongitude();
}
- public int getColorIndex() {
- return colorIndex;
- }
-
@Override
public int getColor() {
return 0;
@@ -105,7 +88,7 @@ public class MapMarkersHelper {
List desc = settings.getMapMarkersPointDescriptions(ips.size());
List colors = settings.getMapMarkersColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
- final MapMarker mapMarker = new MapMarker(ips.get(i),
+ MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
mapMarkers.add(mapMarker);
lookupAddress(mapMarker, false);
@@ -114,8 +97,9 @@ public class MapMarkersHelper {
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
- final MapMarker mapMarker = new MapMarker(ips.get(i),
+ MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
+ mapMarker.history = true;
mapMarkersHistory.add(mapMarker);
lookupAddress(mapMarker, true);
}
@@ -162,7 +146,7 @@ public class MapMarkersHelper {
}
public List getActiveMarkersLatLon() {
- List list = new ArrayList();
+ List list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {
list.add(m.point);
}
@@ -170,7 +154,7 @@ public class MapMarkersHelper {
}
public List getMarkersHistoryLatLon() {
- List list = new ArrayList();
+ List list = new ArrayList<>();
for (MapMarker m : this.mapMarkersHistory) {
list.add(m.point);
}
@@ -195,7 +179,7 @@ public class MapMarkersHelper {
refresh();
}
- public void addMapMarker(final LatLon point, PointDescription historyName) {
+ public void addMapMarker(LatLon point, PointDescription historyName) {
if (point != null) {
final PointDescription pointDescription;
if (historyName == null) {
@@ -214,9 +198,65 @@ public class MapMarkersHelper {
}
settings.insertMapMarker(point.getLatitude(), point.getLongitude(),
pointDescription, colorIndex, mapMarkers.size());
+
+ readFromSettings();
+ refresh();
+ }
+ }
+
+ public void removeMapMarker(MapMarker marker) {
+ if (marker != null) {
+ settings.deleteMapMarker(marker.index);
+ readFromSettings();
+ refresh();
+ }
+ }
+
+ public void addMapMarkerHistory(MapMarker marker) {
+ if (marker != null) {
+ settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, marker.colorIndex, 0);
+ readFromSettings();
+ refresh();
+ }
+ }
+
+ public void removeMapMarkerHistory(MapMarker marker) {
+ if (marker != null) {
+ settings.deleteMapMarkerHistory(marker.index);
+ readFromSettings();
+ refresh();
+ }
+ }
+
+ public void saveMapMarkers(List markers, List markersHistory) {
+ if (markers != null) {
+ List ls = new ArrayList<>(markers.size());
+ List names = new ArrayList<>(markers.size());
+ List colors = new ArrayList<>(markers.size());
+ for (MapMarker marker : markers) {
+ ls.add(marker.point);
+ names.add(PointDescription.serializeToString(marker.pointDescription));
+ colors.add(marker.colorIndex);
+ }
+ settings.saveMapMarkers(ls, names, colors);
+ }
+
+ if (markersHistory != null) {
+ List ls = new ArrayList<>(markersHistory.size());
+ List names = new ArrayList<>(markersHistory.size());
+ List colors = new ArrayList<>(markersHistory.size());
+ for (MapMarker marker : markersHistory) {
+ ls.add(marker.point);
+ names.add(PointDescription.serializeToString(marker.pointDescription));
+ colors.add(marker.colorIndex);
+ }
+ settings.saveMapMarkersHistory(ls, names, colors);
+ }
+
+ if (markers != null || markersHistory != null) {
+ readFromSettings();
+ refresh();
}
- readFromSettings();
- refresh();
}
public void addListener(StateChangedListener l) {
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index c5ed649abe..15b687c0b8 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -1483,6 +1483,7 @@ public class OsmandSettings {
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
+ public final static int MAP_MARKERS_HISTORY_LIMIT = 30;
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
@@ -1562,6 +1563,16 @@ public class OsmandSettings {
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
colorsKey = MAP_MARKERS_HISTORY_COLOR;
}
+
+ @Override
+ public boolean savePoints(List ps, List ds, List cs) {
+ if (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
+ ps.remove(ps.size() - 1);
+ ds.remove(ds.size() - 1);
+ cs.remove(cs.size() - 1);
+ }
+ return super.savePoints(ps, ds, cs);
+ }
}
private class MapMarkersStorage extends MapPointsStorage {
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index 33b3ad8723..4275970f71 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -110,7 +110,7 @@ public class MapActivityActions implements DialogProvider {
public void addMapMarker(double latitude, double longitude, PointDescription pd) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
- openMapMarkersActivity();
+ //openMapMarkersActivity();
}
public void editWaypoints() {
@@ -572,7 +572,7 @@ public class MapActivityActions implements DialogProvider {
return true;
}
}).reg();
- optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_waypoint)
+ optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_flag_dark)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter> adapter, int itemId, int pos, boolean isChecked) {
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapMarkersActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapMarkersActivity.java
index f24a25676e..5ca4e7e45a 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapMarkersActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapMarkersActivity.java
@@ -1,9 +1,11 @@
package net.osmand.plus.activities;
+import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
+import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -50,6 +52,9 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
((DynamicListView) getListView()).setDynamicListViewCallbacks(this);
swipeDismissListener = new SwipeDismissListViewTouchListener(getListView(),
new SwipeDismissListViewTouchListener.DismissCallbacks() {
+
+ private List