summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java22
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java)6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewContainer.java34
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java49
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java2
7 files changed, 75 insertions, 42 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
index 831c1db5a3..a588ff6d23 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
@@ -6,10 +6,12 @@ import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
- * Annotation is an overlay on top of a {@link MapView},
- * from which {@link Polygon}, {@link Polyline} and {@link Marker} are derived.
+ * Annotation is an overlay on top of a Map.
* <p>
- * it manages attachment to a map and identification, but does not require
+ * Known subclasses are {@link Polygon}, {@link Polyline} and {@link Marker}.
+ * </p>
+ * <p>
+ * This class manages attachment to a map and identification, but does not require
* content to be placed at a geographical point.
* </p>
*/
@@ -96,6 +98,12 @@ public abstract class Annotation implements Comparable<Annotation> {
return mapView;
}
+ /**
+ * Compares this Annotation object with another Annotation.
+ *
+ * @param annotation Another Annotation to compare with this object.
+ * @return returns 0 if id's match, 1 if id is lower, -1 if id is higher of another Annotation
+ */
@Override
public int compareTo(@NonNull Annotation annotation) {
if (id < annotation.getId()) {
@@ -107,12 +115,10 @@ public abstract class Annotation implements Comparable<Annotation> {
}
/**
- * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and
- * determines if their color, alpha, width, and vertices match.
+ * Checks if this Annotation object is equal to another Annotation.
*
- * @param object Another {@link PolylineOptions} to compare with this object.
- * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object.
- * Else, false.
+ * @param object Another Annotation to check equality with this object.
+ * @return returns true both id's match else returns false.
*/
@Override
public boolean equals(Object object) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java
index 2bd3c82786..e57821b541 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BasePointCollection.java
@@ -8,12 +8,12 @@ import java.util.List;
/**
* Multipoint is an abstract annotation for combining geographical locations.
*/
-public abstract class MultiPoint extends Annotation {
+public abstract class BasePointCollection extends Annotation {
private List<LatLng> points;
private float alpha = 1.0f;
- protected MultiPoint() {
+ protected BasePointCollection() {
super();
points = new ArrayList<>();
}
@@ -58,7 +58,7 @@ public abstract class MultiPoint extends Annotation {
}
/**
- * Set this {@link MultiPoint}s alpha.
+ * Set this {@link BasePointCollection}s alpha.
*
* @param alpha float value between 0 and 1.
*/
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
index 2e6445170f..07e038c08c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
@@ -14,7 +14,7 @@ import com.mapbox.mapboxsdk.R;
/**
* Bubble View for Android with custom stroke width and color, arrow size, position and direction.
*/
-class BubbleLayout extends LinearLayout {
+public class BubbleLayout extends LinearLayout {
public static final float DEFAULT_STROKE_WIDTH = -1;
private ArrowDirection arrowDirection;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewContainer.java
new file mode 100644
index 0000000000..d590582f09
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewContainer.java
@@ -0,0 +1,34 @@
+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;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index 315e12d280..0f1298eeaf 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -8,6 +8,7 @@ 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;
@@ -503,6 +504,26 @@ 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) {
@@ -531,34 +552,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
- * 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.
*
* @param marker that we are ensuring info window offset.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java
index 7b9de86bc4..4a72cb7d89 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java
@@ -7,7 +7,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Polygon is a geometry annotation that's a closed loop of coordinates.
*/
-public final class Polygon extends MultiPoint {
+public final class Polygon extends BasePointCollection {
private int fillColor = Color.BLACK; // default fillColor is black
private int strokeColor = Color.BLACK; // default strokeColor is black
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java
index a430d11009..6cea29ef81 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java
@@ -7,7 +7,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Polyline is a geometry feature with an unclosed list of coordinates drawn as a line
*/
-public final class Polyline extends MultiPoint {
+public final class Polyline extends BasePointCollection {
private int color = Color.BLACK; // default color is black
private float width = 10; // As specified by Google API Docs (in pixels)