fix #1957 open MarkerEditActivity to receive external marker (#1960)

* fix #1957 add CreateMarkerActivity to receive external marker
This commit is contained in:
Peter Storch
2024-07-30 15:24:18 +02:00
committed by GitHub
parent d8acf7df22
commit 389c4bed96
20 changed files with 226 additions and 415 deletions
@@ -152,31 +152,6 @@ public class ChartView extends View {
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
// Check if the y event is within markerHeight of the marker center
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) {
int minDistance = Integer.MAX_VALUE;
Marker nearestMarker = null;
synchronized (markers) {
for (Marker marker : markers) {
int distance = Math.abs(getX(getMarkerXValue(marker)) - (int) event.getX() - getScrollX());
if (distance < minDistance) {
minDistance = distance;
nearestMarker = marker;
}
}
}
if (nearestMarker != null && minDistance < markerWidth) {
Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class)
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestMarker.getId());
getContext().startActivity(intent);
return true;
}
}
return false;
}
});
private final ScaleGestureDetector detectorZoom = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
@@ -589,7 +564,6 @@ public class ChartView extends View {
clipToGraphArea(canvas);
drawDataSeries(canvas);
drawMarker(canvas);
drawGrid(canvas);
canvas.restore();
@@ -630,30 +604,6 @@ public class ChartView extends View {
}
}
private void drawMarker(Canvas canvas) {
synchronized (markers) {
for (Marker marker : markers) {
double xValue = getMarkerXValue(marker);
double markerIconSizeInXaxisUnits = maxX*markerWidth/effectiveWidth / zoomLevel;
if (xValue > maxX + markerIconSizeInXaxisUnits * (1-MARKER_X_ANCHOR)) {
continue; // there is no chance that this marker will be visible
}
canvas.save();
float x = getX(getMarkerXValue(marker));
canvas.drawLine(x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
// if marker is not near the end of the track then draw it normally
if (xValue < maxX - markerIconSizeInXaxisUnits*(1-MARKER_X_ANCHOR)) {
canvas.translate(x - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
} else { // marker at the end needs to be drawn mirrored so that it is more visible
canvas.translate(x + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
canvas.scale(-1, 1);
}
markerPin.draw(canvas);
canvas.restore();
}
}
}
/**
* Draws the grid.
*
@@ -1043,14 +993,6 @@ public class ChartView extends View {
return topBorder + yAxisOffset + (int) ((1 - percentage) * rangeHeight);
}
private double getMarkerXValue(Marker marker) {
if (chartByDistance) {
return marker.getLength().toKM_Miles(unitSystem);
} else {
return marker.getDuration().toMillis();
}
}
/**
* Gets a paint's Rect for a string.
*