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 authored Aug 1, 2017
1 parent 685b8b2 commit 11b8f2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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 @@ -180,7 +181,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 @@ -557,9 +558,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 @@ -569,7 +568,7 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
return;
}

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
@@ -1,7 +1,6 @@
package com.mapbox.mapboxsdk.maps;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ZoomButtonsController;

import com.mapbox.mapboxsdk.constants.MapboxConstants;
Expand All @@ -12,21 +11,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 11b8f2d

Please sign in to comment.