Merge pull request #6769 from osmandapp/RoutePreparationUiImprovements

Improve route statistic legend sorting and fix contrast colors
This commit is contained in:
Alexey 2019-04-02 18:52:21 +03:00 committed by GitHub
commit 1555b34ec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 17 deletions

View file

@ -0,0 +1,13 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="oval">
<stroke
android:width="1dp"
android:color="@color/divider_dark" />
</shape>
</item>
</layer-list>

View file

@ -0,0 +1,13 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="oval">
<stroke
android:width="1dp"
android:color="@color/divider_light" />
</shape>
</item>
</layer-list>

View file

@ -17,7 +17,9 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin" android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@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" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/legend_text" android:id="@+id/legend_text"

View file

@ -1262,6 +1262,7 @@ public class GpxUiHelper {
yr.setTextColor(mainFontColor); yr.setTextColor(mainFontColor);
chart.setFitBars(true); chart.setFitBars(true);
chart.setBorderColor(ContextCompat.getColor(app, nightMode ? R.color.divider_dark : R.color.divider_light));
Legend l = chart.getLegend(); Legend l = chart.getLegend();
l.setEnabled(false); l.setEnabled(false);
@ -1298,7 +1299,6 @@ public class GpxUiHelper {
entries.add(new BarEntry(0, stacks)); entries.add(new BarEntry(0, stacks));
BarDataSet barDataSet = new BarDataSet(entries, ""); BarDataSet barDataSet = new BarDataSet(entries, "");
barDataSet.setColors(colors); barDataSet.setColors(colors);
barDataSet.setBarBorderColor(ContextCompat.getColor(app, nightMode ? R.color.divider_dark : R.color.divider_light));
BarData dataSet = new BarData(barDataSet); BarData dataSet = new BarData(barDataSet);
dataSet.setDrawValues(false); dataSet.setDrawValues(false);
dataSet.setBarWidth(1); dataSet.setBarWidth(1);

View file

@ -1,6 +1,8 @@
package net.osmand.plus.routepreparationmenu.cards; package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.view.ContextThemeWrapper; import android.support.v7.view.ContextThemeWrapper;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -37,6 +39,8 @@ import static net.osmand.router.RouteStatistics.UNDEFINED_ATTR;
public class RouteInfoCard extends BaseCard { public class RouteInfoCard extends BaseCard {
private static final int MINIMUM_CONTRAST_RATIO = 3;
private Statistics routeStatistics; private Statistics routeStatistics;
private GPXUtilities.GPXTrackAnalysis analysis; private GPXUtilities.GPXTrackAnalysis analysis;
@ -103,16 +107,21 @@ public class RouteInfoCard extends BaseCard {
private <E> void attachLegend(ViewGroup container, Statistics<E> routeStatistics) { private <E> void attachLegend(ViewGroup container, Statistics<E> routeStatistics) {
Map<E, RouteSegmentAttribute<E>> partition = routeStatistics.getPartition(); Map<E, RouteSegmentAttribute<E>> partition = routeStatistics.getPartition();
List<E> list = new ArrayList<E>(partition.keySet()); List<Map.Entry<E, RouteSegmentAttribute<E>>> list = new ArrayList<>(partition.entrySet());
sortRouteSegmentAttributes(list); sortRouteSegmentAttributes(list);
ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
LayoutInflater inflater = LayoutInflater.from(ctx); LayoutInflater inflater = LayoutInflater.from(ctx);
for (E key : list) { for (Map.Entry<E, RouteSegmentAttribute<E>> entry : list) {
RouteSegmentAttribute<E> segment = partition.get(key); RouteSegmentAttribute<E> segment = entry.getValue();
View view = inflater.inflate(R.layout.route_details_legend, container, false); 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); ImageView legendIcon = (ImageView) view.findViewById(R.id.legend_icon_color);
legendIcon.setImageDrawable(circle); 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 propertyName = segment.getPropertyName();
String name = SettingsNavigationActivity.getStringPropertyName(app, propertyName, propertyName.replaceAll("_", " ")); String name = SettingsNavigationActivity.getStringPropertyName(app, propertyName, propertyName.replaceAll("_", " "));
Spannable text = getSpanLegend(name, segment); Spannable text = getSpanLegend(name, segment);
@ -123,23 +132,24 @@ public class RouteInfoCard extends BaseCard {
} }
} }
private <E> void sortRouteSegmentAttributes(List<E> list) { private <E> void sortRouteSegmentAttributes(List<Map.Entry<E, RouteSegmentAttribute<E>>> list) {
Collections.sort(list, new Comparator<E>() { Collections.sort(list, new Comparator<Map.Entry<E, RouteSegmentAttribute<E>>>() {
@Override @Override
public int compare(E o1, E o2) { public int compare(Map.Entry<E, RouteSegmentAttribute<E>> o1, Map.Entry<E, RouteSegmentAttribute<E>> o2) {
if (o1 instanceof String && o2 instanceof String) { Object key1 = o1.getKey();
String name1 = (String) o1; Object key2 = o2.getKey();
String name2 = (String) o2; 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; return 1;
} }
if (name2.equalsIgnoreCase(UNDEFINED_ATTR)) { if (((String) key2).equalsIgnoreCase(UNDEFINED_ATTR) || distance1 > distance2) {
return -1; return -1;
} }
return name1.compareTo(name2); } else if (key1 instanceof Boundaries && key2 instanceof Boundaries) {
} else if (o1 instanceof Boundaries && o2 instanceof Boundaries) { return ((Boundaries) key1).compareTo((Boundaries) key2);
return ((Boundaries) o1).compareTo((Boundaries) o2);
} }
return 0; return 0;
} }