From ab9a1e88a900d8f33c945a24d7da0866d7f314f8 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 24 Jun 2020 23:49:54 +0300 Subject: [PATCH] Fix chart drag without offsets --- .../other/TrackDetailsMenu.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 4600f92bf9..1f3a8443d6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapcontextmenu.other; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Matrix; +import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; import android.widget.AdapterView; @@ -16,6 +18,7 @@ import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; +import com.github.mikephil.charting.listener.BarLineChartTouchListener; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; @@ -150,7 +153,7 @@ public class TrackDetailsMenu { } } - public Location getMyLocation() { + protected Location getMyLocation() { return myLocation; } @@ -547,6 +550,39 @@ public class TrackDetailsMenu { } }); + final float minDragTriggerDist = AndroidUtils.dpToPx(app, 3); + chart.setOnTouchListener(new BarLineChartTouchListener(chart, chart.getViewPortHandler().getMatrixTouch(), 3f) { + private PointF touchStartPoint = new PointF(); + + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction() & MotionEvent.ACTION_MASK) { + case MotionEvent.ACTION_DOWN: + saveTouchStart(event); + break; + case MotionEvent.ACTION_POINTER_DOWN: + if (event.getPointerCount() >= 2) { + saveTouchStart(event); + } + break; + case MotionEvent.ACTION_MOVE: + if (mTouchMode == NONE && mChart.hasNoDragOffset()) { + float touchDistance = distance(event.getX(), touchStartPoint.x, event.getY(), touchStartPoint.y); + if (Math.abs(touchDistance) > minDragTriggerDist) { + mTouchMode = DRAG; + } + } + break; + } + return super.onTouch(v, event); + } + + private void saveTouchStart(MotionEvent event) { + touchStartPoint.x = event.getX(); + touchStartPoint.y = event.getY(); + } + }); chart.setOnChartGestureListener(new OnChartGestureListener() { boolean hasTranslated = false; float highlightDrawX = -1;