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;
fragment.dismiss(backPressed);
} else {
segment = null;
trackChartPoints = null;
reset();
}
}
@ -274,8 +273,7 @@ public class TrackDetailsMenu {
if (hidding) {
hidding = false;
visible = false;
segment = null;
trackChartPoints = null;
reset();
}
}
@ -532,6 +530,11 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit);
}
public void reset() {
segment = null;
trackChartPoints = null;
}
private List<LatLon> getXAxisPoints(LineChart chart) {
float[] entries = chart.getXAxis().mEntries;
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.BaseGraphAdapter;
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.cards.BaseCard;
import net.osmand.router.RouteSegmentResult;
@ -59,6 +60,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
private MeasurementEditingContext editingCtx;
private MeasurementToolFragment fragment;
private TrackDetailsMenu trackDetailsMenu;
private RefreshMapCallback refreshMapCallback;
private GPXFile gpxFile;
private GPXTrackAnalysis analysis;
private GpxDisplayItem gpxItem;
@ -105,7 +107,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
});
GraphAdapterHelper.bindGraphAdapters(commonGraphAdapter, Arrays.asList((BaseGraphAdapter) customGraphAdapter), (ViewGroup) view);
GraphAdapterHelper.bindToMap(commonGraphAdapter, mapActivity, trackDetailsMenu);
refreshMapCallback = GraphAdapterHelper.bindToMap(commonGraphAdapter, mapActivity, trackDetailsMenu);
fullUpdate();
}
@ -116,7 +118,9 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
@Override
public void onUpdateAdditionalInfo() {
fullUpdate();
if (editingCtx != null) {
fullUpdate();
}
}
private void fullUpdate() {
@ -126,6 +130,7 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
updateMenu();
}
updateView();
updateChartOnMap();
}
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,
boolean canBeCalculated,
boolean hasData,
@ -346,6 +358,11 @@ public class GraphsCard extends BaseCard implements OnUpdateAdditionalInfoListen
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 String title;
private boolean canBeCalculated;

View file

@ -553,8 +553,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void updateAdditionalInfoView() {
if (visibleCard instanceof OnUpdateAdditionalInfoListener) {
((OnUpdateAdditionalInfoListener) visibleCard).onUpdateAdditionalInfo();
updateAdditionalInfoView(pointsCard);
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);
}
public boolean hasVisibleGraph() {
return graphsCard != null && graphsCard.hasVisibleGraph();
}
private String getSuggestedFileName() {
GpxData gpxData = editingCtx.getGpxData();
String displayedName = null;

View file

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

View file

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

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.CommonGraphAdapter;
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.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
@ -113,6 +114,7 @@ public class RouteDetailsFragment extends ContextMenuFragment
private RouteStatisticCard statisticCard;
private List<RouteInfoCard> routeInfoCards = new ArrayList<>();
private RouteDetailsMenu routeDetailsMenu;
private RefreshMapCallback refreshMapCallback;
public interface RouteDetailsFragmentListener {
void onNavigationRequested();
@ -336,7 +338,7 @@ public class RouteDetailsFragment extends ContextMenuFragment
CommonGraphAdapter mainGraphAdapter = statisticCard.getGraphAdapter();
if (mainGraphAdapter != null) {
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) {
super.calculateLayout(view, initLayout);
if (!initLayout && getCurrentMenuState() != MenuState.FULL_SCREEN) {
MapActivity mapActivity = getMapActivity();
CommonGraphAdapter mainGraphAdapter = statisticCard.getGraphAdapter();
if (mainGraphAdapter != null) {
LineChart chart = mainGraphAdapter.getChart();
GraphAdapterHelper.refreshChart(mapActivity, chart, routeDetailsMenu, false);
}
refreshMapCallback.refreshMap(false);
}
}

View file

@ -26,7 +26,9 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteDirectionInfo;
@ -158,7 +160,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if ((helper.isPublicTransportMode() && transportHelper.getRoutes() != null) ||
(helper.getFinalLocation() != null && helper.getRoute().isCalculated())) {
(helper.getFinalLocation() != null && helper.getRoute().isCalculated()) ||
isPlanRouteGraphsAvailable()) {
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) {
boolean updatePaints = attrs.updatePaints(view.getApplication(), settings, tileBox);
attrs.isPaint3 = false;