Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - expose setting a custom attribution manager through UiSet…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
tobrun committed Jan 18, 2018
1 parent da891fc commit c404e3b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt

private final Context context;
private final MapboxMap mapboxMap;
private String[] attributionTitles;
private Set<Attribution> attributionSet;

public AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap mapboxMap) {
Expand All @@ -50,11 +49,10 @@ public AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap map
@Override
public void onClick(View view) {
attributionSet = new AttributionBuilder(mapboxMap).build();
showAttributionDialog();
showAttributionDialog(getAttributionTitles());
}

protected void showAttributionDialog() {
attributionTitles = getAttributionTitles();
protected void showAttributionDialog(String[] attributionTitles) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionTitles), this);
Expand All @@ -80,7 +78,7 @@ public void onClick(DialogInterface dialog, int which) {
}

private boolean isLatestEntry(int attributionKeyIndex) {
return attributionKeyIndex == attributionTitles.length - 1;
return attributionKeyIndex == getAttributionTitles().length - 1;
}

private void showTelemetryDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ZoomButtonsController;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
Expand All @@ -36,17 +37,19 @@
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
import timber.log.Timber;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import timber.log.Timber;

import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;

Expand Down Expand Up @@ -201,7 +204,7 @@ private void initialiseMap() {
compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher));
// inject widgets with MapboxMap
myLocationView.setMapboxMap(mapboxMap);
attrView.setOnClickListener(new AttributionDialogManager(context, mapboxMap));
attrView.setOnClickListener(new AttributionClickListener(context, mapboxMap));

// Ensure this view is interactable
setClickable(true);
Expand Down Expand Up @@ -1072,4 +1075,28 @@ void clearOnMapReadyCallbacks() {
onMapReadyCallbackList.clear();
}
}

/**
* Click event hook for providing a custom attribution dialog manager.
*/
private static class AttributionClickListener implements OnClickListener {

private final AttributionDialogManager defaultDialogManager;
private UiSettings uiSettings;

private AttributionClickListener(Context context, MapboxMap mapboxMap) {
this.defaultDialogManager = new AttributionDialogManager(context, mapboxMap);
this.uiSettings = mapboxMap.getUiSettings();
}

@Override
public void onClick(View v) {
AttributionDialogManager customDialogManager = uiSettings.getAttributionDialogManager();
if (customDialogManager != null) {
uiSettings.getAttributionDialogManager().onClick(v);
} else {
defaultDialogManager.onClick(v);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class UiSettings {

private final ImageView attributionsView;
private final int[] attributionsMargins = new int[4];
private AttributionDialogManager attributionDialogManager;

private final View logoView;
private final int[] logoMargins = new int[4];
Expand Down Expand Up @@ -535,6 +536,28 @@ public boolean isAttributionEnabled() {
return attributionsView.getVisibility() == View.VISIBLE;
}


/**
* Set a custom attribution dialog manager.
* <p>
* Set to null to reset to default behaviour.
* </p>
*
* @param attributionDialogManager the manager class used for showing attribution
*/
public void setAttributionDialogManager(AttributionDialogManager attributionDialogManager) {
this.attributionDialogManager = attributionDialogManager;
}

/**
* Get the custom attribution dialog manager.
*
* @return the active manager class used for showing attribution
*/
public AttributionDialogManager getAttributionDialogManager() {
return attributionDialogManager;
}

/**
* <p>
* Sets the gravity of the attribution.
Expand Down

0 comments on commit c404e3b

Please sign in to comment.