From 7c58c7803eb6c9504cc3f0439a3735bba1d4275a Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 1 Feb 2016 10:01:59 +0100 Subject: [android] #3760 - parity with Google Maps SDK [android] #3760 - added missing methods for UiSettings, updated tests and test app to reflect this change [android] #3760 - typo fix --- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 118 +++-- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 329 ++------------ .../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 26 +- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 479 +++++++++++++++++++++ .../testapp/CoordinateChangeActivity.java | 5 +- .../mapboxsdk/testapp/DoubleMapActivity.java | 13 +- .../com/mapbox/mapboxsdk/testapp/MainActivity.java | 6 +- .../mapboxsdk/testapp/ManualZoomActivity.java | 5 +- .../testapp/VisibleCoordinateBoundsActivity.java | 5 +- .../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 82 +--- .../com/mapbox/mapboxsdk/maps/UiSettingsTest.java | 215 +++++++++ 11 files changed, 819 insertions(+), 464 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index f47f30ee07..a62bb1e862 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -245,11 +245,13 @@ public class MapView extends FrameLayout { } // Enable gestures - mMapboxMap.setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true)); - mMapboxMap.setScrollEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true)); - mMapboxMap.setRotateEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true)); - mMapboxMap.setTiltEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true)); - mMapboxMap.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, mMapboxMap.isZoomControlsEnabled())); + UiSettings uiSettings = mMapboxMap.getUiSettings(); + uiSettings.setZoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true)); + uiSettings.setScrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true)); + uiSettings.setRotateGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true)); + uiSettings.setTiltGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true)); + uiSettings.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, false + )); // Compass mMapboxMap.setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true)); @@ -312,11 +314,14 @@ public class MapView extends FrameLayout { if (cameraPosition != null) { mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } - mMapboxMap.setZoomEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED)); - mMapboxMap.setScrollEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED)); - mMapboxMap.setRotateEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED)); - mMapboxMap.setTiltEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED)); - mMapboxMap.setZoomControlsEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED)); + + UiSettings uiSettings = mMapboxMap.getUiSettings(); + uiSettings.setZoomGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED)); + uiSettings.setScrollGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED)); + uiSettings.setRotateGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED)); + uiSettings.setTiltGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED)); + uiSettings.setZoomControlsEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED)); + mMapboxMap.setDebugActive(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE)); mMapboxMap.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL)); setAccessToken(savedInstanceState.getString(MapboxConstants.STATE_ACCESS_TOKEN)); @@ -390,12 +395,14 @@ public class MapView extends FrameLayout { @UiThread public void onSaveInstanceState(@NonNull Bundle outState) { + UiSettings uiSettings = mMapboxMap.getUiSettings(); + outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition()); - outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, mMapboxMap.isZoomEnabled()); - outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, mMapboxMap.isScrollEnabled()); - outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, mMapboxMap.isRotateEnabled()); - outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, mMapboxMap.isTiltEnabled()); - outState.putBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED, mMapboxMap.isZoomControlsEnabled()); + outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, uiSettings.isZoomGesturesEnabled()); + outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, uiSettings.isScrollGesturesEnabled()); + outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, uiSettings.isRotateGesturesEnabled()); + outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, uiSettings.isTiltGesturesEnabled()); + outState.putBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED, uiSettings.isZoomControlsEnabled()); outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive()); outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl()); outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken()); @@ -406,7 +413,7 @@ public class MapView extends FrameLayout { // Compass LayoutParams compassParams = (LayoutParams) mCompassView.getLayoutParams(); - outState.putBoolean(MapboxConstants.STATE_COMPASS_ENABLED, mMapboxMap.isCompassEnabled()); + outState.putBoolean(MapboxConstants.STATE_COMPASS_ENABLED, uiSettings.isCompassEnabled()); outState.putInt(MapboxConstants.STATE_COMPASS_GRAVITY, compassParams.gravity); outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT, compassParams.leftMargin); outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_TOP, compassParams.topMargin); @@ -824,27 +831,6 @@ public class MapView extends FrameLayout { return mNativeMapView.getMaxZoom(); } - /** - *

