Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[annotation] Consumable event with ClickListener #1124

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatLng> innerLatLngs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatLng> latLngs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
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;
import androidx.annotation.Nullable;
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.
* <p>
Expand Down Expand Up @@ -71,6 +74,7 @@ private boolean addSymbol(LatLng point) {
symbolManager.create(new SymbolOptions()
.withLatLng(point)
.withIconImage(ID_ICON)
.withIconAnchor(ICON_ANCHOR_BOTTOM)
);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface OnAnnotationClickListener<T extends Annotation> {
* 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface OnAnnotationLongClickListener<T extends Annotation> {
* 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);
}