diff --git a/OsmAnd/res/drawable/circle_contour_bg_dark.xml b/OsmAnd/res/drawable/circle_contour_bg_dark.xml new file mode 100644 index 0000000000..1642fc8cf7 --- /dev/null +++ b/OsmAnd/res/drawable/circle_contour_bg_dark.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/OsmAnd/res/drawable/circle_contour_bg_light.xml b/OsmAnd/res/drawable/circle_contour_bg_light.xml new file mode 100644 index 0000000000..5be9bc1320 --- /dev/null +++ b/OsmAnd/res/drawable/circle_contour_bg_light.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/OsmAnd/res/layout/route_details_legend.xml b/OsmAnd/res/layout/route_details_legend.xml index acca375cb7..69a3b8803a 100644 --- a/OsmAnd/res/layout/route_details_legend.xml +++ b/OsmAnd/res/layout/route_details_legend.xml @@ -17,7 +17,9 @@ android:layout_gravity="center_vertical" android:layout_marginEnd="@dimen/bottom_sheet_icon_margin" android:layout_marginRight="@dimen/bottom_sheet_icon_margin" - tools:src="@drawable/ic_action_circle" /> + tools:background="@drawable/circle_contour_bg_light" + tools:src="@drawable/ic_action_circle" + tools:tint="?attr/active_color_basic" /> void attachLegend(ViewGroup container, Statistics routeStatistics) { Map> partition = routeStatistics.getPartition(); - List list = new ArrayList(partition.keySet()); + List>> list = new ArrayList<>(partition.entrySet()); sortRouteSegmentAttributes(list); ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); LayoutInflater inflater = LayoutInflater.from(ctx); - for (E key : list) { - RouteSegmentAttribute segment = partition.get(key); + for (Map.Entry> entry : list) { + RouteSegmentAttribute segment = entry.getValue(); View view = inflater.inflate(R.layout.route_details_legend, container, false); - Drawable circle = app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, segment.getColor()); + int segmentColor = segment.getColor(); + Drawable circle = app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, segmentColor); ImageView legendIcon = (ImageView) view.findViewById(R.id.legend_icon_color); legendIcon.setImageDrawable(circle); + double contrastRatio = ColorUtils.calculateContrast(segmentColor, ContextCompat.getColor(app, nightMode ? R.color.card_and_list_background_dark : R.color.card_and_list_background_light)); + if (contrastRatio < MINIMUM_CONTRAST_RATIO) { + legendIcon.setBackgroundResource(nightMode ? R.drawable.circle_contour_bg_dark : R.drawable.circle_contour_bg_light); + } String propertyName = segment.getPropertyName(); String name = SettingsNavigationActivity.getStringPropertyName(app, propertyName, propertyName.replaceAll("_", " ")); Spannable text = getSpanLegend(name, segment); @@ -123,23 +132,24 @@ public class RouteInfoCard extends BaseCard { } } - private void sortRouteSegmentAttributes(List list) { - Collections.sort(list, new Comparator() { + private void sortRouteSegmentAttributes(List>> list) { + Collections.sort(list, new Comparator>>() { @Override - public int compare(E o1, E o2) { - if (o1 instanceof String && o2 instanceof String) { - String name1 = (String) o1; - String name2 = (String) o2; + public int compare(Map.Entry> o1, Map.Entry> o2) { + Object key1 = o1.getKey(); + Object key2 = o2.getKey(); + if (key1 instanceof String && key2 instanceof String) { + float distance1 = o1.getValue().getDistance(); + float distance2 = o2.getValue().getDistance(); - if (name1.equalsIgnoreCase(UNDEFINED_ATTR)) { + if (((String) key1).equalsIgnoreCase(UNDEFINED_ATTR) || distance1 < distance2) { return 1; } - if (name2.equalsIgnoreCase(UNDEFINED_ATTR)) { + if (((String) key2).equalsIgnoreCase(UNDEFINED_ATTR) || distance1 > distance2) { return -1; } - return name1.compareTo(name2); - } else if (o1 instanceof Boundaries && o2 instanceof Boundaries) { - return ((Boundaries) o1).compareTo((Boundaries) o2); + } else if (key1 instanceof Boundaries && key2 instanceof Boundaries) { + return ((Boundaries) key1).compareTo((Boundaries) key2); } return 0; }