Fix chart on map

This commit is contained in:
nazar-kutz 2020-11-05 01:02:16 +02:00
parent 38ebaccc28
commit beddaf8209
7 changed files with 82 additions and 32 deletions

View file

@ -125,8 +125,7 @@ public class TrackDetailsMenu {
hidding = true; hidding = true;
fragment.dismiss(backPressed); fragment.dismiss(backPressed);
} else { } else {
segment = null; reset();
trackChartPoints = null;
} }
} }
@ -274,8 +273,7 @@ public class TrackDetailsMenu {
if (hidding) { if (hidding) {
hidding = false; hidding = false;
visible = false; visible = false;
segment = null; reset();
trackChartPoints = null;
} }
} }
@ -532,6 +530,11 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit); fitTrackOnMap(chart, location, forceFit);
} }
public void reset() {
segment = null;
trackChartPoints = null;
}
private List<LatLon> getXAxisPoints(LineChart chart) { private List<LatLon> getXAxisPoints(LineChart chart) {
float[] entries = chart.getXAxis().mEntries; float[] entries = chart.getXAxis().mEntries;
LineData lineData = chart.getLineData(); LineData lineData = chart.getLineData();

View file

@ -34,6 +34,7 @@ import net.osmand.plus.measurementtool.graph.CustomGraphAdapter;
import net.osmand.plus.measurementtool.graph.CustomGraphAdapter.LegendViewType; import net.osmand.plus.measurementtool.graph.CustomGraphAdapter.LegendViewType;
import net.osmand.plus.measurementtool.graph.BaseGraphAdapter; import net.osmand.plus.measurementtool.graph.BaseGraphAdapter;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper; import net.osmand.plus.measurementtool.graph.GraphAdapterHelper;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper.RefreshMapCallback;
import net.osmand.plus.routepreparationmenu.RouteDetailsFragment; import net.osmand.plus.routepreparationmenu.RouteDetailsFragment;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.router.RouteSegmentResult; import net.osmand.router.RouteSegmentResult;
@ -59,6 +60,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
private MeasurementEditingContext editingCtx; private MeasurementEditingContext editingCtx;
private MeasurementToolFragment fragment; private MeasurementToolFragment fragment;
private TrackDetailsMenu trackDetailsMenu; private TrackDetailsMenu trackDetailsMenu;
private RefreshMapCallback refreshMapCallback;
private GPXFile gpxFile; private GPXFile gpxFile;
private GPXTrackAnalysis analysis; private GPXTrackAnalysis analysis;
private GpxDisplayItem gpxItem; private GpxDisplayItem gpxItem;
@ -105,7 +107,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
}); });
GraphAdapterHelper.bindGraphAdapters(commonGraphAdapter, Arrays.asList((BaseGraphAdapter) customGraphAdapter), (ViewGroup) view); GraphAdapterHelper.bindGraphAdapters(commonGraphAdapter, Arrays.asList((BaseGraphAdapter) customGraphAdapter), (ViewGroup) view);
GraphAdapterHelper.bindToMap(commonGraphAdapter, mapActivity, trackDetailsMenu); refreshMapCallback = GraphAdapterHelper.bindToMap(commonGraphAdapter, mapActivity, trackDetailsMenu);
fullUpdate(); fullUpdate();
} }
@ -116,7 +118,9 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
@Override @Override
public void onUpdateAdditionalInfo() { public void onUpdateAdditionalInfo() {
fullUpdate(); if (editingCtx != null) {
fullUpdate();
}
} }
private void fullUpdate() { private void fullUpdate() {
@ -126,6 +130,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
updateMenu(); updateMenu();
} }
updateView(); updateView();
updateChartOnMap();
} }
private void updateMenu() { private void updateMenu() {
@ -302,6 +307,13 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
} }
} }
private void updateChartOnMap() {
if (hasVisibleGraph()) {
trackDetailsMenu.reset();
refreshMapCallback.refreshMap(false);
}
}
private void addCommonType(int titleId, private void addCommonType(int titleId,
boolean canBeCalculated, boolean canBeCalculated,
boolean hasData, boolean hasData,
@ -346,6 +358,11 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
return fragment.isProgressBarVisible(); return fragment.isProgressBarVisible();
} }
public boolean hasVisibleGraph() {
return (commonGraphContainer != null && commonGraphContainer.getVisibility() == View.VISIBLE)
|| (customGraphContainer != null && customGraphContainer.getVisibility() == View.VISIBLE);
}
private abstract class GraphType<T extends ChartData> { private abstract class GraphType<T extends ChartData> {
private String title; private String title;
private boolean canBeCalculated; private boolean canBeCalculated;

View file

@ -553,8 +553,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
private void updateAdditionalInfoView() { private void updateAdditionalInfoView() {
if (visibleCard instanceof OnUpdateAdditionalInfoListener) { updateAdditionalInfoView(pointsCard);
((OnUpdateAdditionalInfoListener) visibleCard).onUpdateAdditionalInfo(); updateAdditionalInfoView(graphsCard);
}
private void updateAdditionalInfoView(OnUpdateAdditionalInfoListener listener) {
if (listener != null) {
listener.onUpdateAdditionalInfo();
} }
} }
@ -1514,6 +1519,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return type.equals(currentAdditionalInfoType); return type.equals(currentAdditionalInfoType);
} }
public boolean hasVisibleGraph() {
return graphsCard != null && graphsCard.hasVisibleGraph();
}
private String getSuggestedFileName() { private String getSuggestedFileName() {
GpxData gpxData = editingCtx.getGpxData(); GpxData gpxData = editingCtx.getGpxData();
String displayedName = null; String displayedName = null;

View file

@ -24,7 +24,9 @@ public class PointsCard extends BaseCard implements OnUpdateAdditionalInfoListen
@Override @Override
public void onUpdateAdditionalInfo() { public void onUpdateAdditionalInfo() {
adapter.notifyDataSetChanged(); if (adapter != null) {
adapter.notifyDataSetChanged();
}
} }
@Override @Override

View file

@ -5,6 +5,8 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull;
import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
@ -96,15 +98,27 @@ public class GraphAdapterHelper {
} }
} }
public static void bindToMap(final CommonGraphAdapter graphAdapter, public static RefreshMapCallback bindToMap(@NonNull final CommonGraphAdapter graphAdapter,
final MapActivity mapActivity, @NonNull final MapActivity mapActivity,
final TrackDetailsMenu detailsMenu) { @NonNull final TrackDetailsMenu detailsMenu) {
final RefreshMapCallback refreshMapCallback = new RefreshMapCallback() {
@Override
public void refreshMap(boolean forceFit) {
LineChart chart = graphAdapter.getChart();
OsmandApplication app = mapActivity.getMyApplication();
if (!app.getRoutingHelper().isFollowingMode()) {
detailsMenu.refreshChart(chart, forceFit);
mapActivity.refreshMap();
}
}
};
graphAdapter.addValueSelectedListener(BIND_TO_MAP_KEY, graphAdapter.addValueSelectedListener(BIND_TO_MAP_KEY,
new CommonGraphAdapter.ExternalValueSelectedListener() { new CommonGraphAdapter.ExternalValueSelectedListener() {
@Override @Override
public void onValueSelected(Entry e, Highlight h) { public void onValueSelected(Entry e, Highlight h) {
refreshChart(mapActivity, graphAdapter.getChart(), detailsMenu, false); refreshMapCallback.refreshMap(false);
} }
@Override @Override
@ -125,21 +139,15 @@ public class GraphAdapterHelper {
lastPerformedGesture == ChartTouchListener.ChartGesture.PINCH_ZOOM || lastPerformedGesture == ChartTouchListener.ChartGesture.PINCH_ZOOM ||
lastPerformedGesture == ChartTouchListener.ChartGesture.DOUBLE_TAP || lastPerformedGesture == ChartTouchListener.ChartGesture.DOUBLE_TAP ||
lastPerformedGesture == ChartTouchListener.ChartGesture.ROTATE) { lastPerformedGesture == ChartTouchListener.ChartGesture.ROTATE) {
refreshChart(mapActivity, graphAdapter.getChart(), detailsMenu, true); refreshMapCallback.refreshMap(true);
} }
} }
}); });
return refreshMapCallback;
} }
public static void refreshChart(MapActivity mapActivity, public interface RefreshMapCallback {
LineChart chart, void refreshMap(boolean forceFit);
TrackDetailsMenu menu,
boolean forceFit) {
if (mapActivity == null || chart == null || menu == null) return;
OsmandApplication app = mapActivity.getMyApplication();
if (!app.getRoutingHelper().isFollowingMode()) {
menu.refreshChart(chart, forceFit);
mapActivity.refreshMap();
}
} }
} }

