Merge branch 'r3.3'

This commit is contained in:
crimean 2019-04-13 15:11:15 +03:00
commit d9dafd7cf8
3 changed files with 57 additions and 23 deletions

View file

@ -1300,6 +1300,7 @@ public class GpxUiHelper {
entries.add(new BarEntry(0, stacks));
BarDataSet barDataSet = new BarDataSet(entries, "");
barDataSet.setColors(colors);
barDataSet.setHighLightColor(ContextCompat.getColor(app, R.color.color_white));
BarData dataSet = new BarData(barDataSet);
dataSet.setDrawValues(false);
dataSet.setBarWidth(1);

View file

@ -317,19 +317,19 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
GPXUtilities.GPXTrackAnalysis analysis = gpx.getAnalysis(0);
RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteClassStatistic(), analysis);
createRouteCard(cardsContainer, routeClassCard);
addRouteCard(cardsContainer, routeClassCard);
RouteInfoCard routeSurfaceCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteSurfaceStatistic(), analysis);
createRouteCard(cardsContainer, routeSurfaceCard);
addRouteCard(cardsContainer, routeSurfaceCard);
if (slopeDataSet != null) {
List<Incline> inclines = createInclinesAndAdd100MetersWith0Incline(slopeDataSet.getValues());
RouteInfoCard routeSteepnessCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteSteepnessStatistic(inclines), analysis);
createRouteCard(cardsContainer, routeSteepnessCard);
addRouteCard(cardsContainer, routeSteepnessCard);
}
RouteInfoCard routeSmoothnessCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteSmoothnessStatistic(), analysis);
createRouteCard(cardsContainer, routeSmoothnessCard);
addRouteCard(cardsContainer, routeSmoothnessCard);
}
}
}
@ -347,7 +347,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
buildRowDivider(cardsContainer, false);
}
private void createRouteCard(LinearLayout cardsContainer, RouteInfoCard routeInfoCard) {
private void addRouteCard(LinearLayout cardsContainer, RouteInfoCard routeInfoCard) {
OsmandApplication app = requireMyApplication();
menuCards.add(routeInfoCard);
routeInfoCard.setListener(this);

View file

@ -16,8 +16,11 @@ import android.widget.TextView;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -25,7 +28,6 @@ import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.router.RouteStatistics.Boundaries;
import net.osmand.router.RouteStatistics.RouteSegmentAttribute;
import net.osmand.router.RouteStatistics.StatisticType;
import net.osmand.router.RouteStatistics.Statistics;
import net.osmand.util.Algorithms;
@ -42,11 +44,12 @@ public class RouteInfoCard extends BaseCard {
private static final int MINIMUM_CONTRAST_RATIO = 3;
private Statistics routeStatistics;
private GPXUtilities.GPXTrackAnalysis analysis;
private GPXTrackAnalysis analysis;
private String selectedPropertyName;
private boolean showLegend;
public RouteInfoCard(MapActivity mapActivity, Statistics routeStatistics, GPXUtilities.GPXTrackAnalysis analysis) {
public RouteInfoCard(MapActivity mapActivity, Statistics routeStatistics, GPXTrackAnalysis analysis) {
super(mapActivity);
this.routeStatistics = routeStatistics;
this.analysis = analysis;
@ -59,12 +62,41 @@ public class RouteInfoCard extends BaseCard {
@Override
protected void updateContent() {
updateContent(routeStatistics);
}
private <E> void updateContent(final Statistics<E> routeStatistics) {
updateHeader();
final HorizontalBarChart chart = (HorizontalBarChart) view.findViewById(R.id.chart);
GpxUiHelper.setupHorizontalGPXChart(app, chart, 5, 9, 24, true, nightMode);
BarData barData = GpxUiHelper.buildStatisticChart(app, chart, routeStatistics, analysis, true, nightMode);
chart.setData(barData);
final LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
List<RouteSegmentAttribute<E>> elems = routeStatistics.getElements();
int i = h.getStackIndex();
if (elems.size() > i) {
selectedPropertyName = elems.get(i).getPropertyName();
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
if (!showLegend) {
showLegend = true;
}
container.removeAllViews();
attachLegend(container, routeStatistics);
setLayoutNeeded();
}
}
@Override
public void onNothingSelected() {
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
showLegend = false;
container.removeAllViews();
setLayoutNeeded();
}
});
LinearLayout container = (LinearLayout) view.findViewById(R.id.route_items);
container.removeAllViews();
if (showLegend) {
attachLegend(container, routeStatistics);
@ -92,16 +124,17 @@ public class RouteInfoCard extends BaseCard {
}
private String getInfoType() {
if (routeStatistics.getStatisticType() == StatisticType.CLASS) {
return app.getString(R.string.road_types);
} else if (routeStatistics.getStatisticType() == StatisticType.STEEPNESS) {
return app.getString(R.string.route_steepness_stat_container);
} else if (routeStatistics.getStatisticType() == StatisticType.SMOOTHNESS) {
return app.getString(R.string.route_smoothness_stat_container);
} else if (routeStatistics.getStatisticType() == StatisticType.SURFACE) {
return app.getString(R.string.route_surface_stat_container);
} else {
return "";
switch (routeStatistics.getStatisticType()) {
case CLASS:
return app.getString(R.string.road_types);
case STEEPNESS:
return app.getString(R.string.route_steepness_stat_container);
case SMOOTHNESS:
return app.getString(R.string.route_smoothness_stat_container);
case SURFACE:
return app.getString(R.string.route_surface_stat_container);
default:
return "";
}
}
@ -124,7 +157,7 @@ public class RouteInfoCard extends BaseCard {
}
String propertyName = segment.getPropertyName();
String name = SettingsNavigationActivity.getStringPropertyName(app, propertyName, propertyName.replaceAll("_", " "));
Spannable text = getSpanLegend(name, segment);
Spannable text = getSpanLegend(name, segment, segment.getPropertyName().equals(selectedPropertyName));
TextView legend = (TextView) view.findViewById(R.id.legend_text);
legend.setText(text);
@ -156,12 +189,12 @@ public class RouteInfoCard extends BaseCard {
});
}
private Spannable getSpanLegend(String title, RouteSegmentAttribute segment) {
private Spannable getSpanLegend(String title, RouteSegmentAttribute segment, boolean selected) {
String formattedDistance = OsmAndFormatter.getFormattedDistance(segment.getDistance(), getMyApplication());
title = Algorithms.capitalizeFirstLetter(title);
SpannableStringBuilder spannable = new SpannableStringBuilder(title);
spannable.append(": ");
int startIndex = spannable.length();
int startIndex = selected ? -0 : spannable.length();
spannable.append(formattedDistance);
spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);