Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
e8792e0e39
1 changed files with 23 additions and 9 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -52,6 +53,8 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MapMarker implements LocationPoint {
|
public static class MapMarker implements LocationPoint {
|
||||||
|
private static int[] colors;
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public LatLon point;
|
public LatLon point;
|
||||||
private PointDescription pointDescription;
|
private PointDescription pointDescription;
|
||||||
|
@ -136,24 +139,35 @@ public class MapMarkersHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] colors = new int[]{
|
private static final int[] colorsIds = new int[]{
|
||||||
R.color.marker_blue,
|
R.color.marker_blue,
|
||||||
R.color.marker_green,
|
R.color.marker_green,
|
||||||
R.color.marker_orange,
|
R.color.marker_orange,
|
||||||
R.color.marker_red,
|
R.color.marker_red,
|
||||||
R.color.marker_yellow,
|
R.color.marker_yellow,
|
||||||
R.color.marker_teal,
|
R.color.marker_teal,
|
||||||
R.color.marker_purple,
|
R.color.marker_purple
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int getColorId(int colorIndex) {
|
public static int[] getColors(Context context) {
|
||||||
return (colorIndex >= 0 && colorIndex < colors.length) ? colors[colorIndex] : colors[0];
|
if (colors != null) {
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
colors = new int[colorsIds.length];
|
||||||
|
for (int i = 0; i < colorsIds.length; i++) {
|
||||||
|
colors[i] = ContextCompat.getColor(context, colorsIds[i]);
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getColorIndex(int colorId) {
|
public static int getColorId(int colorIndex) {
|
||||||
|
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getColorIndex(Context context, int color) {
|
||||||
|
int[] colors = getColors(context);
|
||||||
for (int i = 0; i < colors.length; i++) {
|
for (int i = 0; i < colors.length; i++) {
|
||||||
int color = colors[i];
|
if (colors[i] == color) {
|
||||||
if (color == colorId) {
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,7 +452,7 @@ public class MapMarkersHelper {
|
||||||
for (MapMarker marker : markers) {
|
for (MapMarker marker : markers) {
|
||||||
if (marker.id.equals(group.getId() + name)) {
|
if (marker.id.equals(group.getId() + name)) {
|
||||||
exists = true;
|
exists = true;
|
||||||
int colorIndex = MapMarker.getColorIndex(ColorDialogs.getNearestColor(group.getColor(), MapMarker.colors));
|
int colorIndex = MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx)));
|
||||||
boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex;
|
boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex;
|
||||||
if (!marker.history && (!marker.point.equals(latLon) || updateColor)) {
|
if (!marker.history && (!marker.point.equals(latLon) || updateColor)) {
|
||||||
for (MapMarker m : mapMarkers) {
|
for (MapMarker m : mapMarkers) {
|
||||||
|
@ -662,7 +676,7 @@ public class MapMarkersHelper {
|
||||||
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
|
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
|
||||||
if (points.size() > 0) {
|
if (points.size() > 0) {
|
||||||
boolean randomColor = group == null || group.getColor() == -1;
|
boolean randomColor = group == null || group.getColor() == -1;
|
||||||
int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ColorDialogs.getNearestColor(group.getColor(), MapMarker.colors));
|
int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx)));
|
||||||
for (int i = 0; i < points.size(); i++) {
|
for (int i = 0; i < points.size(); i++) {
|
||||||
LatLon point = points.get(i);
|
LatLon point = points.get(i);
|
||||||
PointDescription historyName = historyNames.get(i);
|
PointDescription historyName = historyNames.get(i);
|
||||||
|
|
Loading…
Reference in a new issue