View file

@ -60,6 +60,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.measurementtool.graph.BaseGraphAdapter; import net.osmand.plus.measurementtool.graph.BaseGraphAdapter;
import net.osmand.plus.measurementtool.graph.CommonGraphAdapter; import net.osmand.plus.measurementtool.graph.CommonGraphAdapter;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper; import net.osmand.plus.measurementtool.graph.GraphAdapterHelper;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper.RefreshMapCallback;
import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
@ -113,6 +114,7 @@ public class RouteDetailsFragment extends ContextMenuFragment
private RouteStatisticCard statisticCard; private RouteStatisticCard statisticCard;
private List<RouteInfoCard> routeInfoCards = new ArrayList<>(); private List<RouteInfoCard> routeInfoCards = new ArrayList<>();
private RouteDetailsMenu routeDetailsMenu; private RouteDetailsMenu routeDetailsMenu;
private RefreshMapCallback refreshMapCallback;
public interface RouteDetailsFragmentListener { public interface RouteDetailsFragmentListener {
void onNavigationRequested(); void onNavigationRequested();
@ -336,7 +338,7 @@ public class RouteDetailsFragment extends ContextMenuFragment
CommonGraphAdapter mainGraphAdapter = statisticCard.getGraphAdapter(); CommonGraphAdapter mainGraphAdapter = statisticCard.getGraphAdapter();
if (mainGraphAdapter != null) { if (mainGraphAdapter != null) {
GraphAdapterHelper.bindGraphAdapters(mainGraphAdapter, getRouteInfoCardsGraphAdapters(), getMainView()); GraphAdapterHelper.bindGraphAdapters(mainGraphAdapter, getRouteInfoCardsGraphAdapters(), getMainView());
GraphAdapterHelper.bindToMap(mainGraphAdapter, mapActivity, routeDetailsMenu); refreshMapCallback = GraphAdapterHelper.bindToMap(mainGraphAdapter, mapActivity, routeDetailsMenu);
} }
} }
@ -369,12 +371,7 @@ public class RouteDetailsFragment extends ContextMenuFragment
protected void calculateLayout(View view, boolean initLayout) { protected void calculateLayout(View view, boolean initLayout) {
super.calculateLayout(view, initLayout); super.calculateLayout(view, initLayout);
if (!initLayout && getCurrentMenuState() != MenuState.FULL_SCREEN) { if (!initLayout && getCurrentMenuState() != MenuState.FULL_SCREEN) {
MapActivity mapActivity = getMapActivity(); refreshMapCallback.refreshMap(false);
CommonGraphAdapter mainGraphAdapter = statisticCard.getGraphAdapter();
if (mainGraphAdapter != null) {
LineChart chart = mainGraphAdapter.getChart();
GraphAdapterHelper.refreshChart(mapActivity, chart, routeDetailsMenu, false);
}
} }
} }

View file

@ -26,7 +26,9 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo;
@ -158,7 +160,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if ((helper.isPublicTransportMode() && transportHelper.getRoutes() != null) || if ((helper.isPublicTransportMode() && transportHelper.getRoutes() != null) ||
(helper.getFinalLocation() != null && helper.getRoute().isCalculated())) { (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) ||
isPlanRouteGraphsAvailable()) {
updateAttrs(settings, tileBox); updateAttrs(settings, tileBox);
@ -202,6 +205,17 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
} }
private boolean isPlanRouteGraphsAvailable() {
if (view.getContext() instanceof MapActivity) {
MapActivity mapActivity = (MapActivity) view.getContext();
MeasurementToolFragment fragment = mapActivity.getMeasurementToolFragment();
if (fragment != null) {
return fragment.hasVisibleGraph();
}
}
return false;
}
private void updateAttrs(DrawSettings settings, RotatedTileBox tileBox) { private void updateAttrs(DrawSettings settings, RotatedTileBox tileBox) {
boolean updatePaints = attrs.updatePaints(view.getApplication(), settings, tileBox); boolean updatePaints = attrs.updatePaints(view.getApplication(), settings, tileBox);
attrs.isPaint3 = false; attrs.isPaint3 = false;