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

Commit

Permalink
Revert 5.x touch changes (#8585)
Browse files Browse the repository at this point in the history
* Revert "[android] - only dispatch events if not handled by MarkerView (#8447)"

This reverts commit 09d7685.

* Revert "[android] - move touch handling of MarkerViews back to View#setOnClickListener. Workaround panning issue by dispatching touch events to the parent ViewGroup. (#8272)"

This reverts commit 1693b38.
  • Loading branch information
tobrun authored Mar 30, 2017
1 parent dcb14f9 commit a46d91f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 70 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 @@ -504,26 +503,6 @@ public void invalidateViewMarkersInVisibleRegion() {
}
}

adaptedView.setOnTouchListener(new View.OnTouchListener() {

@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;
}
});

marker.setMapboxMap(mapboxMap);
markerViewMap.put(marker, adaptedView);
if (convertView == null) {
Expand Down Expand Up @@ -551,6 +530,34 @@ public boolean onTouch(View v, MotionEvent event) {
updateMarkerViewsPosition();
}

/**
* When the provided {@link MarkerView} is clicked on by a user, we check if a custom click
* event has been created and if not, display a {@link InfoWindow}.
*
* @param markerView that the click event occurred.
*/
public boolean onClickMarkerView(MarkerView markerView) {
boolean clickHandled = false;

MapboxMap.MarkerViewAdapter adapter = getViewAdapter(markerView);
View view = getView(markerView);
if (adapter == null || view == null) {
// not a valid state
return true;
}

if (onMarkerViewClickListener != null) {
clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter);
}

if (!clickHandled) {
ensureInfoWindowOffset(markerView);
select(markerView, view, adapter);
}

return clickHandled;
}

/**
* Handles the {@link MarkerView}'s info window offset.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
Expand Down Expand Up @@ -257,11 +256,7 @@ List<MarkerView> addMarkerViews(@NonNull List<? extends BaseMarkerViewOptions> m

private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
MarkerView marker = markerViewOptions.getMarker();
Icon icon = markerViewOptions.getIcon();
if (icon == null) {
icon = IconFactory.getInstance(mapView.getContext()).defaultMarkerView();
}
marker.setIcon(icon);
iconManager.loadIconForMarkerView(marker);
return marker;
}

Expand Down Expand Up @@ -665,16 +660,24 @@ boolean onTap(PointF tapPoint, float screenDensity) {
if (annotation.getId() == newSelectedMarkerId) {
Marker marker = (Marker) annotation;

if (!(marker instanceof MarkerView)) {
if (marker instanceof MarkerView) {
handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
} else {
if (onMarkerClickListener != null) {
// end developer has provided a custom click listener
handledDefaultClick = onMarkerClickListener.onMarkerClick(marker);
}
}

if (annotation instanceof MarkerView) {
markerViewManager.onClickMarkerView((MarkerView) annotation);
} else {
if (!handledDefaultClick) {
// only select marker if user didn't handle the click event themselves
selectMarker(marker);
}
}

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ Icon loadIconForMarker(Marker marker) {
return icon;
}

Icon loadIconForMarkerView(MarkerView marker) {
Icon icon = marker.getIcon();
int iconSize = icons.size() + 1;
if (icon == null) {
icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarkerView();
marker.setIcon(icon);
}
Bitmap bitmap = icon.getBitmap();
averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize;
averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize;
if (!icons.contains(icon)) {
icons.add(icon);
} else {
Icon oldIcon = icons.get(icons.indexOf(icon));
if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) {
throw new IconBitmapChangedException();
}
}
return icon;
}

int getTopOffsetPixelsForIcon(Icon icon) {
return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:contentDescription="@null"
android:visibility="gone"/>

<com.mapbox.mapboxsdk.annotations.MarkerViewContainer
<FrameLayout
android:id="@+id/markerViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ 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 a46d91f

Please sign in to comment.