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

Commit

Permalink
[android] - move ZoomButtonController creation to view initalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 25, 2017
1 parent c0efad5 commit 8175da0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private void initialise(@NonNull final Context context, @NonNull final MapboxMap
myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
attrView = (ImageView) view.findViewById(R.id.attributionView);
logoView = (ImageView) view.findViewById(R.id.logoView);
mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));

// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
Expand Down Expand Up @@ -166,7 +167,7 @@ private void initialiseMap() {
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);

MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
mapZoomButtonController = new MapZoomButtonController(this, uiSettings, zoomListener);
mapZoomButtonController.bind(uiSettings, zoomListener);

// inject widgets with MapboxMap
compassView.setMapboxMap(mapboxMap);
Expand Down Expand Up @@ -542,9 +543,7 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
@CallSuper
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mapZoomButtonController != null) {
mapZoomButtonController.setVisible(false);
}
mapZoomButtonController.setVisible(false);
}

// Called when view is hidden and shown
Expand All @@ -553,11 +552,12 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
if (isInEditMode()) {
return;
}

if (visibility == View.VISIBLE && nativeMapView == null) {
initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
}

if (mapZoomButtonController != null && nativeMapView != null) {
if (nativeMapView != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
* Allows single touch only devices to zoom in and out.
* </p>
*/
final class MapZoomButtonController extends ZoomButtonsController {
final class MapZoomButtonController {

private UiSettings uiSettings;
private ZoomButtonsController zoomButtonsController;

MapZoomButtonController(@NonNull View ownerView, @NonNull UiSettings uiSettings, @NonNull OnZoomListener listener) {
super(ownerView);
MapZoomButtonController(@NonNull ZoomButtonsController zoomButtonsController) {
this.zoomButtonsController = zoomButtonsController;
this.zoomButtonsController.setZoomSpeed(MapboxConstants.ANIMATION_DURATION);
}

void bind(UiSettings uiSettings, ZoomButtonsController.OnZoomListener onZoomListener) {
this.uiSettings = uiSettings;
setZoomSpeed(MapboxConstants.ANIMATION_DURATION);
setOnZoomListener(listener);
zoomButtonsController.setOnZoomListener(onZoomListener);
}

@Override
public void setVisible(boolean visible) {
if (uiSettings.isZoomControlsEnabled()) {
super.setVisible(visible);
void setVisible(boolean visible) {
if (uiSettings != null && !uiSettings.isZoomControlsEnabled()) {
return;
}
zoomButtonsController.setVisible(visible);
}
}

0 comments on commit 8175da0

Please sign in to comment.