Fix moving chart marker
This commit is contained in:
parent
158bb34e1e
commit
0761591e8d
2 changed files with 75 additions and 3 deletions
|
@ -5,6 +5,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnDismissListener;
|
import android.content.DialogInterface.OnDismissListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -29,7 +30,10 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.mikephil.charting.charts.LineChart;
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
import com.github.mikephil.charting.data.LineData;
|
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.interfaces.datasets.ILineDataSet;
|
||||||
|
import com.github.mikephil.charting.listener.ChartTouchListener;
|
||||||
|
import com.github.mikephil.charting.listener.OnChartGestureListener;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -232,7 +236,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
private void buildHeader(View headerView) {
|
private void buildHeader(View headerView) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
|
final LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
|
||||||
GpxUiHelper.setupGPXChart(app, mChart, 4);
|
GpxUiHelper.setupGPXChart(app, mChart, 4);
|
||||||
mChart.setOnTouchListener(new View.OnTouchListener() {
|
mChart.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,6 +261,62 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
LineData data = new LineData(dataSets);
|
LineData data = new LineData(dataSets);
|
||||||
mChart.setData(data);
|
mChart.setData(data);
|
||||||
|
|
||||||
|
mChart.setOnChartGestureListener(new OnChartGestureListener() {
|
||||||
|
|
||||||
|
float highlightDrawX = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
|
||||||
|
if (mChart.getHighlighted() != null && mChart.getHighlighted().length > 0) {
|
||||||
|
highlightDrawX = mChart.getHighlighted()[0].getDrawX();
|
||||||
|
} else {
|
||||||
|
highlightDrawX = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
|
||||||
|
gpxItem.chartMatrix = new Matrix(mChart.getViewPortHandler().getMatrixTouch());
|
||||||
|
Highlight[] highlights = mChart.getHighlighted();
|
||||||
|
if (highlights != null && highlights.length > 0) {
|
||||||
|
gpxItem.chartHighlightPos = highlights[0].getX();
|
||||||
|
} else {
|
||||||
|
gpxItem.chartHighlightPos = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartLongPressed(MotionEvent me) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartDoubleTapped(MotionEvent me) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartSingleTapped(MotionEvent me) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChartTranslate(MotionEvent me, float dX, float dY) {
|
||||||
|
if (highlightDrawX != -1) {
|
||||||
|
Highlight h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
|
||||||
|
if (h != null) {
|
||||||
|
mChart.highlightValue(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mChart.setVisibility(View.VISIBLE);
|
mChart.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
elevationDataSet = null;
|
elevationDataSet = null;
|
||||||
|
|
|
@ -284,9 +284,7 @@ public class TrackDetailsMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void refreshChart(LineChart chart, boolean forceFit) {
|
private void refreshChart(LineChart chart, boolean forceFit) {
|
||||||
gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch());
|
|
||||||
Highlight[] highlights = chart.getHighlighted();
|
Highlight[] highlights = chart.getHighlighted();
|
||||||
LatLon location = null;
|
LatLon location = null;
|
||||||
if (highlights != null && highlights.length > 0) {
|
if (highlights != null && highlights.length > 0) {
|
||||||
|
@ -321,10 +319,16 @@ public class TrackDetailsMenu {
|
||||||
});
|
});
|
||||||
chart.setOnChartGestureListener(new OnChartGestureListener() {
|
chart.setOnChartGestureListener(new OnChartGestureListener() {
|
||||||
boolean hasTranslated = false;
|
boolean hasTranslated = false;
|
||||||
|
float highlightDrawX = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
|
public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
|
||||||
hasTranslated = false;
|
hasTranslated = false;
|
||||||
|
if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) {
|
||||||
|
highlightDrawX = chart.getHighlighted()[0].getDrawX();
|
||||||
|
} else {
|
||||||
|
highlightDrawX = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -336,6 +340,7 @@ public class TrackDetailsMenu {
|
||||||
lastPerformedGesture == ChartGesture.DOUBLE_TAP ||
|
lastPerformedGesture == ChartGesture.DOUBLE_TAP ||
|
||||||
lastPerformedGesture == ChartGesture.ROTATE) {
|
lastPerformedGesture == ChartGesture.ROTATE) {
|
||||||
|
|
||||||
|
gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch());
|
||||||
refreshChart(chart, true);
|
refreshChart(chart, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,6 +368,13 @@ public class TrackDetailsMenu {
|
||||||
@Override
|
@Override
|
||||||
public void onChartTranslate(MotionEvent me, float dX, float dY) {
|
public void onChartTranslate(MotionEvent me, float dX, float dY) {
|
||||||
hasTranslated = true;
|
hasTranslated = true;
|
||||||
|
if (highlightDrawX != -1) {
|
||||||
|
Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f);
|
||||||
|
if (h != null) {
|
||||||
|
chart.highlightValue(h);
|
||||||
|
refreshChart(chart, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue