#2283 - Supporting custom InfoWindow touch listeners via Marker.setInfoWindowOnTouchListener(). Added Test to Custom Annotations in TestApp's MainActivity.

This commit is contained in:
Brad Leege
2015-09-08 14:46:18 -05:00
committed by Justin R. Miller
parent 038f2f5ea3
commit 0da95e17c3
3 changed files with 46 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package com.mapbox.mapboxgl.annotations;
import android.graphics.Point;
import android.view.View;
import com.mapbox.mapboxgl.geometry.LatLng;
import com.mapbox.mapboxgl.views.R;
@@ -145,13 +146,32 @@ public class Marker extends Annotation {
return;
}
getInfoWindow().open(this, getPosition(), (int) anchorU, (int) anchorV);
getInfoWindow().setBoundMarker(this);
infoWindowShown = true;
}
/**
* Use to set a custom OnTouchListener for the InfoWindow.
* By default the InfoWindow will close on touch.
* @param listener Custom OnTouchListener
*/
public void setInfoWindowOnTouchListener(View.OnTouchListener listener) {
if (listener == null) {
return;
}
getInfoWindow().setOnTouchListener(listener);
}
/**
* Common internal InfoWindow initialization method
* @return InfoWindow for Marker
*/
private InfoWindow getInfoWindow() {
if (infoWindow == null) {
infoWindow = new InfoWindow(R.layout.infowindow, mapView);
}
infoWindow.open(this, getPosition(), (int)anchorU, (int)anchorV);
infoWindow.setBoundMarker(this);
infoWindowShown = true;
return infoWindow;
}
@Override

View File

@@ -8,10 +8,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
@@ -30,7 +27,6 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.ScaleGestureDetector;
@@ -484,6 +480,9 @@ public class MapView extends FrameLayout implements LocationListener {
private void removeAnnotationsWithId(long annotationId){
for (Iterator<Annotation> iterator = mAnnotations.iterator(); iterator.hasNext();) {
Annotation annotation = iterator.next();
if (annotation instanceof Marker) {
((Marker)annotation).hideInfoWindow();
}
if (annotation.getId() == annotationId) {
iterator.remove();
}
@@ -491,6 +490,9 @@ public class MapView extends FrameLayout implements LocationListener {
}
public void removeAnnotation(Annotation annotation) {
if (annotation instanceof Marker) {
((Marker)annotation).hideInfoWindow();
}
long id = annotation.getId();
mNativeMapView.removeAnnotation(id);
mAnnotations.remove(annotation);
@@ -504,8 +506,12 @@ public class MapView extends FrameLayout implements LocationListener {
public void removeAnnotations() {
long[] ids = new long[mAnnotations.size()];
for(int i = 0; i < mAnnotations.size(); i++) {
long id = mAnnotations.get(i).getId();
Annotation annotation = mAnnotations.get(i);
long id = annotation.getId();
ids[i] = id;
if (annotation instanceof Marker) {
((Marker)annotation).hideInfoWindow();
}
}
mNativeMapView.removeAnnotations(ids);
mAnnotations.clear();