Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-04-08 08:32:46 +02:00
commit aff57c34f7
10 changed files with 55 additions and 164 deletions

View file

@ -9,15 +9,12 @@ import net.osmand.data.PointDescription;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
public class MapMarkersHelper { public class MapMarkersHelper {
public static final int MAP_MARKERS_COLORS_COUNT = 7; public static final int MAP_MARKERS_COLORS_COUNT = 7;
private List<MapMarker> mapMarkers = new ArrayList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> sortedMapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private OsmandSettings settings; private OsmandSettings settings;
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
@ -34,18 +31,16 @@ public class MapMarkersHelper {
public LatLon point; public LatLon point;
private PointDescription pointDescription; private PointDescription pointDescription;
public int colorIndex; public int colorIndex;
public int pos;
public int index; public int index;
public boolean history; public boolean history;
public boolean selected; public boolean selected;
public int dist; public int dist;
public MapMarker(LatLon point, PointDescription name, int colorIndex, int pos, public MapMarker(LatLon point, PointDescription name, int colorIndex,
boolean selected, int index) { boolean selected, int index) {
this.point = point; this.point = point;
this.pointDescription = name; this.pointDescription = name;
this.colorIndex = colorIndex; this.colorIndex = colorIndex;
this.pos = pos;
this.selected = selected; this.selected = selected;
this.index = index; this.index = index;
} }
@ -89,7 +84,6 @@ public class MapMarkersHelper {
MapMarker mapMarker = (MapMarker) o; MapMarker mapMarker = (MapMarker) o;
if (colorIndex != mapMarker.colorIndex) return false; if (colorIndex != mapMarker.colorIndex) return false;
if (pos != mapMarker.pos) return false;
return point.equals(mapMarker.point); return point.equals(mapMarker.point);
} }
@ -98,7 +92,6 @@ public class MapMarkersHelper {
public int hashCode() { public int hashCode() {
int result = point.hashCode(); int result = point.hashCode();
result = 31 * result + colorIndex; result = 31 * result + colorIndex;
result = 31 * result + pos;
return result; return result;
} }
} }
@ -134,32 +127,23 @@ public class MapMarkersHelper {
List<LatLon> ips = settings.getMapMarkersPoints(); List<LatLon> ips = settings.getMapMarkersPoints();
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size()); List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size()); List<Integer> colors = settings.getMapMarkersColors(ips.size());
List<Integer> positions = settings.getMapMarkersPositions(ips.size());
List<Boolean> selections = settings.getMapMarkersSelections(ips.size()); List<Boolean> selections = settings.getMapMarkersSelections(ips.size());
int colorIndex = 0; int colorIndex = 0;
int pos = 0;
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) { if (colors.size() > i) {
colorIndex = colors.get(i); colorIndex = colors.get(i);
} }
if (positions.size() > i) {
pos = positions.get(i);
} else {
pos++;
}
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex,
pos, selections.get(i), i); selections.get(i), i);
mapMarkers.add(mapMarker); mapMarkers.add(mapMarker);
} }
updateSortedArray();
ips = settings.getMapMarkersHistoryPoints(); ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), 0, 0, false, i); PointDescription.deserializeFromString(desc.get(i), ips.get(i)), 0, false, i);
mapMarker.history = true; mapMarker.history = true;
mapMarkersHistory.add(mapMarker); mapMarkersHistory.add(mapMarker);
} }
@ -169,25 +153,6 @@ public class MapMarkersHelper {
} }
} }
private void updateSortedArray() {
sortedMapMarkers.clear();
sortedMapMarkers.addAll(mapMarkers);
Collections.sort(sortedMapMarkers, new Comparator<MapMarker>() {
@Override
public int compare(MapMarker lhs, MapMarker rhs) {
return lhs.pos < rhs.pos ? -1 : (lhs.pos == rhs.pos ? 0 : 1);
}
});
}
public void normalizePositions() {
for (int i = 0; i < sortedMapMarkers.size(); i++) {
MapMarker marker = sortedMapMarkers.get(i);
marker.pos = i;
}
saveMapMarkers(mapMarkers, null);
}
private void lookupAddress(final MapMarker mapMarker, final boolean history) { private void lookupAddress(final MapMarker mapMarker, final boolean history) {
if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) { if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) {
cancelPointAddressRequests(mapMarker.point); cancelPointAddressRequests(mapMarker.point);
@ -204,7 +169,7 @@ public class MapMarkersHelper {
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex);
} else { } else {
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.pos, mapMarker.selected); mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected);
} }
updateMarker(mapMarker); updateMarker(mapMarker);
} }
@ -221,11 +186,10 @@ public class MapMarkersHelper {
for (MapMarker marker : mapMarkers) { for (MapMarker marker : mapMarkers) {
marker.index = ind++; marker.index = ind++;
} }
updateSortedArray();
refresh(); refresh();
} }
public List<MapMarker> getActiveMapMarkers() { public List<MapMarker> getMapMarkers() {
return mapMarkers; return mapMarkers;
} }
@ -237,10 +201,6 @@ public class MapMarkersHelper {
} }
} }
public List<MapMarker> getSortedMapMarkers() {
return sortedMapMarkers;
}
public List<MapMarker> getMapMarkersHistory() { public List<MapMarker> getMapMarkersHistory() {
return mapMarkersHistory; return mapMarkersHistory;
} }
@ -342,8 +302,8 @@ public class MapMarkersHelper {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
} }
if (colorIndex == -1) { if (colorIndex == -1) {
if (sortedMapMarkers.size() > 0) { if (mapMarkers.size() > 0) {
colorIndex = (sortedMapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else { } else {
colorIndex = 0; colorIndex = 0;
} }
@ -369,14 +329,13 @@ public class MapMarkersHelper {
settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, positions, settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, positions,
selections, indexes); selections, indexes);
readFromSettings(); readFromSettings();
normalizePositions();
} }
} }
public void updateMapMarker(MapMarker marker, boolean refresh) { public void updateMapMarker(MapMarker marker, boolean refresh) {
if (marker != null) { if (marker != null) {
settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(), settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(),
marker.pointDescription, marker.colorIndex, marker.pos, marker.selected); marker.pointDescription, marker.colorIndex, marker.selected);
if (refresh) { if (refresh) {
readFromSettings(); readFromSettings();
refresh(); refresh();
@ -387,7 +346,7 @@ public class MapMarkersHelper {
public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) { public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) {
if (marker != null) { if (marker != null) {
settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon, settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon,
marker.pointDescription, marker.colorIndex, marker.pos, marker.selected); marker.pointDescription, marker.colorIndex, marker.selected);
marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude());
readFromSettings(); readFromSettings();
refresh(); refresh();
@ -423,16 +382,14 @@ public class MapMarkersHelper {
List<LatLon> ls = new ArrayList<>(markers.size()); List<LatLon> ls = new ArrayList<>(markers.size());
List<String> names = new ArrayList<>(markers.size()); List<String> names = new ArrayList<>(markers.size());
List<Integer> colors = new ArrayList<>(markers.size()); List<Integer> colors = new ArrayList<>(markers.size());
List<Integer> positions = new ArrayList<>(markers.size());
List<Boolean> selections = new ArrayList<>(markers.size()); List<Boolean> selections = new ArrayList<>(markers.size());
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
ls.add(marker.point); ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription)); names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex); colors.add(marker.colorIndex);
positions.add(marker.pos);
selections.add(marker.selected); selections.add(marker.selected);
} }
settings.saveMapMarkers(ls, names, colors, positions, selections); settings.saveMapMarkers(ls, names, colors, selections);
} }
if (markersHistory != null) { if (markersHistory != null) {

View file

@ -1731,7 +1731,6 @@ public class OsmandSettings {
public final static String MAP_MARKERS_POINT = "map_markers_point"; //$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_COLOR = "map_markers_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$ public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_POSITION = "map_markers_position"; //$NON-NLS-1$
public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$ public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
@ -1845,7 +1844,6 @@ public class OsmandSettings {
.remove(MAP_MARKERS_POINT) .remove(MAP_MARKERS_POINT)
.remove(MAP_MARKERS_DESCRIPTION) .remove(MAP_MARKERS_DESCRIPTION)
.remove(MAP_MARKERS_COLOR) .remove(MAP_MARKERS_COLOR)
.remove(MAP_MARKERS_POSITION)
.remove(MAP_MARKERS_SELECTION) .remove(MAP_MARKERS_SELECTION)
.commit(); .commit();
} }
@ -1896,14 +1894,12 @@ public class OsmandSettings {
private class MapMarkersStorage extends MapPointsStorage { private class MapMarkersStorage extends MapPointsStorage {
protected String colorsKey; protected String colorsKey;
protected String posKey;
protected String selectionKey; protected String selectionKey;
public MapMarkersStorage() { public MapMarkersStorage() {
pointsKey = MAP_MARKERS_POINT; pointsKey = MAP_MARKERS_POINT;
descriptionsKey = MAP_MARKERS_DESCRIPTION; descriptionsKey = MAP_MARKERS_DESCRIPTION;
colorsKey = MAP_MARKERS_COLOR; colorsKey = MAP_MARKERS_COLOR;
posKey = MAP_MARKERS_POSITION;
selectionKey = MAP_MARKERS_SELECTION; selectionKey = MAP_MARKERS_SELECTION;
} }
@ -1928,30 +1924,6 @@ public class OsmandSettings {
return list; return list;
} }
public List<Integer> getPositions(int sz) {
List<Integer> list = new ArrayList<>();
int pos = 0;
String ip = settingsAPI.getString(globalPreferences, posKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String indexStr = tok.nextToken();
int p = Integer.parseInt(indexStr);
list.add(p);
if (p > pos) {
pos = p;
}
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(++pos);
}
return list;
}
public List<Boolean> getSelections(int sz) { public List<Boolean> getSelections(int sz) {
List<Boolean> list = new ArrayList<>(); List<Boolean> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, selectionKey, ""); String ip = settingsAPI.getString(globalPreferences, selectionKey, "");
@ -1977,17 +1949,15 @@ public class OsmandSettings {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
ps.add(index, new LatLon(latitude, longitude)); ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription)); ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex); cs.add(index, colorIndex);
ns.add(index, pos);
bs.add(index, selected); bs.add(index, selected);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
return savePoints(ps, ds, cs, ns, bs); return savePoints(ps, ds, cs, bs);
} }
public boolean insertPoints(double[] latitudes, double[] longitudes, public boolean insertPoints(double[] latitudes, double[] longitudes,
@ -1996,35 +1966,31 @@ public class OsmandSettings {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
for (int i = 0; i < latitudes.length; i++) { for (int i = 0; i < latitudes.length; i++) {
double latitude = latitudes[i]; double latitude = latitudes[i];
double longitude = longitudes[i]; double longitude = longitudes[i];
PointDescription historyDescription = historyDescriptions.get(i); PointDescription historyDescription = historyDescriptions.get(i);
int colorIndex = colorIndexes[i]; int colorIndex = colorIndexes[i];
int pos = positions[i];
boolean selected = selections[i]; boolean selected = selections[i];
int index = indexes[i]; int index = indexes[i];
ps.add(index, new LatLon(latitude, longitude)); ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription)); ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex); cs.add(index, colorIndex);
ns.add(index, pos);
bs.add(index, selected); bs.add(index, selected);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
} }
return savePoints(ps, ds, cs, ns, bs); return savePoints(ps, ds, cs, bs);
} }
public boolean updatePoint(double latitude, double longitude, public boolean updatePoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, PointDescription historyDescription, int colorIndex,
int pos, boolean selected) { boolean selected) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
int index = ps.indexOf(new LatLon(latitude, longitude)); int index = ps.indexOf(new LatLon(latitude, longitude));
if (index != -1) { if (index != -1) {
@ -2032,16 +1998,13 @@ public class OsmandSettings {
if (cs.size() > index) { if (cs.size() > index) {
cs.set(index, colorIndex); cs.set(index, colorIndex);
} }
if (ns.size() > index) {
ns.set(index, pos);
}
if (bs.size() > index) { if (bs.size() > index) {
bs.set(index, selected); bs.set(index, selected);
} }
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
return savePoints(ps, ds, cs, ns, bs); return savePoints(ps, ds, cs, bs);
} else { } else {
return false; return false;
} }
@ -2051,12 +2014,10 @@ public class OsmandSettings {
LatLon latLonNew, LatLon latLonNew,
PointDescription historyDescription, PointDescription historyDescription,
int colorIndex, int colorIndex,
int pos,
boolean selected) { boolean selected) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
int index = ps.indexOf(latLonEx); int index = ps.indexOf(latLonEx);
if (index != -1) { if (index != -1) {
@ -2067,9 +2028,6 @@ public class OsmandSettings {
if (cs.size() > index) { if (cs.size() > index) {
cs.set(index, colorIndex); cs.set(index, colorIndex);
} }
if (ns.size() > index) {
ns.set(index, pos);
}
if (bs.size() > index) { if (bs.size() > index) {
bs.set(index, selected); bs.set(index, selected);
} }
@ -2078,7 +2036,7 @@ public class OsmandSettings {
double lon = latLonNew.getLongitude(); double lon = latLonNew.getLongitude();
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription);
} }
return savePoints(ps, ds, cs, ns, bs); return savePoints(ps, ds, cs, bs);
} else { } else {
return false; return false;
} }
@ -2089,24 +2047,20 @@ public class OsmandSettings {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
ps.remove(index); ps.remove(index);
ds.remove(index); ds.remove(index);
if (cs.size() > index) { if (cs.size() > index) {
cs.remove(index); cs.remove(index);
} }
if (ns.size() > index) {
ns.remove(index);
}
if (bs.size() > index) { if (bs.size() > index) {
bs.remove(index); bs.remove(index);
} }
return savePoints(ps, ds, cs, ns, bs); return savePoints(ps, ds, cs, bs);
} }
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs, public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs,
List<Integer> ns, List<Boolean> bs) { List<Boolean> bs) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) { for (int i = 0; i < ps.size(); i++) {
if (i > 0) { if (i > 0) {
@ -2132,15 +2086,6 @@ public class OsmandSettings {
} }
cb.append(Integer.toString(cs.get(i))); cb.append(Integer.toString(cs.get(i)));
} }
StringBuilder nb = new StringBuilder();
if (ns != null) {
for (int i = 0; i < ns.size(); i++) {
if (i > 0) {
nb.append(",");
}
nb.append(Integer.toString(ns.get(i)));
}
}
StringBuilder bb = new StringBuilder(); StringBuilder bb = new StringBuilder();
if (bs != null) { if (bs != null) {
for (int i = 0; i < bs.size(); i++) { for (int i = 0; i < bs.size(); i++) {
@ -2154,7 +2099,6 @@ public class OsmandSettings {
.putString(pointsKey, sb.toString()) .putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString()) .putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString()) .putString(colorsKey, cb.toString())
.putString(posKey, nb.toString())
.putString(selectionKey, bb.toString()) .putString(selectionKey, bb.toString())
.commit(); .commit();
} }
@ -2345,10 +2289,6 @@ public class OsmandSettings {
return mapMarkersStorage.getColors(sz); return mapMarkersStorage.getColors(sz);
} }
public List<Integer> getMapMarkersPositions(int sz) {
return mapMarkersStorage.getPositions(sz);
}
public List<Boolean> getMapMarkersSelections(int sz) { public List<Boolean> getMapMarkersSelections(int sz) {
return mapMarkersStorage.getSelections(sz); return mapMarkersStorage.getSelections(sz);
} }
@ -2372,29 +2312,24 @@ public class OsmandSettings {
} }
public boolean updateMapMarker(double latitude, double longitude, public boolean updateMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, PointDescription historyDescription, int colorIndex, boolean selected) {
int pos, boolean selected) { return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected);
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex,
pos, selected);
} }
public boolean moveMapMarker(LatLon latLonEx, public boolean moveMapMarker(LatLon latLonEx,
LatLon latLonNew, LatLon latLonNew,
PointDescription historyDescription, PointDescription historyDescription,
int colorIndex, int colorIndex,
int pos,
boolean selected) { boolean selected) {
return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected);
pos, selected);
} }
public boolean deleteMapMarker(int index) { public boolean deleteMapMarker(int index) {
return mapMarkersStorage.deletePoint(index); return mapMarkersStorage.deletePoint(index);
} }
public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Integer> ns, public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Boolean> bs) {
List<Boolean> bs) { return mapMarkersStorage.savePoints(ps, ds, cs, bs);
return mapMarkersStorage.savePoints(ps, ds, cs, ns, bs);
} }

