Revert 5.x touch changes (#8585)

* Revert "[android] - only dispatch events if not handled by MarkerView (#8447)"

This reverts commit 09d76854ab.

* 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 1693b389d7.
This commit is contained in:
Tobrun
2017-03-30 17:30:47 +02:00
committed by GitHub
parent dcb14f98ee
commit a46d91f7c5
6 changed files with 60 additions and 70 deletions

View File

@@ -1,34 +0,0 @@
package com.mapbox.mapboxsdk.annotations;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
/**
* ViewGroup that dispatches TouchEvents to the parent ViewGroup.
* <p>
* This allows to dispatch touch events that occur on MarkerView to MapView.
* https://github.com/mapbox/mapbox-gl-native/issues/5388
* </p>
*/
public class MarkerViewContainer extends FrameLayout {
public MarkerViewContainer(Context context, AttributeSet attrs) {
super(context, attrs);
setTag(false);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
boolean actionUp = (boolean) getTag();
if (!actionUp) {
((ViewGroup) getParent()).onTouchEvent(ev);
} else {
setTag(false);
}
return true;
}
}

View File

@@ -8,7 +8,6 @@ import android.support.annotation.NonNull;
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;
@@ -504,26 +503,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
}
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) {
@@ -551,6 +530,34 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
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.
*

View File

@@ -10,7 +10,6 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
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;
@@ -257,11 +256,7 @@ class AnnotationManager {
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;
}
@@ -665,16 +660,24 @@ class AnnotationManager {
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;
}
}

View File

@@ -71,6 +71,27 @@ class IconManager {
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());
}