#894 - Moving annotation selection determination to onSingleTapUp() to only run it when it's actual single tap. Fixing newSelectedAnnotationID to be greater than or equals to 0 to handle first annotation case
This commit is contained in:
committed by
Justin R. Miller
parent
902b80888f
commit
77951eea93
@@ -973,86 +973,6 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
|
||||
// Open / Close InfoWindow
|
||||
PointF tapPoint = new PointF(event.getX(), event.getY());
|
||||
|
||||
float toleranceWidth = 60 * mScreenDensity;
|
||||
float toleranceHeight = 80 * mScreenDensity;
|
||||
|
||||
PointF tr = new PointF(tapPoint.x + toleranceWidth / 2, tapPoint.y + 2 * toleranceHeight / 3);
|
||||
PointF bl = new PointF(tapPoint.x - toleranceWidth / 2, tapPoint.y - 1 * toleranceHeight / 3);
|
||||
|
||||
LatLng sw = fromScreenLocation(bl);
|
||||
LatLng ne = fromScreenLocation(tr);
|
||||
|
||||
BoundingBox bbox = new BoundingBox(ne, sw);
|
||||
|
||||
List<Annotation> nearbyAnnotations = getAnnotationsInBounds(bbox);
|
||||
|
||||
long newSelectedAnnotationID = -1;
|
||||
|
||||
if (nearbyAnnotations.size() > 0) {
|
||||
|
||||
// there is at least one nearby annotation; select one
|
||||
//
|
||||
// first, sort for comparison and iteration
|
||||
Collections.sort(nearbyAnnotations);
|
||||
|
||||
if (nearbyAnnotations == mAnnotationsNearLastTap)
|
||||
{
|
||||
// the selection candidates haven't changed; cycle through them
|
||||
if (mSelectedAnnotation != null && (mSelectedAnnotation.getId() == mAnnotationsNearLastTap.get(mAnnotationsNearLastTap.size() - 1).getId()))
|
||||
{
|
||||
// the selected annotation is the last in the set; cycle back to the first
|
||||
// note: this could be the selected annotation if only one in set
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
else if (mSelectedAnnotation != null)
|
||||
{
|
||||
// otherwise increment the selection through the candidates
|
||||
long currentID = mSelectedAnnotation.getId();
|
||||
long result = mAnnotationsNearLastTap.indexOf(mSelectedAnnotation);
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get((int) result + 1).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// no current selection; select the first one
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// start tracking a new set of nearby annotations
|
||||
mAnnotationsNearLastTap = nearbyAnnotations;
|
||||
|
||||
// select the first one
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
|
||||
} else {
|
||||
// there are no nearby annotations; deselect if necessary
|
||||
newSelectedAnnotationID = -1;
|
||||
}
|
||||
|
||||
if (newSelectedAnnotationID > 0) {
|
||||
|
||||
for (Annotation annotation : mAnnotations) {
|
||||
if (annotation.getId() == newSelectedAnnotationID) {
|
||||
if (annotation.getId() == mSelectedAnnotation.getId()) {
|
||||
selectAnnotation(annotation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// deselect any selected annotation
|
||||
if (mSelectedAnnotation != null) {
|
||||
deselectAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
// First pointer up
|
||||
long tapInterval = event.getEventTime() - event.getDownTime();
|
||||
boolean isTap = tapInterval <= ViewConfiguration.getTapTimeout();
|
||||
@@ -1111,6 +1031,86 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
// Cancel any animation
|
||||
mNativeMapView.cancelTransitions();
|
||||
|
||||
// Open / Close InfoWindow
|
||||
PointF tapPoint = new PointF(e.getX(), e.getY());
|
||||
|
||||
float toleranceWidth = 60 * mScreenDensity;
|
||||
float toleranceHeight = 80 * mScreenDensity;
|
||||
|
||||
PointF tr = new PointF(tapPoint.x + toleranceWidth / 2, tapPoint.y + 2 * toleranceHeight / 3);
|
||||
PointF bl = new PointF(tapPoint.x - toleranceWidth / 2, tapPoint.y - 1 * toleranceHeight / 3);
|
||||
|
||||
LatLng sw = fromScreenLocation(bl);
|
||||
LatLng ne = fromScreenLocation(tr);
|
||||
|
||||
BoundingBox bbox = new BoundingBox(ne, sw);
|
||||
|
||||
List<Annotation> nearbyAnnotations = getAnnotationsInBounds(bbox);
|
||||
|
||||
long newSelectedAnnotationID = -1;
|
||||
|
||||
if (nearbyAnnotations.size() > 0) {
|
||||
|
||||
// there is at least one nearby annotation; select one
|
||||
//
|
||||
// first, sort for comparison and iteration
|
||||
Collections.sort(nearbyAnnotations);
|
||||
|
||||
if (nearbyAnnotations == mAnnotationsNearLastTap)
|
||||
{
|
||||
// the selection candidates haven't changed; cycle through them
|
||||
if (mSelectedAnnotation != null && (mSelectedAnnotation.getId() == mAnnotationsNearLastTap.get(mAnnotationsNearLastTap.size() - 1).getId()))
|
||||
{
|
||||
// the selected annotation is the last in the set; cycle back to the first
|
||||
// note: this could be the selected annotation if only one in set
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
else if (mSelectedAnnotation != null)
|
||||
{
|
||||
// otherwise increment the selection through the candidates
|
||||
long currentID = mSelectedAnnotation.getId();
|
||||
long result = mAnnotationsNearLastTap.indexOf(mSelectedAnnotation);
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get((int) result + 1).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// no current selection; select the first one
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// start tracking a new set of nearby annotations
|
||||
mAnnotationsNearLastTap = nearbyAnnotations;
|
||||
|
||||
// select the first one
|
||||
newSelectedAnnotationID = mAnnotationsNearLastTap.get(0).getId();
|
||||
}
|
||||
|
||||
} else {
|
||||
// there are no nearby annotations; deselect if necessary
|
||||
newSelectedAnnotationID = -1;
|
||||
}
|
||||
|
||||
if (newSelectedAnnotationID >= 0) {
|
||||
|
||||
for (Annotation annotation : mAnnotations) {
|
||||
if (annotation.getId() == newSelectedAnnotationID) {
|
||||
if (annotation.getId() == mSelectedAnnotation.getId()) {
|
||||
selectAnnotation(annotation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// deselect any selected annotation
|
||||
if (mSelectedAnnotation != null) {
|
||||
deselectAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
performClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user