Add OnMarkerClickListener, added example in test app
This commit is contained in:
@@ -201,6 +201,10 @@ public final class MapView extends FrameLayout implements LocationListener, Comp
|
||||
private OnFlingListener onFlingListener;
|
||||
private OnScrollListener onScrollListener;
|
||||
|
||||
// Used to manage marker click event listeners
|
||||
private OnMarkerClickListener onMarkerClickListener;
|
||||
|
||||
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
@@ -356,6 +360,21 @@ public final class MapView extends FrameLayout implements LocationListener, Comp
|
||||
void onFpsChanged(double fps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the user clicks on a marker.
|
||||
*
|
||||
* @see MapView#setOnMarkerClickListener(OnMarkerClickListener)
|
||||
*/
|
||||
public interface OnMarkerClickListener {
|
||||
/**
|
||||
* Called when the user clicks on a marker.
|
||||
*
|
||||
* @param marker The marker the user clicked on.
|
||||
* @return If true the event was handled and the {@link InfoWindow} will not be shown.
|
||||
*/
|
||||
boolean onMarkerClick(Marker marker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the displayed map view changes.
|
||||
*
|
||||
@@ -1454,7 +1473,16 @@ public final class MapView extends FrameLayout implements LocationListener, Comp
|
||||
// Need to deselect any currently selected annotation first
|
||||
deselectAnnotation();
|
||||
|
||||
((Marker) annotation).showInfoWindow();
|
||||
Marker marker = (Marker) annotation;
|
||||
boolean handledClick = false;
|
||||
if (onMarkerClickListener != null) {
|
||||
handledClick = onMarkerClickListener.onMarkerClick(marker);
|
||||
}
|
||||
|
||||
if (!handledClick) {
|
||||
marker.showInfoWindow();
|
||||
}
|
||||
|
||||
mSelectedAnnotation = annotation;
|
||||
}
|
||||
}
|
||||
@@ -2340,6 +2368,10 @@ public final class MapView extends FrameLayout implements LocationListener, Comp
|
||||
this.onFlingListener = onFlingListener;
|
||||
}
|
||||
|
||||
public void setOnMarkerClickListener(OnMarkerClickListener onMarkerClickListener){
|
||||
this.onMarkerClickListener = onMarkerClickListener;
|
||||
}
|
||||
|
||||
//
|
||||
// User location
|
||||
//
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
@@ -138,6 +139,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mMapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
Snackbar.make(findViewById(android.R.id.content),"Custom Marker Click Listener",Snackbar.LENGTH_SHORT).show();
|
||||
marker.showInfoWindow();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mFpsTextView = (TextView) findViewById(R.id.view_fps);
|
||||
mFpsTextView.setText("");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user