Fix route details charts sync. Highlight with vert line.
This commit is contained in:
parent
f2f5511f58
commit
984120dda7
5 changed files with 69 additions and 156 deletions
|
@ -1255,8 +1255,6 @@ public class GpxUiHelper {
|
|||
yr.setDrawGridLines(false);
|
||||
yr.setAxisMinimum(0f);
|
||||
chart.setMinOffset(0);
|
||||
chart.setExtraRightOffset(16);
|
||||
chart.setExtraLeftOffset(16);
|
||||
|
||||
int mainFontColor = ContextCompat.getColor(app, nightMode ? R.color.main_font_dark : R.color.main_font_light);
|
||||
yl.setTextColor(mainFontColor);
|
||||
|
@ -1300,7 +1298,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));
|
||||
barDataSet.setHighLightColor(!nightMode ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
|
||||
BarData dataSet = new BarData(barDataSet);
|
||||
dataSet.setDrawValues(false);
|
||||
dataSet.setBarWidth(1);
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.routepreparationmenu;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
|
@ -28,11 +29,14 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.listener.ChartTouchListener;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
|
||||
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -319,7 +323,14 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
if (mainView != null) {
|
||||
mainView.requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
dispatchEventToInfoCards(v, ev);
|
||||
for (RouteInfoCard card : routeInfoCards) {
|
||||
final HorizontalBarChart ch = card.getChart();
|
||||
if (ch != null) {
|
||||
final MotionEvent event = MotionEvent.obtainNoHistory(ev);
|
||||
event.setSource(0);
|
||||
ch.dispatchTouchEvent(event);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, new OnClickListener() {
|
||||
|
@ -373,6 +384,8 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
trackDetailsMenu.setMapActivity(mapActivity);
|
||||
LineChart chart = statisticCard.getChart();
|
||||
if (chart != null) {
|
||||
chart.setExtraRightOffset(16);
|
||||
chart.setExtraLeftOffset(16);
|
||||
trackDetailsMenu.refreshChart(chart, true);
|
||||
}
|
||||
}
|
||||
|
@ -404,24 +417,13 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
ch.dispatchTouchEvent(event);
|
||||
}
|
||||
}
|
||||
dispatchEventToInfoCards(v, ev);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void dispatchEventToInfoCards(View v, MotionEvent ev) {
|
||||
for (RouteInfoCard card : routeInfoCards) {
|
||||
final HorizontalBarChart ch = card.getChart();
|
||||
if (ch != null && ch != v) {
|
||||
final MotionEvent event = MotionEvent.obtainNoHistory(ev);
|
||||
event.setSource(0);
|
||||
ch.dispatchTouchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void addRouteCard(final LinearLayout cardsContainer, RouteInfoCard routeInfoCard) {
|
||||
OsmandApplication app = requireMyApplication();
|
||||
|
@ -433,6 +435,14 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
routeInfoCards.add(routeInfoCard);
|
||||
HorizontalBarChart chart = routeInfoCard.getChart();
|
||||
if (chart != null) {
|
||||
LineChart mainChart = statisticCard.getChart();
|
||||
if (mainChart != null) {
|
||||
chart.getAxisRight().setAxisMinimum(mainChart.getXChartMin());
|
||||
chart.getAxisRight().setAxisMaximum(mainChart.getXChartMax());
|
||||
}
|
||||
chart.setRenderer(new CustomBarChartRenderer(chart, chart.getAnimator(), chart.getViewPortHandler(), AndroidUtils.dpToPx(app, 1f) / 2f));
|
||||
chart.setHighlightPerDragEnabled(false);
|
||||
chart.setHighlightPerTapEnabled(false);
|
||||
chart.setOnTouchListener(getChartTouchListener());
|
||||
}
|
||||
}
|
||||
|
@ -1645,49 +1655,28 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
}
|
||||
}
|
||||
|
||||
private void highlightRouteInfoCharts(@Nullable Highlight h) {
|
||||
for (RouteInfoCard rc : routeInfoCards) {
|
||||
HorizontalBarChart chart = rc.getChart();
|
||||
if (chart != null) {
|
||||
Highlight bh = h != null ? chart.getHighlighter().getHighlight(1, h.getXPx()) : null;
|
||||
if (bh != null) {
|
||||
bh.setDraw(h.getXPx(), 0);
|
||||
}
|
||||
chart.highlightValue(bh, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueSelected(BaseCard card, Entry e, Highlight h) {
|
||||
refreshChart();
|
||||
highlightRouteInfoCharts(h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(BaseCard card) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartGestureStart(BaseCard card, MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartGestureEnd(BaseCard card, MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartLongPressed(BaseCard card, MotionEvent me) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartDoubleTapped(BaseCard card, MotionEvent me) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartSingleTapped(BaseCard card, MotionEvent me) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartFling(BaseCard card, MotionEvent me1, MotionEvent me2, float velocityX,
|
||||
float velocityY) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartScale(BaseCard card, MotionEvent me, float scaleX, float scaleY) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartTranslate(BaseCard card, Highlight h, MotionEvent me, float dX, float dY) {
|
||||
if (h != null) {
|
||||
refreshChart();
|
||||
}
|
||||
highlightRouteInfoCharts(null);
|
||||
}
|
||||
|
||||
public static class CumulativeInfo {
|
||||
|
@ -1718,4 +1707,20 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
final int timeInSeconds = model.getExpectedTime();
|
||||
return Algorithms.formatDuration(timeInSeconds, app.accessibilityEnabled());
|
||||
}
|
||||
|
||||
private static class CustomBarChartRenderer extends HorizontalBarChartRenderer {
|
||||
|
||||
private float highlightHalfWidth;
|
||||
|
||||
CustomBarChartRenderer(BarDataProvider chart, ChartAnimator animator, ViewPortHandler viewPortHandler, float highlightHalfWidth) {
|
||||
super(chart, animator, viewPortHandler);
|
||||
this.highlightHalfWidth = highlightHalfWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHighlightDrawPos(Highlight high, RectF bar) {
|
||||
bar.left = high.getDrawX() - highlightHalfWidth;
|
||||
bar.right = high.getDrawX() + highlightHalfWidth;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package net.osmand.plus.routepreparationmenu.cards;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.listener.ChartTouchListener;
|
||||
|
||||
public interface CardChartListener {
|
||||
/**
|
||||
|
@ -20,69 +17,4 @@ public interface CardChartListener {
|
|||
* Called when nothing has been selected or an "un-select" has been made.
|
||||
*/
|
||||
void onNothingSelected(BaseCard card);
|
||||
|
||||
/**
|
||||
* Callbacks when a touch-gesture has started on the chart (ACTION_DOWN)
|
||||
*
|
||||
* @param me
|
||||
* @param lastPerformedGesture
|
||||
*/
|
||||
void onChartGestureStart(BaseCard card, MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
|
||||
|
||||
/**
|
||||
* Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL)
|
||||
*
|
||||
* @param me
|
||||
* @param lastPerformedGesture
|
||||
*/
|
||||
void onChartGestureEnd(BaseCard card, MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
|
||||
|
||||
/**
|
||||
* Callbacks when the chart is longpressed.
|
||||
*
|
||||
* @param me
|
||||
*/
|
||||
void onChartLongPressed(BaseCard card, MotionEvent me);
|
||||
|
||||
/**
|
||||
* Callbacks when the chart is double-tapped.
|
||||
*
|
||||
* @param me
|
||||
*/
|
||||
void onChartDoubleTapped(BaseCard card, MotionEvent me);
|
||||
|
||||
/**
|
||||
* Callbacks when the chart is single-tapped.
|
||||
*
|
||||
* @param me
|
||||
*/
|
||||
void onChartSingleTapped(BaseCard card, MotionEvent me);
|
||||
|
||||
/**
|
||||
* Callbacks then a fling gesture is made on the chart.
|
||||
*
|
||||
* @param me1
|
||||
* @param me2
|
||||
* @param velocityX
|
||||
* @param velocityY
|
||||
*/
|
||||
void onChartFling(BaseCard card, MotionEvent me1, MotionEvent me2, float velocityX, float velocityY);
|
||||
|
||||
/**
|
||||
* Callbacks when the chart is scaled / zoomed via pinch zoom gesture.
|
||||
*
|
||||
* @param me
|
||||
* @param scaleX scalefactor on the x-axis
|
||||
* @param scaleY scalefactor on the y-axis
|
||||
*/
|
||||
void onChartScale(BaseCard card, MotionEvent me, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Callbacks when the chart is moved / translated via drag gesture.
|
||||
*
|
||||
* @param me
|
||||
* @param dX translation distance on the x-axis
|
||||
* @param dY translation distance on the y-axis
|
||||
*/
|
||||
void onChartTranslate(BaseCard card, Highlight h, MotionEvent me, float dX, float dY);
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ public class RouteInfoCard extends BaseCard {
|
|||
updateHeader();
|
||||
final HorizontalBarChart chart = (HorizontalBarChart) view.findViewById(R.id.chart);
|
||||
GpxUiHelper.setupHorizontalGPXChart(app, chart, 5, 9, 24, true, nightMode);
|
||||
chart.setExtraRightOffset(16);
|
||||
chart.setExtraLeftOffset(16);
|
||||
BarData barData = GpxUiHelper.buildStatisticChart(app, chart, routeStatistics, analysis, true, nightMode);
|
||||
chart.setData(barData);
|
||||
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
|||
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
|
||||
import com.github.mikephil.charting.listener.OnChartGestureListener;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.MPPointD;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -287,10 +288,6 @@ public class RouteStatisticCard extends BaseCard {
|
|||
} else {
|
||||
highlightDrawX = -1;
|
||||
}
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartGestureStart(RouteStatisticCard.this, me, lastPerformedGesture);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -302,65 +299,44 @@ public class RouteStatisticCard extends BaseCard {
|
|||
} else {
|
||||
gpxItem.chartHighlightPos = -1;
|
||||
}
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartGestureEnd(RouteStatisticCard.this, me, lastPerformedGesture);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartLongPressed(MotionEvent me) {
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartLongPressed(RouteStatisticCard.this, me);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartDoubleTapped(MotionEvent me) {
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartDoubleTapped(RouteStatisticCard.this, me);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartSingleTapped(MotionEvent me) {
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartSingleTapped(RouteStatisticCard.this, me);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartFling(RouteStatisticCard.this, me1, me2, velocityX, velocityY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartScale(RouteStatisticCard.this, me, scaleX, scaleY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChartTranslate(MotionEvent me, float dX, float dY) {
|
||||
Highlight h = null;
|
||||
if (highlightDrawX != -1) {
|
||||
h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
|
||||
Highlight h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
|
||||
if (h != null) {
|
||||
mChart.highlightValue(h);
|
||||
/*
|
||||
ILineDataSet set = mChart.getLineData().getDataSetByIndex(h.getDataSetIndex());
|
||||
if (set != null && set.isHighlightEnabled()) {
|
||||
Entry e = set.getEntryForXValue(h.getX(), h.getY());
|
||||
MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());
|
||||
h.setDraw((float) pix.x, (float) pix.y);
|
||||
}
|
||||
*/
|
||||
mChart.highlightValue(h, true);
|
||||
}
|
||||
}
|
||||
CardChartListener chartListener = getChartListener();
|
||||
if (chartListener != null) {
|
||||
chartListener.onChartTranslate(RouteStatisticCard.this, h, me, dX, dY);
|
||||
}
|
||||
}
|
||||
});
|
||||
mChart.setVisibility(View.VISIBLE);
|
||||
|
|
Loading…
Reference in a new issue