From e3a8a7e38311a342a457ca8914db273e4d704e84 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 2 Apr 2019 18:17:03 +0300 Subject: [PATCH 1/2] Improve route statistic legend sorting and fix contrast colors --- .../res/drawable/circle_contour_bg_dark.xml | 13 ++++++ .../res/drawable/circle_contour_bg_light.xml | 13 ++++++ OsmAnd/res/layout/route_details_legend.xml | 4 +- .../net/osmand/plus/helpers/GpxUiHelper.java | 2 +- .../cards/RouteInfoCard.java | 40 ++++++++++++------- 5 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 OsmAnd/res/drawable/circle_contour_bg_dark.xml create mode 100644 OsmAnd/res/drawable/circle_contour_bg_light.xml 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_RATE) { + 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; } From 5cdf51b37ecfe3119f0ee3701d444e09817d85ad Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 2 Apr 2019 18:20:22 +0300 Subject: [PATCH 2/2] Rename constant --- .../osmand/plus/routepreparationmenu/cards/RouteInfoCard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java index 2597da9091..5eb47e79aa 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/RouteInfoCard.java @@ -39,7 +39,7 @@ import static net.osmand.router.RouteStatistics.UNDEFINED_ATTR; public class RouteInfoCard extends BaseCard { - private static final int MINIMUM_CONTRAST_RATE = 3; + private static final int MINIMUM_CONTRAST_RATIO = 3; private Statistics routeStatistics; private GPXUtilities.GPXTrackAnalysis analysis; @@ -119,7 +119,7 @@ public class RouteInfoCard extends BaseCard { 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_RATE) { + if (contrastRatio < MINIMUM_CONTRAST_RATIO) { legendIcon.setBackgroundResource(nightMode ? R.drawable.circle_contour_bg_dark : R.drawable.circle_contour_bg_light); } String propertyName = segment.getPropertyName();