forked from upstream-mirrors/OpenTracks
Add synchronization when accessing waypoints in ChartView
This commit is contained in:
@@ -309,14 +309,18 @@ public class ChartView extends View {
|
|||||||
* @param waypoint the waypoint
|
* @param waypoint the waypoint
|
||||||
*/
|
*/
|
||||||
public void addWaypoint(Waypoint waypoint) {
|
public void addWaypoint(Waypoint waypoint) {
|
||||||
waypoints.add(waypoint);
|
synchronized (waypoints) {
|
||||||
|
waypoints.add(waypoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the waypoints.
|
* Clears the waypoints.
|
||||||
*/
|
*/
|
||||||
public void clearWaypoints() {
|
public void clearWaypoints() {
|
||||||
waypoints.clear();
|
synchronized (waypoints) {
|
||||||
|
waypoints.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,13 +449,15 @@ public class ChartView extends View {
|
|||||||
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2) < markerHeight) {
|
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2) < markerHeight) {
|
||||||
int minDistance = Integer.MAX_VALUE;
|
int minDistance = Integer.MAX_VALUE;
|
||||||
Waypoint nearestWaypoint = null;
|
Waypoint nearestWaypoint = null;
|
||||||
for (int i = 0; i < waypoints.size(); i++) {
|
synchronized (waypoints) {
|
||||||
Waypoint waypoint = waypoints.get(i);
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
int distance = Math.abs(
|
Waypoint waypoint = waypoints.get(i);
|
||||||
getX(getWaypointXValue(waypoint)) - (int) event.getX() - getScrollX());
|
int distance = Math.abs(
|
||||||
if (distance < minDistance) {
|
getX(getWaypointXValue(waypoint)) - (int) event.getX() - getScrollX());
|
||||||
minDistance = distance;
|
if (distance < minDistance) {
|
||||||
nearestWaypoint = waypoint;
|
minDistance = distance;
|
||||||
|
nearestWaypoint = waypoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nearestWaypoint != null && minDistance < markerWidth) {
|
if (nearestWaypoint != null && minDistance < markerWidth) {
|
||||||
@@ -543,27 +549,29 @@ public class ChartView extends View {
|
|||||||
* @param canvas the canvas
|
* @param canvas the canvas
|
||||||
*/
|
*/
|
||||||
private void drawWaypoints(Canvas canvas) {
|
private void drawWaypoints(Canvas canvas) {
|
||||||
for (int i = 0; i < waypoints.size(); i++) {
|
synchronized (waypoints) {
|
||||||
final Waypoint waypoint = waypoints.get(i);
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
if (waypoint.getLocation() == null) {
|
final Waypoint waypoint = waypoints.get(i);
|
||||||
continue;
|
if (waypoint.getLocation() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double xValue = getWaypointXValue(waypoint);
|
||||||
|
if (xValue > maxX) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
canvas.save();
|
||||||
|
float x = getX(getWaypointXValue(waypoint));
|
||||||
|
canvas.drawLine(
|
||||||
|
x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
|
||||||
|
canvas.translate(
|
||||||
|
x - (float) (markerWidth * MapOverlay.WAYPOINT_X_ANCHOR), topBorder + spacer);
|
||||||
|
if (waypoints.get(i).getType() == Waypoint.TYPE_STATISTICS) {
|
||||||
|
statisticsMarker.draw(canvas);
|
||||||
|
} else {
|
||||||
|
waypointMarker.draw(canvas);
|
||||||
|
}
|
||||||
|
canvas.restore();
|
||||||
}
|
}
|
||||||
double xValue = getWaypointXValue(waypoint);
|
|
||||||
if (xValue > maxX) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
canvas.save();
|
|
||||||
float x = getX(getWaypointXValue(waypoint));
|
|
||||||
canvas.drawLine(
|
|
||||||
x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
|
|
||||||
canvas.translate(x - (float) (markerWidth * MapOverlay.WAYPOINT_X_ANCHOR),
|
|
||||||
topBorder + spacer);
|
|
||||||
if (waypoints.get(i).getType() == Waypoint.TYPE_STATISTICS) {
|
|
||||||
statisticsMarker.draw(canvas);
|
|
||||||
} else {
|
|
||||||
waypointMarker.draw(canvas);
|
|
||||||
}
|
|
||||||
canvas.restore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user