Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - only dispatch events if not handled by MarkerView (#8447)
Browse files Browse the repository at this point in the history
use onTouch listener to ignore dispatching action up events to MapView when they are already handled by MarkerView.
  • Loading branch information
tobrun authored Mar 17, 2017
1 parent 2e6c026 commit 09d7685
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public class MarkerViewContainer extends FrameLayout {

public MarkerViewContainer(Context context, AttributeSet attrs) {
super(context, attrs);
setTag(false);
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final boolean childResult = super.dispatchTouchEvent(ev);
if (childResult) {
super.dispatchTouchEvent(ev);
boolean actionUp = (boolean) getTag();
if (!actionUp) {
((ViewGroup) getParent()).onTouchEvent(ev);
} else {
setTag(false);
}
return childResult;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand Down Expand Up @@ -503,18 +504,23 @@ public void invalidateViewMarkersInVisibleRegion() {
}
}

adaptedView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
boolean clickHandled = false;
if (onMarkerViewClickListener != null) {
clickHandled = onMarkerViewClickListener.onMarkerClick(marker, v, adapter);
}
adaptedView.setOnTouchListener(new View.OnTouchListener() {

if (!clickHandled) {
ensureInfoWindowOffset(marker);
select(marker, v, adapter);
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
boolean clickHandled = false;
if (onMarkerViewClickListener != null) {
clickHandled = onMarkerViewClickListener.onMarkerClick(marker, v, adapter);
markerViewContainer.setTag(true);
}

if (!clickHandled) {
ensureInfoWindowOffset(marker);
select(marker, v, adapter);
}
}
return true;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view,
// open infowindow offscreen markers
mapboxMap.selectMarker(markerRightOffScreen);
mapboxMap.selectMarker(markerRightBottomOffScreen);

mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
Toast.makeText(MarkerViewActivity.this, point.toString(), Toast.LENGTH_SHORT).show();
}
});
}
});
}
Expand Down

0 comments on commit 09d7685

Please sign in to comment.