[android] #3156 - improving marker selection touch handling

This commit is contained in:
Tobrun
2016-01-19 10:25:05 +01:00
parent 5ff95d4524
commit 6b3745c68d

View File

@@ -3186,9 +3186,9 @@ public final class MapView extends FrameLayout {
// Open / Close InfoWindow
PointF tapPoint = new PointF(e.getX(), e.getY());
final float toleranceSides = 30 * mScreenDensity;
final float toleranceTop = 40 * mScreenDensity;
final float toleranceBottom = 10 * mScreenDensity;
final float toleranceSides = 15 * mScreenDensity;
final float toleranceTop = 20 * mScreenDensity;
final float toleranceBottom = 5 * mScreenDensity;
RectF tapRect = new RectF(tapPoint.x - toleranceSides, tapPoint.y + toleranceTop,
tapPoint.x + toleranceSides, tapPoint.y - toleranceBottom);
@@ -3201,52 +3201,27 @@ public final class MapView extends FrameLayout {
);
BoundingBox tapBounds = BoundingBox.fromLatLngs(corners);
List<Marker> nearbyMarkers = getMarkersInBounds(tapBounds);
long newSelectedMarkerId = -1;
long newSelectedMarkerId;
if (nearbyMarkers.size() > 0) {
// there is at least one nearby marker; select one
//
// first, sort for comparison and iteration
if (nearbyMarkers!=null && nearbyMarkers.size() > 0) {
Collections.sort(nearbyMarkers);
if (nearbyMarkers == mMarkersNearLastTap) {
// TODO: We still need to adapt this logic to the new mSelectedMarkers list,
// though the basic functionality is there.
// the selection candidates haven't changed; cycle through them
// if (mSelectedMarker != null
// && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) {
// // the selected marker is the last in the set; cycle back to the first
// // note: this could be the selected marker if only one in set
// newSelectedMarkerId = mMarkersNearLastTap.get(0).getId();
// } else if (mSelectedMarker != null) {
// // otherwise increment the selection through the candidates
// long result = mMarkersNearLastTap.indexOf(mSelectedMarker);
// newSelectedMarkerId = mMarkersNearLastTap.get((int) result + 1).getId();
// } else {
// no current selection; select the first one
newSelectedMarkerId = mMarkersNearLastTap.get(0).getId();
// }
} else {
// start tracking a new set of nearby markers
mMarkersNearLastTap = nearbyMarkers;
// select the first one
newSelectedMarkerId = mMarkersNearLastTap.get(0).getId();
for (Marker nearbyMarker : nearbyMarkers) {
boolean found = false;
for (Marker selectedMarker : mSelectedMarkers) {
if(selectedMarker.equals(nearbyMarker)){
found = true;
}
}
if(!found){
newSelectedMarkerId = nearbyMarker.getId();
break;
}
}
} else {
// there are no nearby markers; deselect if necessary
newSelectedMarkerId = -1;
mMarkersNearLastTap = nearbyMarkers;
}
if (newSelectedMarkerId >= 0) {
int count = mAnnotations.size();
for (int i = 0; i < count; i++) {
Annotation annotation = mAnnotations.get(i);
@@ -3259,7 +3234,6 @@ public final class MapView extends FrameLayout {
}
}
}
} else {
// deselect any selected marker
deselectMarkers();