From 728be7dba5423ec04aa2f55cd451e0668582fa38 Mon Sep 17 00:00:00 2001 From: Langston Smith Date: Tue, 5 May 2020 13:59:06 -0700 Subject: [PATCH] ls annotation clicklistener refactoring --- .../activity/annotation/CircleActivity.java | 22 ++++++++++------ .../activity/annotation/FillActivity.java | 25 +++++++++++-------- .../annotation/FillChangeActivity.java | 11 +++++--- .../activity/annotation/LineActivity.java | 22 ++++++++++------ .../annotation/LineChangeActivity.java | 11 +++++--- .../annotation/PressForSymbolActivity.java | 4 +++ .../activity/annotation/SymbolActivity.java | 21 ++++++++++------ .../plugins/annotation/AnnotationManager.java | 8 ++++-- .../annotation/OnAnnotationClickListener.java | 5 ++-- .../OnAnnotationLongClickListener.java | 5 ++-- 10 files changed, 86 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/CircleActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/CircleActivity.java index f79bab1c8..dfd29c3f5 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/CircleActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/CircleActivity.java @@ -54,14 +54,20 @@ protected void onCreate(Bundle savedInstanceState) { // create circle manager circleManager = new CircleManager(mapView, mapboxMap, style); - circleManager.addClickListener(circle -> Toast.makeText(CircleActivity.this, - String.format("Circle clicked %s", circle.getId()), - Toast.LENGTH_SHORT - ).show()); - circleManager.addLongClickListener(circle -> Toast.makeText(CircleActivity.this, - String.format("Circle long clicked %s", circle.getId()), - Toast.LENGTH_SHORT - ).show()); + circleManager.addClickListener(circle -> { + Toast.makeText(CircleActivity.this, + String.format("Circle clicked %s", circle.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); + circleManager.addLongClickListener(circle -> { + Toast.makeText(CircleActivity.this, + String.format("Circle long clicked %s", circle.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); // create a fixed circle CircleOptions circleOptions = new CircleOptions() diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillActivity.java index 154007ef2..71c7344db 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillActivity.java @@ -48,16 +48,21 @@ protected void onCreate(Bundle savedInstanceState) { mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2)); - fillManager = new FillManager(mapView, mapboxMap, style); - fillManager.addClickListener(fill -> Toast.makeText(FillActivity.this, - String.format("Fill clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), - Toast.LENGTH_SHORT - ).show()); - - fillManager.addLongClickListener(fill -> Toast.makeText(FillActivity.this, - String.format("Fill long clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), - Toast.LENGTH_SHORT - ).show()); + fillManager.addClickListener(fill -> { + Toast.makeText(FillActivity.this, + String.format("Fill clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), + Toast.LENGTH_SHORT + ).show(); + return false; + }); + + fillManager.addLongClickListener(fill -> { + Toast.makeText(FillActivity.this, + String.format("Fill long clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), + Toast.LENGTH_SHORT + ).show(); + return false; + }); // create a fixed fill List innerLatLngs = new ArrayList<>(); diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillChangeActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillChangeActivity.java index 40a1eb086..9b55ec25b 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillChangeActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/FillChangeActivity.java @@ -80,10 +80,13 @@ protected void onCreate(Bundle savedInstanceState) { public void onMapReady(@NonNull MapboxMap map) { map.setStyle(new Style.Builder().fromUri(Style.MAPBOX_STREETS), style -> { fillManager = new FillManager(mapView, map, style, "aerialway"); - fillManager.addClickListener(fill -> Toast.makeText( - FillChangeActivity.this, - "Clicked: " + fill.getId(), - Toast.LENGTH_SHORT).show()); + fillManager.addClickListener(fill -> { + Toast.makeText( + FillChangeActivity.this, + "Clicked: " + fill.getId(), + Toast.LENGTH_SHORT).show(); + return false; + }); fill = fillManager.create(new FillOptions() .withLatLngs(STAR_SHAPE_POINTS) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineActivity.java index 0d13e69f5..c05230f62 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineActivity.java @@ -46,14 +46,20 @@ protected void onCreate(Bundle savedInstanceState) { mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2)); lineManager = new LineManager(mapView, mapboxMap, style); - lineManager.addClickListener(line -> Toast.makeText(LineActivity.this, - String.format("Line clicked %s", line.getId()), - Toast.LENGTH_SHORT - ).show()); - lineManager.addLongClickListener(line -> Toast.makeText(LineActivity.this, - String.format("Line long clicked %s", line.getId()), - Toast.LENGTH_SHORT - ).show()); + lineManager.addClickListener(line -> { + Toast.makeText(LineActivity.this, + String.format("Line clicked %s", line.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); + lineManager.addLongClickListener(line -> { + Toast.makeText(LineActivity.this, + String.format("Line long clicked %s", line.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); // create a fixed line List latLngs = new ArrayList<>(); diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java index 5a7b00987..9e27aec47 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java @@ -73,10 +73,13 @@ protected void onCreate(Bundle savedInstanceState) { lineManager = new LineManager(mapView, mapboxMap, style); lines = lineManager.create(getAllPolylines()); - lineManager.addClickListener(line -> Toast.makeText( - LineChangeActivity.this, - "Clicked: " + line.getId(), - Toast.LENGTH_SHORT).show()); + lineManager.addClickListener(line -> { + Toast.makeText( + LineChangeActivity.this, + "Clicked: " + line.getId(), + Toast.LENGTH_SHORT).show(); + return false; + }); LineManager dottedLineManger = new LineManager(mapView, mapboxMap, style); dottedLineManger.create(new LineOptions() diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/PressForSymbolActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/PressForSymbolActivity.java index 4cb5637bc..6979a745f 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/PressForSymbolActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/PressForSymbolActivity.java @@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.mapboxsdk.plugins.testapp.Utils; +import com.mapbox.mapboxsdk.style.layers.Property; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; @@ -21,6 +22,8 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; +import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ANCHOR_BOTTOM; + /** * Test activity showcasing to add a Symbol on click. *

@@ -71,6 +74,7 @@ private boolean addSymbol(LatLng point) { symbolManager.create(new SymbolOptions() .withLatLng(point) .withIconImage(ID_ICON) + .withIconAnchor(ICON_ANCHOR_BOTTOM) ); return true; } diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java index 69d1e8449..6421996fc 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java @@ -82,15 +82,20 @@ protected void onCreate(Bundle savedInstanceState) { // create symbol manager GeoJsonOptions geoJsonOptions = new GeoJsonOptions().withTolerance(0.4f); symbolManager = new SymbolManager(mapView, mapboxMap, style, null, geoJsonOptions); - symbolManager.addClickListener(symbol -> Toast.makeText(SymbolActivity.this, - String.format("Symbol clicked %s", symbol.getId()), - Toast.LENGTH_SHORT - ).show()); - symbolManager.addLongClickListener(symbol -> + symbolManager.addClickListener(symbol -> { Toast.makeText(SymbolActivity.this, - String.format("Symbol long clicked %s", symbol.getId()), - Toast.LENGTH_SHORT - ).show()); + String.format("Symbol clicked %s", symbol.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); + symbolManager.addLongClickListener(symbol -> { + Toast.makeText(SymbolActivity.this, + String.format("Symbol long clicked %s", symbol.getId()), + Toast.LENGTH_SHORT + ).show(); + return false; + }); // set non data driven properties symbolManager.setIconAllowOverlap(true); diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java index a86998aee..c87662944 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java @@ -377,7 +377,9 @@ public boolean onMapClick(@NonNull LatLng point) { T annotation = queryMapForFeatures(point); if (annotation != null) { for (U clickListener : clickListeners) { - clickListener.onAnnotationClick(annotation); + if (clickListener.onAnnotationClick(annotation)) { + return true; + } } } return false; @@ -392,7 +394,9 @@ public boolean onMapLongClick(@NonNull LatLng point) { T annotation = queryMapForFeatures(point); if (annotation != null) { for (V clickListener : longClickListeners) { - clickListener.onAnnotationLongClick(annotation); + if (clickListener.onAnnotationLongClick(annotation)) { + return true; + } } } return false; diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationClickListener.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationClickListener.java index f19d55472..e89828d31 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationClickListener.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationClickListener.java @@ -11,7 +11,8 @@ public interface OnAnnotationClickListener { * Called when an annotation has been clicked * * @param t the annotation clicked. + * @return True if this click should be consumed and not passed further to other listeners + * registered afterwards, false otherwise. */ - void onAnnotationClick(T t); - + boolean onAnnotationClick(T t); } diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationLongClickListener.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationLongClickListener.java index 5103e7c84..da0754723 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationLongClickListener.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/OnAnnotationLongClickListener.java @@ -11,7 +11,8 @@ public interface OnAnnotationLongClickListener { * Called when an annotation has been long clicked * * @param t the annotation long clicked. + * @return True if this click should be consumed and not passed further to other listeners + * registered afterwards, false otherwise. */ - void onAnnotationLongClick(T t); - + boolean onAnnotationLongClick(T t); }