- * Changes whether the user may zoom the map. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param zoomEnabled If true, zooming is enabled. - */ - @UiThread - void setZoomEnabled(boolean zoomEnabled) { - if (mMapboxMap.isZoomControlsEnabled() && (getVisibility() == View.VISIBLE) && zoomEnabled) { - mZoomButtonsController.setVisible(true); - } else { - mZoomButtonsController.setVisible(false); - } - } - /** *

* Sets whether the zoom controls are enabled. @@ -858,11 +844,7 @@ public class MapView extends FrameLayout { * @param enabled If true, the zoom controls are enabled. */ void setZoomControlsEnabled(boolean enabled) { - if (enabled && (getVisibility() == View.VISIBLE) && mMapboxMap.isZoomEnabled()) { - mZoomButtonsController.setVisible(true); - } else { - mZoomButtonsController.setVisible(false); - } + mZoomButtonsController.setVisible(enabled); } // Zoom in or out @@ -1720,7 +1702,7 @@ public class MapView extends FrameLayout { protected void onDetachedFromWindow() { super.onDetachedFromWindow(); // Required by ZoomButtonController (from Android SDK documentation) - if (mMapboxMap.isZoomControlsEnabled()) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled()) { mZoomButtonsController.setVisible(false); } } @@ -1729,10 +1711,10 @@ public class MapView extends FrameLayout { @Override protected void onVisibilityChanged(@NonNull View changedView, int visibility) { // Required by ZoomButtonController (from Android SDK documentation) - if (mMapboxMap.isZoomControlsEnabled() && (visibility != View.VISIBLE)) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled() && (visibility != View.VISIBLE)) { mZoomButtonsController.setVisible(false); } - if (mMapboxMap.isZoomControlsEnabled() && (visibility == View.VISIBLE) && mMapboxMap.isZoomEnabled()) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled() && (visibility == View.VISIBLE)) { mZoomButtonsController.setVisible(true); } } @@ -1809,7 +1791,7 @@ public class MapView extends FrameLayout { @SuppressLint("ResourceType") public boolean onDown(MotionEvent event) { // Show the zoom controls - if (mMapboxMap.isZoomControlsEnabled() && mMapboxMap.isZoomEnabled()) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled()) { mZoomButtonsController.setVisible(true); } return true; @@ -1818,7 +1800,7 @@ public class MapView extends FrameLayout { // Called for double taps @Override public boolean onDoubleTapEvent(MotionEvent e) { - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -1937,7 +1919,7 @@ public class MapView extends FrameLayout { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -1970,7 +1952,7 @@ public class MapView extends FrameLayout { // Called for drags @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2001,7 +1983,7 @@ public class MapView extends FrameLayout { // Called when two fingers first touch the screen @Override public boolean onScaleBegin(ScaleGestureDetector detector) { - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2024,7 +2006,7 @@ public class MapView extends FrameLayout { // Called for pinch zooms and quickzooms/quickscales @Override public boolean onScale(ScaleGestureDetector detector) { - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2053,7 +2035,7 @@ public class MapView extends FrameLayout { mQuickZoom = !mTwoTap; // Scale the map - if (mMapboxMap.isScrollEnabled() && !mQuickZoom && mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) { + if (mMapboxMap.getUiSettings().isScrollGesturesEnabled() && !mQuickZoom && mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) { // around gesture mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity); } else { @@ -2074,7 +2056,7 @@ public class MapView extends FrameLayout { // Called when two fingers first touch the screen @Override public boolean onRotateBegin(RotateGestureDetector detector) { - if (!mMapboxMap.isRotateEnabled()) { + if (!mMapboxMap.getUiSettings().isRotateGesturesEnabled()) { return false; } @@ -2097,7 +2079,7 @@ public class MapView extends FrameLayout { // Called for rotation @Override public boolean onRotate(RotateGestureDetector detector) { - if (!mMapboxMap.isRotateEnabled()) { + if (!mMapboxMap.getUiSettings().isRotateGesturesEnabled()) { return false; } @@ -2153,7 +2135,7 @@ public class MapView extends FrameLayout { @Override public boolean onShoveBegin(ShoveGestureDetector detector) { - if (!mMapboxMap.isTiltEnabled()) { + if (!mMapboxMap.getUiSettings().isTiltGesturesEnabled()) { return false; } @@ -2173,7 +2155,7 @@ public class MapView extends FrameLayout { @Override public boolean onShove(ShoveGestureDetector detector) { - if (!mMapboxMap.isTiltEnabled()) { + if (!mMapboxMap.getUiSettings().isTiltGesturesEnabled()) { return false; } @@ -2224,7 +2206,7 @@ public class MapView extends FrameLayout { // Called when user pushes a zoom button @Override public void onZoom(boolean zoomIn) { - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return; } @@ -2255,7 +2237,7 @@ public class MapView extends FrameLayout { return true; case KeyEvent.KEYCODE_DPAD_LEFT: - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2267,7 +2249,7 @@ public class MapView extends FrameLayout { return true; case KeyEvent.KEYCODE_DPAD_RIGHT: - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2279,7 +2261,7 @@ public class MapView extends FrameLayout { return true; case KeyEvent.KEYCODE_DPAD_UP: - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2291,7 +2273,7 @@ public class MapView extends FrameLayout { return true; case KeyEvent.KEYCODE_DPAD_DOWN: - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2317,7 +2299,7 @@ public class MapView extends FrameLayout { // onKeyLongPress is fired case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2347,7 +2329,7 @@ public class MapView extends FrameLayout { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2368,7 +2350,7 @@ public class MapView extends FrameLayout { switch (event.getActionMasked()) { // The trackball was rotated case MotionEvent.ACTION_MOVE: - if (!mMapboxMap.isScrollEnabled()) { + if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } @@ -2396,7 +2378,7 @@ public class MapView extends FrameLayout { // Trackball was released case MotionEvent.ACTION_UP: - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2461,7 +2443,7 @@ public class MapView extends FrameLayout { switch (event.getActionMasked()) { // Mouse scrolls case MotionEvent.ACTION_SCROLL: - if (!mMapboxMap.isZoomEnabled()) { + if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return false; } @@ -2494,14 +2476,14 @@ public class MapView extends FrameLayout { case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: // Show the zoom controls - if (mMapboxMap.isZoomControlsEnabled() && mMapboxMap.isZoomEnabled()) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled()) { mZoomButtonsController.setVisible(true); } return true; case MotionEvent.ACTION_HOVER_EXIT: // Hide the zoom controls - if (mMapboxMap.isZoomControlsEnabled()) { + if (mMapboxMap.getUiSettings().isZoomControlsEnabled()) { mZoomButtonsController.setVisible(false); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 843386dd03..da59d868e0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -41,20 +41,15 @@ import java.util.concurrent.TimeUnit; public class MapboxMap { private MapView mMapView; + private UiSettings mUiSettings; private CameraPosition mCurrentCameraPosition; private String mStyleUrl; private List mSelectedMarkers; private List mInfoWindows; private MapboxMap.InfoWindowAdapter mInfoWindowAdapter; - private boolean mZoomEnabled = true; - private boolean mScrollEnabled = true; - private boolean mRotateEnabled = true; - private boolean mTiltEnabled = true; - private boolean mCompassEnabled = true; private boolean mMyLocationEnabled; private boolean mAllowConcurrentMultipleInfoWindows; - private boolean mZoomControlsEnabled; private MapboxMap.OnMapClickListener mOnMapClickListener; private MapboxMap.OnMapLongClickListener mOnMapLongClickListener; @@ -68,10 +63,24 @@ public class MapboxMap { MapboxMap(@NonNull MapView mapView) { mMapView = mapView; + mUiSettings = new UiSettings(this); mSelectedMarkers = new ArrayList<>(); mInfoWindows = new ArrayList<>(); } + // + // UiSettings + // + + /** + * Gets the user interface settings for the map. + * + * @return + */ + public UiSettings getUiSettings() { + return mUiSettings; + } + // // Camera API // @@ -216,100 +225,10 @@ public class MapboxMap { return durationMs > 0 ? TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS) : 0; } - // - // Scroll - // - - /** - * Returns whether the user may scroll around the map. - * - * @return If true, scrolling is enabled. - */ - @UiThread - public boolean isScrollEnabled() { - return mScrollEnabled; - } - - /** - *

