[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
This commit is contained in:
Tobrun
2016-02-01 10:01:59 +01:00
parent 5c1bad41bd
commit 7c58c7803e
11 changed files with 819 additions and 464 deletions

View File

@@ -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();
}
/**
* <p>
* Changes whether the user may zoom the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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);
}
}
/**
* <p>
* 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);
}

View File

@@ -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<Marker> mSelectedMarkers;
private List<InfoWindow> 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;
}
/**
* <p>
* Changes whether the user may scroll around the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may rotate the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may zoom the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* The default value is true.
*
* @param zoomEnabled If true, zooming is enabled.
*/
@UiThread
public void setZoomEnabled(boolean zoomEnabled) {
mZoomEnabled = zoomEnabled;
mMapView.setZoomEnabled(true);
}
/**
* <p>
* 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;
}
/**
* <p>
* 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.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may tilt the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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
//
/**
* <p>
* Sets the preference for whether all gestures should be enabled or disabled.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* 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.
* </p>
* 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);
}
/**
* <p>
* Sets the gravity of the compass view. Use this to change the corner of the map view that the
* compass is displayed in.
* </p>
* 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
//
/**
* <p>
* Sets the gravity of the logo view. Use this to change the corner of the map view that the
* Mapbox logo is displayed in.
* </p>
* 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);
}
/**
* <p>
* Enables or disables the Mapbox logo.
* </p>
* 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
//
/**
* <p>
* 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.
* </p>
* 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);
}
/**
* <p>
* 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.
* </p>
* 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);
}

View File

@@ -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) {

View File

@@ -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];
}
/**
* <p>
* 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.
* </p>
* 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;
}
/**
* <p>
* Sets the gravity of the compass view. Use this to change the corner of the map view that the
* compass is displayed in.
* </p>
* 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];
}
/**
* <p>
* Enables or disables the Mapbox logo.
* </p>
* 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;
}
/**
* <p>
* Sets the gravity of the logo view. Use this to change the corner of the map view that the
* Mapbox logo is displayed in.
* </p>
* 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];
}
/**
* <p>
* Enables or disables the Mapbox logo.
* </p>
* 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;
}
/**
* <p>
* Sets the gravity of the logo view. Use this to change the corner of the map view that the
* Mapbox logo is displayed in.
* </p>
* 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];
}
/**
* <p>
* Changes whether the user may rotate the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may tilt the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may zoom the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* 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.
* </p>
* 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;
}
/**
* <p>
* Changes whether the user may scroll around the map.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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;
}
/**
* <p>
* Sets the preference for whether all gestures should be enabled or disabled.
* </p>
* <p>
* This setting controls only user interactions with the map. If you set the value to false,
* you may still change the map location programmatically.
* </p>
* 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);
}
}