Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
565de1a651
5 changed files with 112 additions and 57 deletions
|
@ -177,7 +177,7 @@ public class FavouritesDbHelper {
|
|||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ public class FavouritesDbHelper {
|
|||
p.setLatitude(lat);
|
||||
p.setLongitude(lon);
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE));
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -597,6 +597,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setColor(color);
|
||||
}
|
||||
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
|
||||
}
|
||||
if (group.visible != visible) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
|
@ -604,7 +605,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setVisible(visible);
|
||||
}
|
||||
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
}
|
||||
if (!group.name.equals(newName)) {
|
||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||
|
@ -624,7 +625,7 @@ public class FavouritesDbHelper {
|
|||
renamedGroup.points.add(p);
|
||||
}
|
||||
}
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
@ -134,34 +136,28 @@ public class MapMarkersHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static int[] colors = new int[]{
|
||||
R.color.marker_blue,
|
||||
R.color.marker_green,
|
||||
R.color.marker_orange,
|
||||
R.color.marker_red,
|
||||
R.color.marker_yellow,
|
||||
R.color.marker_teal,
|
||||
R.color.marker_purple,
|
||||
};
|
||||
|
||||
public static int getColorId(int colorIndex) {
|
||||
int colorId;
|
||||
switch (colorIndex) {
|
||||
case 0:
|
||||
colorId = R.color.marker_blue;
|
||||
break;
|
||||
case 1:
|
||||
colorId = R.color.marker_green;
|
||||
break;
|
||||
case 2:
|
||||
colorId = R.color.marker_orange;
|
||||
break;
|
||||
case 3:
|
||||
colorId = R.color.marker_red;
|
||||
break;
|
||||
case 4:
|
||||
colorId = R.color.marker_yellow;
|
||||
break;
|
||||
case 5:
|
||||
colorId = R.color.marker_teal;
|
||||
break;
|
||||
case 6:
|
||||
colorId = R.color.marker_purple;
|
||||
break;
|
||||
default:
|
||||
colorId = R.color.marker_blue;
|
||||
return (colorIndex >= 0 && colorIndex < colors.length) ? colors[colorIndex] : colors[0];
|
||||
}
|
||||
return colorId;
|
||||
|
||||
public static int getColorIndex(int colorId) {
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int color = colors[i];
|
||||
if (color == colorId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,11 +169,20 @@ public class MapMarkersHelper {
|
|||
private String id;
|
||||
private String name;
|
||||
private int type;
|
||||
private int color;
|
||||
|
||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type, int color) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.color = -1;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -191,6 +196,10 @@ public class MapMarkersHelper {
|
|||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public MapMarkersHelper(OsmandApplication ctx) {
|
||||
|
@ -386,7 +395,7 @@ public class MapMarkersHelper {
|
|||
List<MapMarker> dbMarkers = markersDbHelper.getMarkersFromGroup(group);
|
||||
|
||||
if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) {
|
||||
FavouritesDbHelper.FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
|
||||
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
|
||||
if (favGroup == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -429,10 +438,13 @@ public class MapMarkersHelper {
|
|||
for (MapMarker marker : markers) {
|
||||
if (marker.id.equals(group.getId() + name)) {
|
||||
exists = true;
|
||||
if (!marker.history && !marker.point.equals(latLon)) {
|
||||
int colorIndex = MapMarker.getColorIndex(ColorDialogs.getNearestColor(group.getColor(), MapMarker.colors));
|
||||
boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex;
|
||||
if (!marker.history && (!marker.point.equals(latLon) || updateColor)) {
|
||||
for (MapMarker m : mapMarkers) {
|
||||
if (m.id.equals(marker.id)) {
|
||||
m.point = latLon;
|
||||
m.colorIndex = colorIndex;
|
||||
updateMapMarker(m, true);
|
||||
break;
|
||||
}
|
||||
|
@ -649,7 +661,8 @@ public class MapMarkersHelper {
|
|||
|
||||
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
|
||||
if (points.size() > 0) {
|
||||
int colorIndex = -1;
|
||||
boolean randomColor = group == null || group.getColor() == -1;
|
||||
int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ColorDialogs.getNearestColor(group.getColor(), MapMarker.colors));
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
LatLon point = points.get(i);
|
||||
PointDescription historyName = historyNames.get(i);
|
||||
|
@ -662,6 +675,7 @@ public class MapMarkersHelper {
|
|||
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
|
||||
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
|
||||
}
|
||||
if (randomColor) {
|
||||
if (colorIndex == -1) {
|
||||
if (mapMarkers.size() > 0) {
|
||||
colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
|
||||
|
@ -671,6 +685,7 @@ public class MapMarkersHelper {
|
|||
} else {
|
||||
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
|
||||
if (group != null) {
|
||||
|
|
|
@ -176,7 +176,8 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
});
|
||||
|
||||
final MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||
final MarkersSyncGroup syncGroup =
|
||||
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
||||
|
||||
View addToMarkersView = view.findViewById(R.id.add_to_markers_view);
|
||||
|
|
|
@ -407,7 +407,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
List<PointDescription> names = new LinkedList<>();
|
||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
MarkersSyncGroup syncGr = new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||
MarkersSyncGroup syncGr =
|
||||
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
markersHelper.addMarkersSyncGroup(syncGr);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
public class ColorDialogs {
|
||||
|
@ -66,6 +66,43 @@ public class ColorDialogs {
|
|||
"brown"
|
||||
};
|
||||
|
||||
private static double getDistanceBetweenColors(int color1, int color2) {
|
||||
double distance;
|
||||
|
||||
double r1 = Color.red(color1);
|
||||
double g1 = Color.green(color1);
|
||||
double b1 = Color.blue(color1);
|
||||
double a1 = Color.alpha(color1);
|
||||
|
||||
double r2 = Color.red(color2);
|
||||
double g2 = Color.green(color2);
|
||||
double b2 = Color.blue(color2);
|
||||
double a2 = Color.alpha(color2);
|
||||
|
||||
distance = Math.sqrt(Math.pow(r1 - r2, 2) + Math.pow(g1 - g2, 2) + Math.pow(b1 - b2, 2));
|
||||
|
||||
if (distance == 0) {
|
||||
distance = Math.sqrt(Math.pow(a1 - a2, 2));
|
||||
}
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
public static int getNearestColor(int source, int[] colors) {
|
||||
double distance = Double.MAX_VALUE;
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
double newDistance = getDistanceBetweenColors(source, colors[i]);
|
||||
if (newDistance < distance) {
|
||||
index = i;
|
||||
distance = newDistance;
|
||||
}
|
||||
}
|
||||
|
||||
return colors[index];
|
||||
}
|
||||
|
||||
public static int getColorByTag(String tag) {
|
||||
String t = tag.toLowerCase();
|
||||
for (int i = 0; i < paletteColorTags.length; i++) {
|
||||
|
|
Loading…
Reference in a new issue