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

Move ZoomButtonController creation to view initalisation #9587

Merged
merged 2 commits into from
Aug 1, 2017
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 @@ -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 @@ -556,9 +557,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 @@ -568,7 +567,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);
}
}