View file

@ -924,8 +924,8 @@ public class MapActivityActions implements DialogProvider {
} }
public void setFirstMapMarkerAsTarget() { public void setFirstMapMarkerAsTarget() {
if (getMyApplication().getMapMarkersHelper().getSortedMapMarkers().size() > 0) { if (getMyApplication().getMapMarkersHelper().getMapMarkers().size() > 0) {
MapMarkersHelper.MapMarker marker = getMyApplication().getMapMarkersHelper().getSortedMapMarkers().get(0); MapMarkersHelper.MapMarker marker = getMyApplication().getMapMarkersHelper().getMapMarkers().get(0);
PointDescription pointDescription = marker.getOriginalPointDescription(); PointDescription pointDescription = marker.getOriginalPointDescription();
if (pointDescription.isLocation() if (pointDescription.isLocation()
&& pointDescription.getName().equals(PointDescription.getAddressNotFoundStr(mapActivity))) { && pointDescription.getName().equals(PointDescription.getAddressNotFoundStr(mapActivity))) {

View file

@ -90,7 +90,6 @@ import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.DismissCallbacks; import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.DismissCallbacks;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.Undoable; import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.Undoable;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.search.core.ObjectType;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
@ -509,7 +508,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} }
if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION
&& getMyApplication().getMapMarkersHelper().getActiveMapMarkers().size() > 0) { && getMyApplication().getMapMarkersHelper().getMapMarkers().size() > 0) {
sort.setVisibility(View.VISIBLE); sort.setVisibility(View.VISIBLE);
sort.setOnClickListener(new View.OnClickListener() { sort.setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -100,7 +100,7 @@ public class MapMarkerDialogHelper {
} }
public boolean hasActiveMarkers() { public boolean hasActiveMarkers() {
return markersHelper.getActiveMapMarkers().size() > 0; return markersHelper.getMapMarkers().size() > 0;
} }
public void setSelectionMode(boolean selectionMode) { public void setSelectionMode(boolean selectionMode) {
@ -166,7 +166,7 @@ public class MapMarkerDialogHelper {
List<Object> activeObjects = getActiveObjects(objects); List<Object> activeObjects = getActiveObjects(objects);
allSelected = true; allSelected = true;
List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getActiveMapMarkers()); List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getMapMarkers());
for (MapMarker m : activeMarkers) { for (MapMarker m : activeMarkers) {
if (!m.selected) { if (!m.selected) {
allSelected = false; allSelected = false;
@ -290,7 +290,7 @@ public class MapMarkerDialogHelper {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
markersHelper.removeMarkersHistory(); markersHelper.removeMarkersHistory();
if (markersHelper.getActiveMapMarkers().size() == 0) { if (markersHelper.getMapMarkers().size() == 0) {
mapActivity.getDashboard().hideDashboard(); mapActivity.getDashboard().hideDashboard();
} else if (helperCallbacks != null) { } else if (helperCallbacks != null) {
helperCallbacks.reloadAdapter(); helperCallbacks.reloadAdapter();
@ -318,7 +318,7 @@ public class MapMarkerDialogHelper {
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
List<MapMarker> markers = markersHelper.getActiveMapMarkers(); List<MapMarker> markers = markersHelper.getMapMarkers();
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
marker.selected = !allSelected; marker.selected = !allSelected;
} }
@ -371,7 +371,7 @@ public class MapMarkerDialogHelper {
} }
}); });
if (!sorted && markersHelper.getActiveMapMarkers().size() > 1) { if (!sorted && markersHelper.getMapMarkers().size() > 1) {
item = optionsMenu.getMenu().add(R.string.shared_string_reverse_order).setIcon( item = optionsMenu.getMenu().add(R.string.shared_string_reverse_order).setIcon(
iconsCache.getThemedIcon(R.drawable.ic_action_undo_dark)); iconsCache.getThemedIcon(R.drawable.ic_action_undo_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -393,7 +393,7 @@ public class MapMarkerDialogHelper {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
generateGPX(markersHelper.getActiveMapMarkers()); generateGPX(markersHelper.getMapMarkers());
return true; return true;
} }
}); });
@ -745,7 +745,7 @@ public class MapMarkerDialogHelper {
LatLon mapLocation = LatLon mapLocation =
new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude()); new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getActiveMapMarkers()); List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getMapMarkers());
calcDistance(mapLocation, activeMarkers); calcDistance(mapLocation, activeMarkers);
if (sorted) { if (sorted) {
Collections.sort(activeMarkers, new Comparator<MapMarker>() { Collections.sort(activeMarkers, new Comparator<MapMarker>() {
@ -899,7 +899,7 @@ public class MapMarkerDialogHelper {
fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); fout = new File(dir, fileName + "_" + (++ind) + ".gpx");
} }
GPXFile file = new GPXFile(); GPXFile file = new GPXFile();
for (MapMarker marker : markersHelper.getActiveMapMarkers()) { for (MapMarker marker : markersHelper.getMapMarkers()) {
WptPt wpt = new WptPt(); WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude(); wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude(); wpt.lon = marker.getLongitude();

View file

@ -458,7 +458,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
private void selectMapMarker(final int index, final boolean target) { private void selectMapMarker(final int index, final boolean target) {
if (index != -1) { if (index != -1) {
MapMarker m = mapActivity.getMyApplication().getMapMarkersHelper().getActiveMapMarkers().get(index); MapMarker m = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().get(index);
LatLon point = new LatLon(m.getLatitude(), m.getLongitude()); LatLon point = new LatLon(m.getLatitude(), m.getLongitude());
if (target) { if (target) {
getTargets().navigateToPoint(point, true, -1, m.getPointDescription(mapActivity)); getTargets().navigateToPoint(point, true, -1, m.getPointDescription(mapActivity));
@ -794,7 +794,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
private void addMarkersToSpinner(List<RouteSpinnerRow> actions) { private void addMarkersToSpinner(List<RouteSpinnerRow> actions) {
MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
List<MapMarker> markers = markersHelper.getActiveMapMarkers(); List<MapMarker> markers = markersHelper.getMapMarkers();
if (markers.size() > 0) { if (markers.size() > 0) {
MapMarker m = markers.get(0); MapMarker m = markers.get(0);
actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_1_ID, actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_1_ID,

View file

@ -89,7 +89,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment {
ListView listView = (ListView) view.findViewById(android.R.id.list); ListView listView = (ListView) view.findViewById(android.R.id.list);
final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter(); final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getActiveMapMarkers(); List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getMapMarkers();
if (markers.size() > 0) { if (markers.size() > 0) {
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
adapter.add(marker); adapter.add(marker);

View file

@ -258,7 +258,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
} }
List<MapMarker> activeMapMarkers = markersHelper.getActiveMapMarkers(); List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
for (MapMarker marker : activeMapMarkers) { for (MapMarker marker : activeMapMarkers) {
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker)
&& !isInMotion(marker)) { && !isInMotion(marker)) {
@ -282,9 +282,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
loc = tileBox.getCenterLatLon(); loc = tileBox.getCenterLatLon();
} }
if (loc != null) { if (loc != null) {
List<MapMarker> sortedMapMarkers = markersHelper.getSortedMapMarkers(); List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
int i = 0; int i = 0;
for (MapMarker marker : sortedMapMarkers) { for (MapMarker marker : mapMarkers) {
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
canvas.save(); canvas.save();
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(),
@ -432,7 +432,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
} }
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> markers = markersHelper.getActiveMapMarkers(); List<MapMarker> markers = markersHelper.getMapMarkers();
int r = getRadiusPoi(tileBox); int r = getRadiusPoi(tileBox);
for (int i = 0; i < markers.size(); i++) { for (int i = 0; i < markers.size(); i++) {
MapMarker marker = markers.get(i); MapMarker marker = markers.get(i);
@ -495,12 +495,12 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
if (o instanceof MapMarker) { if (o instanceof MapMarker) {
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
MapMarker marker = (MapMarker) o; MapMarker marker = (MapMarker) o;
List<MapMarker> sortedMarkers = markersHelper.getSortedMapMarkers(); List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
int i = sortedMarkers.indexOf(marker); int i = mapMarkers.indexOf(marker);
if (i != -1) { if (i != -1) {
sortedMarkers.remove(i); mapMarkers.remove(i);
sortedMarkers.add(0, marker); mapMarkers.add(0, marker);
markersHelper.normalizePositions(); markersHelper.saveMapMarkers(mapMarkers, null);
} }
} }
} }
@ -525,9 +525,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
marker.getOriginalPointDescription().setName(PointDescription.getSearchAddressStr(map)); marker.getOriginalPointDescription().setName(PointDescription.getSearchAddressStr(map));
markersHelper.moveMapMarker(marker, position); markersHelper.moveMapMarker(marker, position);
int index = markersHelper.getActiveMapMarkers().indexOf(marker); int index = markersHelper.getMapMarkers().indexOf(marker);
if (index != -1) { if (index != -1) {
newObject = markersHelper.getActiveMapMarkers().get(index); newObject = markersHelper.getMapMarkers().get(index);
} }
result = true; result = true;
} }

View file

@ -93,7 +93,7 @@ public class MapMarkersWidgetsFactory {
}); });
IconsCache iconsCache = map.getMyApplication().getIconsCache(); IconsCache iconsCache = map.getMyApplication().getIconsCache();
if (isLandscapeLayout() && helper.getSortedMapMarkers().size() > 1) { if (isLandscapeLayout() && helper.getMapMarkers().size() > 1) {
moreButton.setVisibility(View.GONE); moreButton.setVisibility(View.GONE);
} else { } else {
moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color)); moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
@ -132,16 +132,16 @@ public class MapMarkersWidgetsFactory {
} }
private void removeMarker(int index) { private void removeMarker(int index) {
if (helper.getSortedMapMarkers().size() > index) { if (helper.getMapMarkers().size() > index) {
MapMarker marker = helper.getSortedMapMarkers().get(index); MapMarker marker = helper.getMapMarkers().get(index);
helper.removeMapMarker(marker.index); helper.removeMapMarker(marker.index);
helper.addMapMarkerHistory(marker); helper.addMapMarkerHistory(marker);
} }
} }
private void showMarkerOnMap(int index) { private void showMarkerOnMap(int index) {
if (helper.getSortedMapMarkers().size() > index) { if (helper.getMapMarkers().size() > index) {
MapMarker marker = helper.getSortedMapMarkers().get(index); MapMarker marker = helper.getMapMarkers().get(index);
AnimateDraggingMapThread thread = map.getMapView().getAnimatedDraggingThread(); AnimateDraggingMapThread thread = map.getMapView().getAnimatedDraggingThread();
LatLon pointToNavigate = marker.point; LatLon pointToNavigate = marker.point;
if (pointToNavigate != null) { if (pointToNavigate != null) {
@ -195,7 +195,7 @@ public class MapMarkersWidgetsFactory {
} }
} }
List<MapMarker> markers = helper.getSortedMapMarkers(); List<MapMarker> markers = helper.getMapMarkers();
if (zoom < 3 || markers.size() == 0 if (zoom < 3 || markers.size() == 0
|| !map.getMyApplication().getSettings().MAP_MARKERS_MODE.get().isToolbar() || !map.getMyApplication().getSettings().MAP_MARKERS_MODE.get().isToolbar()
|| map.getMyApplication().getRoutingHelper().isFollowingMode() || map.getMyApplication().getRoutingHelper().isFollowingMode()
@ -385,7 +385,7 @@ public class MapMarkersWidgetsFactory {
} }
private MapMarker getMarker() { private MapMarker getMarker() {
List<MapMarker> markers = helper.getSortedMapMarkers(); List<MapMarker> markers = helper.getMapMarkers();
if (firstMarker) { if (firstMarker) {
if (markers.size() > 0) { if (markers.size() > 0) {
return markers.get(0); return markers.get(0);

View file

@ -672,7 +672,7 @@ public class RouteInfoWidgetsFactory {
Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation(); Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation();
LatLon l = getPointToNavigate(); LatLon l = getPointToNavigate();
if (l == null) { if (l == null) {
List<MapMarker> markers = getOsmandApplication().getMapMarkersHelper().getSortedMapMarkers(); List<MapMarker> markers = getOsmandApplication().getMapMarkersHelper().getMapMarkers();
if (markers.size() > 0) { if (markers.size() > 0) {
l = markers.get(0).point; l = markers.get(0).point;
} }