From ba19772b588d635e48a8ae2307d2fdc3a5a66d8f Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 7 Dec 2020 12:28:53 +0200 Subject: [PATCH 1/2] Fix "Custom graph legend doesn't show when only one type available" --- .../graph/CustomGraphAdapter.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/graph/CustomGraphAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/graph/CustomGraphAdapter.java index 1bc763b165..32a1f6a654 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/graph/CustomGraphAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/graph/CustomGraphAdapter.java @@ -61,11 +61,14 @@ public class CustomGraphAdapter extends BaseGraphAdapter elems = getStatistics().elements; + List elems = getStatistics().elements; int i = h.getStackIndex(); if (i >= 0 && elems.size() > i) { selectedPropertyName = elems.get(i).getPropertyName(); updateLegend(); + } else if (LegendViewType.ONE_ELEMENT == legendViewType && elems.size() == 1) { + selectedPropertyName = elems.get(0).getPropertyName(); + updateLegend(); } } @@ -116,19 +119,20 @@ public class CustomGraphAdapter extends BaseGraphAdapter attributes = getSegmentsList(); + if (attributes == null) return; switch (legendViewType) { case ONE_ELEMENT: - for (RouteSegmentAttribute segment : getSegmentsList()) { - if (segment.getPropertyName().equals(selectedPropertyName)) { - attachLegend(Collections.singletonList(segment), null); + for (RouteSegmentAttribute attribute : attributes) { + if (attribute.getPropertyName().equals(selectedPropertyName)) { + attachLegend(Collections.singletonList(attribute), null); break; } } break; case ALL_AS_LIST: - attachLegend(getSegmentsList(), selectedPropertyName); + attachLegend(attributes, selectedPropertyName); break; } } @@ -137,7 +141,7 @@ public class CustomGraphAdapter extends BaseGraphAdapter Date: Mon, 7 Dec 2020 12:31:14 +0200 Subject: [PATCH 2/2] "Map center" jumps to previous point location after route calculation --- .../plus/mapcontextmenu/other/TrackDetailsMenu.java | 8 +++++++- .../net/osmand/plus/measurementtool/GraphsCard.java | 2 +- .../plus/measurementtool/graph/GraphAdapterHelper.java | 10 +++++----- .../routepreparationmenu/RouteDetailsFragment.java | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index f1be5a9fad..94811ff241 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -473,6 +473,10 @@ public class TrackDetailsMenu { } public void refreshChart(LineChart chart, boolean forceFit) { + refreshChart(chart, true, forceFit); + } + + public void refreshChart(LineChart chart, boolean fitTrackOnMap, boolean forceFit) { MapActivity mapActivity = getMapActivity(); GpxDisplayItem gpxItem = getGpxItem(); if (mapActivity == null || gpxItem == null) { @@ -529,7 +533,9 @@ public class TrackDetailsMenu { if (location != null) { mapActivity.refreshMap(); } - fitTrackOnMap(chart, location, forceFit); + if (fitTrackOnMap) { + fitTrackOnMap(chart, location, forceFit); + } } public boolean shouldShowXAxisPoints () { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/GraphsCard.java b/OsmAnd/src/net/osmand/plus/measurementtool/GraphsCard.java index ef376f48fd..deb636420a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/GraphsCard.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/GraphsCard.java @@ -311,7 +311,7 @@ public class GraphsCard extends BaseCard implements OnUpdateInfoListener { private void updateChartOnMap() { if (hasVisibleGraph()) { trackDetailsMenu.reset(); - refreshMapCallback.refreshMap(false); + refreshMapCallback.refreshMap(false, false); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/graph/GraphAdapterHelper.java b/OsmAnd/src/net/osmand/plus/measurementtool/graph/GraphAdapterHelper.java index 94b8a45d24..323a2b120b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/graph/GraphAdapterHelper.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/graph/GraphAdapterHelper.java @@ -105,11 +105,11 @@ public class GraphAdapterHelper { @NonNull final TrackDetailsMenu detailsMenu) { final RefreshMapCallback refreshMapCallback = new RefreshMapCallback() { @Override - public void refreshMap(boolean forceFit) { + public void refreshMap(boolean fitTrackOnMap, boolean forceFit) { LineChart chart = graphAdapter.getChart(); OsmandApplication app = mapActivity.getMyApplication(); if (!app.getRoutingHelper().isFollowingMode()) { - detailsMenu.refreshChart(chart, forceFit); + detailsMenu.refreshChart(chart, fitTrackOnMap, forceFit); mapActivity.refreshMap(); } } @@ -120,7 +120,7 @@ public class GraphAdapterHelper { @Override public void onValueSelected(Entry e, Highlight h) { - refreshMapCallback.refreshMap(false); + refreshMapCallback.refreshMap(true, false); } @Override @@ -141,7 +141,7 @@ public class GraphAdapterHelper { lastPerformedGesture == ChartTouchListener.ChartGesture.PINCH_ZOOM || lastPerformedGesture == ChartTouchListener.ChartGesture.DOUBLE_TAP || lastPerformedGesture == ChartTouchListener.ChartGesture.ROTATE) { - refreshMapCallback.refreshMap(true); + refreshMapCallback.refreshMap(true, true); } } }); @@ -150,6 +150,6 @@ public class GraphAdapterHelper { } public interface RefreshMapCallback { - void refreshMap(boolean forceFit); + void refreshMap(boolean fitTrackOnMap, boolean forceFit); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index 0747c650c5..ba8e6133c3 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -369,7 +369,7 @@ public class RouteDetailsFragment extends ContextMenuFragment super.calculateLayout(view, initLayout); if (!initLayout && getCurrentMenuState() != MenuState.FULL_SCREEN) { if (refreshMapCallback != null) { - refreshMapCallback.refreshMap(false); + refreshMapCallback.refreshMap(false, false); } } }