- * Changes whether the user may scroll around the map. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param scrollEnabled If true, scrolling is enabled. - */ - @UiThread - public void setScrollEnabled(boolean scrollEnabled) { - mScrollEnabled = scrollEnabled; - } - - // - // Rotation - // - - /** - * Returns whether the user may rotate the map. - * - * @return If true, rotating is enabled. - */ - @UiThread - public boolean isRotateEnabled() { - return mRotateEnabled; - } - - /** - *

- * Changes whether the user may rotate the map. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param rotateEnabled If true, rotating is enabled. - */ - @UiThread - public void setRotateEnabled(boolean rotateEnabled) { - mRotateEnabled = rotateEnabled; - } - // // ZOOM // - /** - * Returns whether the user may zoom the map. - * - * @return If true, zooming is enabled. - */ - @UiThread - public boolean isZoomEnabled() { - return mZoomEnabled; - } - - /** - *

- * Changes whether the user may zoom the map. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param zoomEnabled If true, zooming is enabled. - */ - @UiThread - public void setZoomEnabled(boolean zoomEnabled) { - mZoomEnabled = zoomEnabled; - mMapView.setZoomEnabled(true); - } - /** *

* Sets the minimum zoom level the map can be displayed at. @@ -370,63 +289,11 @@ public class MapboxMap { // Manual zoom controls // - /** - * Gets whether the zoom controls are enabled. - * - * @return If true, the zoom controls are enabled. - */ - public boolean isZoomControlsEnabled() { - return mZoomControlsEnabled; - } - - /** - *

- * Sets whether the zoom controls are enabled. - * If enabled, the zoom controls are a pair of buttons - * (one for zooming in, one for zooming out) that appear on the screen. - * When pressed, they cause the camera to zoom in (or out) by one zoom level. - * If disabled, the zoom controls are not shown. - *

- * By default the zoom controls are enabled if the device is only single touch capable; - * - * @param enabled If true, the zoom controls are enabled. - */ - public void setZoomControlsEnabled(boolean enabled) { - mZoomControlsEnabled = enabled; + // used by UiSettings + void setZoomControlsEnabled(boolean enabled) { mMapView.setZoomControlsEnabled(enabled); } - // - // Tilt - // - - /** - * Returns whether the user may tilt the map. - * - * @return If true, tilting is enabled. - */ - @UiThread - public boolean isTiltEnabled() { - return mTiltEnabled; - } - - /** - *

- * Changes whether the user may tilt the map. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param tiltEnabled If true, tilting is enabled. - */ - @UiThread - public void setTiltEnabled(boolean tiltEnabled) { - mTiltEnabled = tiltEnabled; - } - // // Debug // @@ -900,33 +767,6 @@ public class MapboxMap { return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet()); } - // - // Touch events - // - - /** - *

- * Sets the preference for whether all gestures should be enabled or disabled. - *

- *

- * This setting controls only user interactions with the map. If you set the value to false, - * you may still change the map location programmatically. - *

- * The default value is true. - * - * @param enabled If true, all gestures are available; otherwise, all gestures are disabled. - * @see MapboxMap#setZoomEnabled(boolean) - * @see MapboxMap#setScrollEnabled(boolean) - * @see MapboxMap#setRotateEnabled(boolean) - * @see MapboxMap#setTiltEnabled(boolean) - */ - public void setAllGesturesEnabled(boolean enabled) { - setZoomEnabled(enabled); - setScrollEnabled(enabled); - setRotateEnabled(enabled); - setTiltEnabled(enabled); - } - // // Map events // @@ -1198,7 +1038,7 @@ public class MapboxMap { mOnMyBearingTrackingModeChangeListener = listener; } - // used by mapview + // used by MapView OnMyBearingTrackingModeChangeListener getOnMyBearingTrackingModeChangeListener() { return mOnMyBearingTrackingModeChangeListener; } @@ -1207,59 +1047,18 @@ public class MapboxMap { // Compass // - /** - * Returns whether the compass is enabled. - * - * @return True if the compass is enabled; false if the compass is disabled. - */ - @UiThread - public boolean isCompassEnabled() { - return mCompassEnabled; - } - - /** - *

- * Enables or disables the compass. The compass is an icon on the map that indicates the - * direction of north on the map. When a user clicks - * the compass, the camera orients itself to its default orientation and fades away shortly - * after. If disabled, the compass will never be displayed. - *

- * By default, the compass is enabled. - * - * @param compassEnabled True to enable the compass; false to disable the compass. - */ - @UiThread - public void setCompassEnabled(boolean compassEnabled) { - mCompassEnabled = compassEnabled; + // used by UiSettings + void setCompassEnabled(boolean compassEnabled) { mMapView.setCompassEnabled(compassEnabled); } - /** - *

- * Sets the gravity of the compass view. Use this to change the corner of the map view that the - * compass is displayed in. - *

- * By default, the compass is in the top right corner. - * - * @param gravity One of the values from {@link Gravity}. - * @see Gravity - */ - @UiThread - public void setCompassGravity(int gravity) { + // used by UiSettings + void setCompassGravity(int gravity) { mMapView.setCompassGravity(gravity); } - /** - * Sets the margins of the compass view. Use this to change the distance of the compass from the - * map view edge. - * - * @param left The left margin in pixels. - * @param top The top margin in pixels. - * @param right The right margin in pixels. - * @param bottom The bottom margin in pixels. - */ - @UiThread - public void setCompassMargins(int left, int top, int right, int bottom) { + // used by UiSettings + void setCompassMargins(int left, int top, int right, int bottom) { mMapView.setCompassMargins(left, top, right, bottom); } @@ -1267,45 +1066,18 @@ public class MapboxMap { // Logo // - /** - *

- * Sets the gravity of the logo view. Use this to change the corner of the map view that the - * Mapbox logo is displayed in. - *

- * By default, the logo is in the bottom left corner. - * - * @param gravity One of the values from {@link Gravity}. - * @see Gravity - */ - @UiThread - public void setLogoGravity(int gravity) { + // used by UiSettings + void setLogoGravity(int gravity) { mMapView.setLogoGravity(gravity); } - /** - * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the - * map view edge. - * - * @param left The left margin in pixels. - * @param top The top margin in pixels. - * @param right The right margin in pixels. - * @param bottom The bottom margin in pixels. - */ - @UiThread - public void setLogoMargins(int left, int top, int right, int bottom) { + // used by UiSettings + void setLogoMargins(int left, int top, int right, int bottom) { mMapView.setLogoMargins(left, top, right, bottom); } - /** - *

- * Enables or disables the Mapbox logo. - *

- * By default, the compass is enabled. - * - * @param visibility True to enable the logo; false to disable the logo. - */ - @UiThread - public void setLogoVisibility(int visibility) { + // used by UiSettings + void setLogoVisibility(int visibility) { mMapView.setLogoVisibility(visibility); } @@ -1313,47 +1085,18 @@ public class MapboxMap { // Attribution // - /** - *

- * Sets the gravity of the attribution button view. Use this to change the corner of the map - * view that the attribution button is displayed in. - *

- * By default, the attribution button is in the bottom left corner. - * - * @param gravity One of the values from {@link Gravity}. - * @see Gravity - */ - @UiThread - public void setAttributionGravity(int gravity) { + // used by UiSettings + void setAttributionGravity(int gravity) { mMapView.setAttributionGravity(gravity); } - /** - * Sets the margins of the attribution button view. Use this to change the distance of the - * attribution button from the map view edge. - * - * @param left The left margin in pixels. - * @param top The top margin in pixels. - * @param right The right margin in pixels. - * @param bottom The bottom margin in pixels. - */ - @UiThread - public void setAttributionMargins(int left, int top, int right, int bottom) { + // used by UiSettings + void setAttributionMargins(int left, int top, int right, int bottom) { mMapView.setAttributionMargins(left, top, right, bottom); } - /** - *

- * Enables or disables the attribution button. The attribution is a button with an "i" than when - * clicked shows a menu with copyright and legal notices. The menu also inlcudes the "Improve - * this map" link which user can report map errors with. - *

- * By default, the attribution button is enabled. - * - * @param visibility True to enable the attribution button; false to disable the attribution button. - */ - @UiThread - public void setAttributionVisibility(int visibility) { + // used by UiSettings + void setAttributionVisibility(int visibility) { mMapView.setAttributionVisibility(visibility); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 6828a6e6d4..a0a03926a3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -15,10 +15,12 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; */ public class MapboxMapOptions implements Parcelable { - public MapboxMap mMapboxMap; + private MapboxMap mMapboxMap; + private UiSettings mUiSettings; public MapboxMapOptions(MapboxMap mapboxMap) { mMapboxMap = mapboxMap; + mUiSettings = mapboxMap.getUiSettings(); } public MapboxMapOptions(Parcel in) { @@ -40,52 +42,52 @@ public class MapboxMapOptions implements Parcelable { } public boolean getCompassEnabled() { - return mMapboxMap.isCompassEnabled(); + return mUiSettings.isCompassEnabled(); } public MapboxMapOptions rotateEnabled(boolean rotateEnabled) { - mMapboxMap.setRotateEnabled(rotateEnabled); + mUiSettings.setRotateGesturesEnabled(rotateEnabled); return this; } public MapboxMapOptions rotateGesturesEnabled(boolean enabled) { - mMapboxMap.setRotateEnabled(enabled); + mUiSettings.setRotateGesturesEnabled(enabled); return this; } public boolean getRotateGesturesEnabled() { - return mMapboxMap.isRotateEnabled(); + return mUiSettings.isRotateGesturesEnabled(); } public MapboxMapOptions scrollGesturesEnabled(boolean enabled) { - mMapboxMap.setScrollEnabled(enabled); + mUiSettings.setScrollGesturesEnabled(enabled); return this; } public boolean getScrollGesturesEnabled() { - return mMapboxMap.isScrollEnabled(); + return mUiSettings.isScrollGesturesEnabled(); } public MapboxMapOptions tiltGesturesEnabled(boolean enabled) { - mMapboxMap.setTiltEnabled(enabled); + mUiSettings.setTiltGesturesEnabled(enabled); return this; } public boolean getTiltGesturesEnabled() { - return mMapboxMap.isTiltEnabled(); + return mUiSettings.isTiltGesturesEnabled(); } public MapboxMapOptions zoomControlsEnabled(boolean enabled) { - mMapboxMap.setZoomControlsEnabled(enabled); + mUiSettings.setZoomControlsEnabled(enabled); return this; } public boolean getZoomControlsEnabled() { - return mMapboxMap.isZoomControlsEnabled(); + return mUiSettings.isZoomControlsEnabled(); } public boolean getZoomGesturesEnabled() { - return mMapboxMap.isZoomEnabled(); + return mUiSettings.isZoomGesturesEnabled(); } public MapboxMapOptions createFromAttributes(Context context, AttributeSet attrs) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java new file mode 100644 index 0000000000..e4ed6d52ee --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -0,0 +1,479 @@ +package com.mapbox.mapboxsdk.maps; + +import android.support.annotation.UiThread; +import android.view.Gravity; +import android.view.View; + +/** + * Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings(). + */ +public class UiSettings { + + private MapboxMap mapboxMap; + + private boolean compassEnabled; + private int compassGravity; + private int[] compassMargins; + + private boolean logoEnabled; + private int logoGravity; + private int[] logoMargins; + + private boolean attributionEnabled; + private int attributionGravity; + private int[] attributionMargins; + + private boolean rotateGesturesEnabled; + private boolean tiltGesturesEnabled; + private boolean zoomGesturesEnabled; + private boolean zoomControlsEnabled; + private boolean scrollGesturesEnabled; + + UiSettings(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + this.compassMargins = new int[4]; + this.attributionMargins = new int[4]; + this.logoMargins = new int[4]; + } + + /** + *

+ * Enables or disables the compass. The compass is an icon on the map that indicates the + * direction of north on the map. When a user clicks + * the compass, the camera orients itself to its default orientation and fades away shortly + * after. If disabled, the compass will never be displayed. + *

+ * By default, the compass is enabled. + * + * @param compassEnabled True to enable the compass; false to disable the compass. + */ + public void setCompassEnabled(boolean compassEnabled) { + this.compassEnabled = compassEnabled; + this.mapboxMap.setCompassEnabled(compassEnabled); + } + + /** + * Returns whether the compass is enabled. + * + * @return True if the compass is enabled; false if the compass is disabled. + */ + public boolean isCompassEnabled() { + return compassEnabled; + } + + /** + *

+ * Sets the gravity of the compass view. Use this to change the corner of the map view that the + * compass is displayed in. + *

+ * By default, the compass is in the top right corner. + * + * @param gravity One of the values from {@link Gravity}. + * @see Gravity + */ + @UiThread + public void setCompassGravity(int gravity) { + this.compassGravity = gravity; + this.mapboxMap.setCompassGravity(gravity); + } + + /** + * Returns the gravity value of the CompassView + * + * @return The gravity + */ + public int getCompassGravity() { + return compassGravity; + } + + /** + * Sets the margins of the compass view. Use this to change the distance of the compass from the + * map view edge. + * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + */ + @UiThread + public void setCompassMargins(int left, int top, int right, int bottom) { + this.compassMargins = new int[]{left, top, right, bottom}; + this.mapboxMap.setCompassMargins(left, top, right, bottom); + } + + /** + * Returns the left side margin of CompassView + * + * @return The left margin in pixels + */ + public int getCompassMarginLeft() { + return compassMargins[0]; + } + + /** + * Returns the top side margin of CompassView + * + * @return The top margin in pixels + */ + public int getCompassMarginTop() { + return compassMargins[1]; + } + + /** + * Returns the right side margin of CompassView + * + * @return The right margin in pixels + */ + public int getCompassMarginRight() { + return compassMargins[2]; + } + + /** + * Returns the bottom side margin of CompassView + * + * @return The bottom margin in pixels + */ + public int getCompassMarginBottom() { + return compassMargins[3]; + } + + /** + *

+ * Enables or disables the Mapbox logo. + *

+ * By default, the compass is enabled. + * + * @param enabled True to enable the logo; false to disable the logo. + */ + public void setLogoEnabled(boolean enabled) { + this.logoEnabled = enabled; + this.mapboxMap.setLogoVisibility(enabled ? View.VISIBLE : View.GONE); + } + + /** + * Returns whether the logo is enabled. + * + * @return True if the logo is enabled; false if the logo is disabled. + */ + public boolean isLogoEnabled() { + return logoEnabled; + } + + /** + *

+ * Sets the gravity of the logo view. Use this to change the corner of the map view that the + * Mapbox logo is displayed in. + *

+ * By default, the logo is in the bottom left corner. + * + * @param gravity One of the values from {@link Gravity}. + * @see Gravity + */ + public void setLogoGravity(int gravity) { + this.logoGravity = gravity; + this.mapboxMap.setLogoGravity(gravity); + } + + /** + * Returns the gravity value of the logo + * + * @return The gravity + */ + public int getLogoGravity() { + return logoGravity; + } + + /** + * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the + * map view edge. + * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + */ + public void setLogoMargins(int left, int top, int right, int bottom) { + this.logoMargins = new int[]{left, top, right, bottom}; + this.mapboxMap.setLogoMargins(left, top, right, bottom); + } + + /** + * Returns the left side margin of the logo + * + * @return The left margin in pixels + */ + public int getLogoMarginLeft(){ + return logoMargins[0]; + } + + /** + * Returns the top side margin of the logo + * + * @return The top margin in pixels + */ + public int getLogoMarginTop(){ + return logoMargins[1]; + } + + /** + * Returns the right side margin of the logo + * + * @return The right margin in pixels + */ + public int getLogoMarginRight(){ + return logoMargins[2]; + } + + /** + * Returns the bottom side margin of the logo + * + * @return The bottom margin in pixels + */ + public int getLogoMarginBottom(){ + return logoMargins[3]; + } + + /** + *

+ * Enables or disables the Mapbox logo. + *

+ * By default, the compass is enabled. + * + * @param enabled True to enable the logo; false to disable the logo. + */ + public void setAttributionEnabled(boolean enabled) { + this.attributionEnabled = enabled; + this.mapboxMap.setAttributionVisibility(enabled ? View.VISIBLE : View.GONE); + } + + /** + * Returns whether the logo is enabled. + * + * @return True if the logo is enabled; false if the logo is disabled. + */ + public boolean isAttributionEnabled() { + return attributionEnabled; + } + + /** + *

+ * Sets the gravity of the logo view. Use this to change the corner of the map view that the + * Mapbox logo is displayed in. + *

+ * By default, the logo is in the bottom left corner. + * + * @param gravity One of the values from {@link Gravity}. + * @see Gravity + */ + public void setAttributionGravity(int gravity) { + this.attributionGravity = gravity; + this.mapboxMap.setAttributionGravity(gravity); + } + + /** + * Returns the gravity value of the logo + * + * @return The gravity + */ + public int getAttributionGravity() { + return attributionGravity; + } + + /** + * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the + * map view edge. + * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + */ + public void setAttributionMargins(int left, int top, int right, int bottom) { + this.attributionMargins = new int[]{left, top, right, bottom}; + this.mapboxMap.setAttributionMargins(left, top, right, bottom); + } + + /** + * Returns the left side margin of the logo + * + * @return The left margin in pixels + */ + public int getAttributionMarginLeft(){ + return attributionMargins[0]; + } + + /** + * Returns the top side margin of the logo + * + * @return The top margin in pixels + */ + public int getAttributionMarginTop(){ + return attributionMargins[1]; + } + + /** + * Returns the right side margin of the logo + * + * @return The right margin in pixels + */ + public int getAttributionMarginRight(){ + return attributionMargins[2]; + } + + /** + * Returns the bottom side margin of the logo + * + * @return The bottom margin in pixels + */ + public int getAttributionMarginBottom(){ + return attributionMargins[3]; + } + + /** + *

+ * Changes whether the user may rotate the map. + *

+ *

+ * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + *

+ * The default value is true. + * + * @param rotateGesturesEnabled If true, rotating is enabled. + */ + public void setRotateGesturesEnabled(boolean rotateGesturesEnabled) { + this.rotateGesturesEnabled = rotateGesturesEnabled; + } + + /** + * Returns whether the user may rotate the map. + * + * @return If true, rotating is enabled. + */ + public boolean isRotateGesturesEnabled() { + return rotateGesturesEnabled; + } + + /** + *

+ * Changes whether the user may tilt the map. + *

+ *

+ * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + *

+ * The default value is true. + * + * @param tiltGesturesEnabled If true, tilting is enabled. + */ + public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) { + this.tiltGesturesEnabled = tiltGesturesEnabled; + } + + /** + * Returns whether the user may tilt the map. + * + * @return If true, tilting is enabled. + */ + public boolean isTiltGesturesEnabled() { + return tiltGesturesEnabled; + } + + /** + *

+ * Changes whether the user may zoom the map. + *

+ *

+ * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + *

+ * The default value is true. + * + * @param zoomGesturesEnabled If true, zooming is enabled. + */ + public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { + this.zoomGesturesEnabled = zoomGesturesEnabled; + } + + /** + * Returns whether the user may zoom the map. + * + * @return If true, zooming is enabled. + */ + public boolean isZoomGesturesEnabled() { + return zoomGesturesEnabled; + } + + /** + *

+ * Sets whether the zoom controls are enabled. + * If enabled, the zoom controls are a pair of buttons + * (one for zooming in, one for zooming out) that appear on the screen. + * When pressed, they cause the camera to zoom in (or out) by one zoom level. + * If disabled, the zoom controls are not shown. + *

+ * By default the zoom controls are enabled if the device is only single touch capable; + * + * @param zoomControlsEnabled If true, the zoom controls are enabled. + */ + public void setZoomControlsEnabled(boolean zoomControlsEnabled) { + this.zoomControlsEnabled = zoomControlsEnabled; + } + + /** + * Gets whether the zoom controls are enabled. + * + * @return If true, the zoom controls are enabled. + */ + public boolean isZoomControlsEnabled() { + return zoomControlsEnabled; + } + + /** + *

+ * Changes whether the user may scroll around the map. + *

+ *

+ * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + *

+ * The default value is true. + * + * @param scrollGesturesEnabled If true, scrolling is enabled. + */ + public void setScrollGesturesEnabled(boolean scrollGesturesEnabled) { + this.scrollGesturesEnabled = scrollGesturesEnabled; + } + + /** + * Returns whether the user may scroll around the map. + * + * @return If true, scrolling is enabled. + */ + public boolean isScrollGesturesEnabled() { + return scrollGesturesEnabled; + } + + /** + *

+ * Sets the preference for whether all gestures should be enabled or disabled. + *

+ *

+ * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + *

+ * The default value is true. + * + * @param enabled If true, all gestures are available; otherwise, all gestures are disabled. + * @see #setZoomGesturesEnabled(boolean) ) + * @see #setScrollGesturesEnabled(boolean) + * @see #setRotateGesturesEnabled(boolean) + * @see #setTiltGesturesEnabled(boolean) + */ + public void setAllGesturesEnabled(boolean enabled) { + setScrollGesturesEnabled(enabled); + setRotateGesturesEnabled(enabled); + setTiltGesturesEnabled(enabled); + setZoomGesturesEnabled(enabled); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java index 799ea8c0e1..b9db578564 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java @@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.maps.MapView; @@ -47,8 +48,10 @@ public class CoordinateChangeActivity extends AppCompatActivity { public void onMapReady(@NonNull MapboxMap mapboxMap) { mMapboxMap = mapboxMap; mapboxMap.setStyle(Style.MAPBOX_STREETS); - mapboxMap.setCompassEnabled(false); mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16)); + + UiSettings uiSettings = mapboxMap.getUiSettings(); + uiSettings.setCompassEnabled(false); } }); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java index 360ea584aa..3a3b170a86 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java @@ -18,6 +18,7 @@ import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.UiSettings; public class DoubleMapActivity extends AppCompatActivity { @@ -86,12 +87,14 @@ public class DoubleMapActivity extends AppCompatActivity { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { mapboxMap.setStyle(Style.LIGHT); - mapboxMap.setAllGesturesEnabled(false); - mapboxMap.setCompassEnabled(false); - mapboxMap.setAttributionVisibility(View.GONE); - mapboxMap.setLogoVisibility(View.GONE); mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4)); + UiSettings uiSettings = mapboxMap.getUiSettings(); + uiSettings.setAllGesturesEnabled(false); + uiSettings.setCompassEnabled(false); + uiSettings.setAttributionEnabled(false); + uiSettings.setLogoEnabled(false); + try { mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); }catch (SecurityException e){ @@ -162,6 +165,4 @@ public class DoubleMapActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } } - - } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index 7239611ef2..7c17b5f55e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -38,6 +38,7 @@ import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.layers.CustomLayer; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer; import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil; import com.mapbox.mapboxsdk.utils.ApiAccess; @@ -164,7 +165,7 @@ public class MainActivity extends AppCompatActivity { }); // Set default UI state - mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mapboxMap.isCompassEnabled()); + mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mapboxMap.getUiSettings().isCompassEnabled()); mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mapboxMap.isDebugActive()); mNavigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn); toggleGps(mapboxMap.isMyLocationEnabled()); @@ -348,7 +349,8 @@ public class MainActivity extends AppCompatActivity { case R.id.action_compass: // Toggle compass - mMapboxMap.setCompassEnabled(!mMapboxMap.isCompassEnabled()); + UiSettings uiSettings = mMapboxMap.getUiSettings(); + uiSettings.setCompassEnabled(!uiSettings.isCompassEnabled()); return true; case R.id.action_mapboxmap: diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java index 9a4b5e9ecb..b0146fe73b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java @@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.maps.MapView; @@ -44,7 +45,9 @@ public class ManualZoomActivity extends AppCompatActivity { public void onMapReady(@NonNull final MapboxMap mapboxMap) { mMapboxMap = mapboxMap; mMapboxMap.setStyle(Style.SATELLITE_STREETS); - mMapboxMap.setAllGesturesEnabled(false); + + UiSettings uiSettings = mMapboxMap.getUiSettings(); + uiSettings.setAllGesturesEnabled(false); } }); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java index 8b5538eb82..894b5805cc 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java @@ -18,6 +18,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.maps.MapView; @@ -48,7 +49,9 @@ public class VisibleCoordinateBoundsActivity extends AppCompatActivity { @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { mapboxMap.setStyle(Style.DARK); - mapboxMap.setAllGesturesEnabled(false); + + UiSettings uiSettings = mapboxMap.getUiSettings(); + uiSettings.setAllGesturesEnabled(false); mapboxMap.addMarker(new MarkerOptions() .title("Los Angeles") diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java index 92809fdde1..8677346336 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -1,7 +1,5 @@ package com.mapbox.mapboxsdk.maps; -import android.util.Log; - import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; @@ -9,8 +7,6 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; import org.junit.Before; import org.junit.Test; @@ -18,8 +14,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.lang.reflect.Constructor; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -51,78 +45,6 @@ public class MapboxMapTest { assertNotNull("mMapboxMap should not be null", mMapboxMap); } - @Test - public void testCompassEnabled() { - mMapboxMap.setCompassEnabled(true); - assertTrue("CompassEnabled should be true", mMapboxMap.isCompassEnabled()); - } - - @Test - public void testCompassDisabled() { - mMapboxMap.setCompassEnabled(false); - assertFalse("CompassbEnabled should be false", mMapboxMap.isCompassEnabled()); - } - - @Test - public void testScrollEnabled() { - mMapboxMap.setScrollEnabled(true); - assertTrue("ScrollEnabled should be true", mMapboxMap.isScrollEnabled()); - } - - @Test - public void testScrollDisabled() { - mMapboxMap.setScrollEnabled(false); - assertFalse("ScrollEnabled should be false", mMapboxMap.isScrollEnabled()); - } - - @Test - public void testRotateEnabled() { - mMapboxMap.setRotateEnabled(true); - assertTrue("RotateEnabled should be true", mMapboxMap.isRotateEnabled()); - } - - @Test - public void testRotateDisabled() { - mMapboxMap.setRotateEnabled(false); - assertFalse("RotateDisabled should be false", mMapboxMap.isRotateEnabled()); - } - - @Test - public void testZoomEnabled() { - mMapboxMap.setZoomEnabled(true); - assertTrue("ZoomEnabled should be true", mMapboxMap.isZoomEnabled()); - } - - @Test - public void testZoomDisabled() { - mMapboxMap.setZoomEnabled(false); - assertFalse("ZoomEnabled should be false", mMapboxMap.isZoomEnabled()); - } - - @Test - public void testZoomControlsEnabled() { - mMapboxMap.setZoomControlsEnabled(true); - assertTrue("ZoomControlsEnabled should be true", mMapboxMap.isZoomControlsEnabled()); - } - - @Test - public void testZoomControlsDisabled() { - mMapboxMap.setZoomControlsEnabled(false); - assertFalse("ZoomControlsEnabled should be false", mMapboxMap.isZoomControlsEnabled()); - } - - @Test - public void testTiltEnabled() { - mMapboxMap.setTiltEnabled(true); - assertTrue("TiltEnabled should be true", mMapboxMap.isTiltEnabled()); - } - - @Test - public void testTiltDisabled() { - mMapboxMap.setTiltEnabled(false); - assertFalse("TiltEnabled should be false", mMapboxMap.isTiltEnabled()); - } - @Test public void testConcurrentInfoWindowEnabled() { mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); @@ -185,7 +107,7 @@ public class MapboxMapTest { public void testAnimateCamera() { CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position)); - assertEquals("CameraPosition should be same", position , mMapboxMap.getCameraPosition()); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); } @Test @@ -199,7 +121,7 @@ public class MapboxMapTest { public void testAnimateCameraWithDurationParameter() { CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build(); mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0); - assertEquals("CameraPosition should be same",position, mMapboxMap.getCameraPosition()); + assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition()); } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java new file mode 100644 index 0000000000..1494c65b05 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java @@ -0,0 +1,215 @@ +package com.mapbox.mapboxsdk.maps; + +import android.view.Gravity; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +public class UiSettingsTest { + + private MapboxMap mMapboxMap; + + @InjectMocks + MapView mMapView = mock(MapView.class); + + @Before + public void beforeTest() { + mMapboxMap = new MapboxMap(mMapView); + } + + @Test + public void testSanity() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + assertNotNull("uiSettings should not be null", uiSettings); + } + + @Test + public void testCompassEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setCompassEnabled(true); + assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled()); + } + + @Test + public void testCompassDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setCompassEnabled(false); + assertEquals("Compass should be disabled", false, uiSettings.isCompassEnabled()); + } + + @Test + public void testCompassGravity() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setCompassGravity(Gravity.LEFT); + assertEquals("Compass gravity should be same", Gravity.LEFT, uiSettings.getCompassGravity()); + } + + @Test + public void testCompassMargins() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setCompassMargins(1, 2, 3, 4); + assertTrue("Compass margin left should be same", uiSettings.getCompassMarginLeft() == 1); + assertTrue("Compass margin top should be same", uiSettings.getCompassMarginTop() == 2); + assertTrue("Compass margin right should be same", uiSettings.getCompassMarginRight() == 3); + assertTrue("Compass margin bottom should be same", uiSettings.getCompassMarginBottom() == 4); + } + + @Test + public void testLogoEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setLogoEnabled(true); + assertEquals("Logo should be enabled", true, uiSettings.isLogoEnabled()); + } + + @Test + public void testLogoDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setLogoEnabled(false); + assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled()); + } + + @Test + public void testLogoGravity() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setLogoGravity(Gravity.RIGHT); + assertEquals("Logo gravity should be same", Gravity.RIGHT, uiSettings.getLogoGravity()); + } + + @Test + public void testLogoMargins() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setLogoMargins(1, 2, 3, 4); + assertTrue("Compass margin left should be same", uiSettings.getLogoMarginLeft() == 1); + assertTrue("Compass margin top should be same", uiSettings.getLogoMarginTop() == 2); + assertTrue("Compass margin right should be same", uiSettings.getLogoMarginRight() == 3); + assertTrue("Compass margin bottom should be same", uiSettings.getLogoMarginBottom() == 4); + } + + @Test + public void testAttributionEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAttributionEnabled(true); + assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled()); + } + + @Test + public void testAttributionDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAttributionEnabled(false); + assertEquals("Attribution should be disabled", false, uiSettings.isLogoEnabled()); + } + + @Test + public void testAttributionGravity() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAttributionGravity(Gravity.RIGHT); + assertEquals("Attribution gravity should be same", Gravity.RIGHT, uiSettings.getAttributionGravity()); + } + + @Test + public void testAttributionMargins() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAttributionMargins(1, 2, 3, 4); + assertTrue("Attribution margin left should be same", uiSettings.getAttributionMarginLeft() == 1); + assertTrue("Attribution margin top should be same", uiSettings.getAttributionMarginTop() == 2); + assertTrue("Attribution margin right should be same", uiSettings.getAttributionMarginRight() == 3); + assertTrue("Attribution margin bottom should be same", uiSettings.getAttributionMarginBottom() == 4); + } + + @Test + public void testRotateGesturesEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setRotateGesturesEnabled(true); + assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled()); + } + + @Test + public void testRotateGesturesDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setRotateGesturesEnabled(false); + assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled()); + } + + @Test + public void testTiltGesturesEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setTiltGesturesEnabled(true); + assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled()); + } + + @Test + public void testTiltGesturesDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setTiltGesturesEnabled(false); + assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled()); + } + + @Test + public void testZoomGesturesEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setZoomGesturesEnabled(true); + assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled()); + } + + @Test + public void testZoomGesturesDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setZoomGesturesEnabled(false); + assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); + } + + @Test + public void testZoomControlsEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setZoomControlsEnabled(true); + assertEquals("Zoom controls should be enabled", true, uiSettings.isZoomControlsEnabled()); + } + + @Test + public void testZoomControlsDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setZoomControlsEnabled(false); + assertEquals("Zoom controls should be disabled", false, uiSettings.isZoomControlsEnabled()); + } + + @Test + public void testScrollGesturesEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setScrollGesturesEnabled(true); + assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); + } + + @Test + public void testScrollGesturesDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setScrollGesturesEnabled(false); + assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); + } + + @Test + public void testAllGesturesEnabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAllGesturesEnabled(true); + assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled()); + assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled()); + assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled()); + assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); + } + + @Test + public void testAllGesturesDisabled() { + UiSettings uiSettings = new UiSettings(mMapboxMap); + uiSettings.setAllGesturesEnabled(false); + assertEquals("Rotate gesture should be enabled", false, uiSettings.isRotateGesturesEnabled()); + assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled()); + assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); + assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); + } + +} \ No newline at end of file -- cgit v1.2.1