diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | 207 |
1 files changed, 149 insertions, 58 deletions
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 index d6cb106054..1538f49d60 100644 --- 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 @@ -1,9 +1,14 @@ package com.mapbox.mapboxsdk.maps; +import android.support.annotation.FloatRange; import android.support.annotation.NonNull; import android.support.annotation.UiThread; +import android.util.Log; import android.view.Gravity; import android.view.View; +import android.widget.VideoView; + +import com.mapbox.mapboxsdk.constants.MapboxConstants; /** * Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings(). @@ -12,17 +17,9 @@ public class UiSettings { private MapView mapView; - 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 ViewSettings compassSettings; + private ViewSettings logoSettings; + private ViewSettings attributionSettings; private boolean rotateGesturesEnabled; private boolean tiltGesturesEnabled; @@ -30,11 +27,78 @@ public class UiSettings { private boolean zoomControlsEnabled; private boolean scrollGesturesEnabled; + private double maxZoomLevel = -1; + private double minZoomLevel = -1; + UiSettings(@NonNull MapView mapView) { this.mapView = mapView; - this.compassMargins = new int[4]; - this.attributionMargins = new int[4]; - this.logoMargins = new int[4]; + this.compassSettings = new ViewSettings(); + this.logoSettings = new ViewSettings(); + this.attributionSettings = new ViewSettings(); + } + + /** + * <p> + * Sets the minimum zoom level the map can be displayed at. + * </p> + * + * @param minZoom The new minimum zoom level. + */ + @UiThread + public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) { + if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) { + Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom); + return; + } + minZoomLevel = minZoom; + mapView.setMinZoom(minZoom); + } + + /** + * <p> + * Gets the maximum zoom level the map can be displayed at. + * </p> + * + * @return The minimum zoom level. + */ + @UiThread + public double getMinZoom() { + if (minZoomLevel == -1) { + return minZoomLevel = mapView.getMinZoom(); + } + return minZoomLevel; + } + + /** + * <p> + * Sets the maximum zoom level the map can be displayed at. + * </p> + * + * @param maxZoom The new maximum zoom level. + */ + @UiThread + public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) { + if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) { + Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom); + return; + } + maxZoomLevel = maxZoom; + mapView.setMaxZoom(maxZoom); + } + + /** + * <p> + * Gets the maximum zoom level the map can be displayed at. + * </p> + * + * @return The maximum zoom level. + */ + @UiThread + public double getMaxZoom() { + if (maxZoomLevel == -1) { + return maxZoomLevel = mapView.getMaxZoom(); + } + return maxZoomLevel; } /** @@ -49,8 +113,8 @@ public class UiSettings { * @param compassEnabled True to enable the compass; false to disable the compass. */ public void setCompassEnabled(boolean compassEnabled) { - this.compassEnabled = compassEnabled; - this.mapView.setCompassEnabled(compassEnabled); + compassSettings.setEnabled(compassEnabled); + mapView.setCompassEnabled(compassEnabled); } /** @@ -59,7 +123,7 @@ public class UiSettings { * @return True if the compass is enabled; false if the compass is disabled. */ public boolean isCompassEnabled() { - return compassEnabled; + return compassSettings.isEnabled(); } /** @@ -74,8 +138,8 @@ public class UiSettings { */ @UiThread public void setCompassGravity(int gravity) { - this.compassGravity = gravity; - this.mapView.setCompassGravity(gravity); + compassSettings.setGravity(gravity); + mapView.setCompassGravity(gravity); } /** @@ -84,7 +148,7 @@ public class UiSettings { * @return The gravity */ public int getCompassGravity() { - return compassGravity; + return compassSettings.getGravity(); } /** @@ -98,8 +162,8 @@ public class UiSettings { */ @UiThread public void setCompassMargins(int left, int top, int right, int bottom) { - this.compassMargins = new int[]{left, top, right, bottom}; - this.mapView.setCompassMargins(left, top, right, bottom); + compassSettings.setMargins(new int[]{left, top, right, bottom}); + mapView.setCompassMargins(left, top, right, bottom); } /** @@ -108,7 +172,7 @@ public class UiSettings { * @return The left margin in pixels */ public int getCompassMarginLeft() { - return compassMargins[0]; + return compassSettings.getMargins()[0]; } /** @@ -117,7 +181,7 @@ public class UiSettings { * @return The top margin in pixels */ public int getCompassMarginTop() { - return compassMargins[1]; + return compassSettings.getMargins()[1]; } /** @@ -126,7 +190,7 @@ public class UiSettings { * @return The right margin in pixels */ public int getCompassMarginRight() { - return compassMargins[2]; + return compassSettings.getMargins()[2]; } /** @@ -135,7 +199,7 @@ public class UiSettings { * @return The bottom margin in pixels */ public int getCompassMarginBottom() { - return compassMargins[3]; + return compassSettings.getMargins()[3]; } /** @@ -147,8 +211,8 @@ public class UiSettings { * @param enabled True to enable the logo; false to disable the logo. */ public void setLogoEnabled(boolean enabled) { - this.logoEnabled = enabled; - this.mapView.setLogoVisibility(enabled ); + logoSettings.setEnabled(enabled); + mapView.setLogoVisibility(enabled); } /** @@ -157,7 +221,7 @@ public class UiSettings { * @return True if the logo is enabled; false if the logo is disabled. */ public boolean isLogoEnabled() { - return logoEnabled; + return logoSettings.isEnabled(); } /** @@ -171,8 +235,8 @@ public class UiSettings { * @see Gravity */ public void setLogoGravity(int gravity) { - this.logoGravity = gravity; - this.mapView.setLogoGravity(gravity); + logoSettings.setGravity(gravity); + mapView.setLogoGravity(gravity); } /** @@ -181,7 +245,7 @@ public class UiSettings { * @return The gravity */ public int getLogoGravity() { - return logoGravity; + return logoSettings.getGravity(); } /** @@ -194,8 +258,8 @@ public class UiSettings { * @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.mapView.setLogoMargins(left, top, right, bottom); + logoSettings.setMargins(new int[]{left, top, right, bottom}); + mapView.setLogoMargins(left, top, right, bottom); } /** @@ -203,8 +267,8 @@ public class UiSettings { * * @return The left margin in pixels */ - public int getLogoMarginLeft(){ - return logoMargins[0]; + public int getLogoMarginLeft() { + return logoSettings.getMargins()[0]; } /** @@ -212,8 +276,8 @@ public class UiSettings { * * @return The top margin in pixels */ - public int getLogoMarginTop(){ - return logoMargins[1]; + public int getLogoMarginTop() { + return logoSettings.getMargins()[1]; } /** @@ -221,8 +285,8 @@ public class UiSettings { * * @return The right margin in pixels */ - public int getLogoMarginRight(){ - return logoMargins[2]; + public int getLogoMarginRight() { + return logoSettings.getMargins()[2]; } /** @@ -230,8 +294,8 @@ public class UiSettings { * * @return The bottom margin in pixels */ - public int getLogoMarginBottom(){ - return logoMargins[3]; + public int getLogoMarginBottom() { + return logoSettings.getMargins()[3]; } /** @@ -243,8 +307,8 @@ public class UiSettings { * @param enabled True to enable the logo; false to disable the logo. */ public void setAttributionEnabled(boolean enabled) { - this.attributionEnabled = enabled; - this.mapView.setAttributionVisibility(enabled ? View.VISIBLE : View.GONE); + attributionSettings.setEnabled(enabled); + mapView.setAttributionVisibility(enabled ? View.VISIBLE : View.GONE); } /** @@ -253,7 +317,7 @@ public class UiSettings { * @return True if the logo is enabled; false if the logo is disabled. */ public boolean isAttributionEnabled() { - return attributionEnabled; + return attributionSettings.isEnabled(); } /** @@ -267,8 +331,8 @@ public class UiSettings { * @see Gravity */ public void setAttributionGravity(int gravity) { - this.attributionGravity = gravity; - this.mapView.setAttributionGravity(gravity); + attributionSettings.setGravity(gravity); + mapView.setAttributionGravity(gravity); } /** @@ -277,7 +341,7 @@ public class UiSettings { * @return The gravity */ public int getAttributionGravity() { - return attributionGravity; + return attributionSettings.getGravity(); } /** @@ -290,8 +354,8 @@ public class UiSettings { * @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.mapView.setAttributionMargins(left, top, right, bottom); + attributionSettings.setMargins(new int[]{left, top, right, bottom}); + mapView.setAttributionMargins(left, top, right, bottom); } /** @@ -299,8 +363,8 @@ public class UiSettings { * * @return The left margin in pixels */ - public int getAttributionMarginLeft(){ - return attributionMargins[0]; + public int getAttributionMarginLeft() { + return attributionSettings.getMargins()[0]; } /** @@ -308,8 +372,8 @@ public class UiSettings { * * @return The top margin in pixels */ - public int getAttributionMarginTop(){ - return attributionMargins[1]; + public int getAttributionMarginTop() { + return attributionSettings.getMargins()[1]; } /** @@ -317,8 +381,8 @@ public class UiSettings { * * @return The right margin in pixels */ - public int getAttributionMarginRight(){ - return attributionMargins[2]; + public int getAttributionMarginRight() { + return attributionSettings.getMargins()[2]; } /** @@ -326,8 +390,8 @@ public class UiSettings { * * @return The bottom margin in pixels */ - public int getAttributionMarginBottom(){ - return attributionMargins[3]; + public int getAttributionMarginBottom() { + return attributionSettings.getMargins()[3]; } /** @@ -477,4 +541,31 @@ public class UiSettings { setTiltGesturesEnabled(enabled); setZoomGesturesEnabled(enabled); } + + /** + * Returns the measured height of the MapView + * + * @return height in pixels + */ + public float getHeight() { + return mapView.getMeasuredHeight(); + } + + /** + * Returns the measured width of the MapView + * + * @return widht in pixels + */ + public float getWidth() { + return mapView.getMeasuredWidth(); + } + + /** + * Invalidates the ViewSettings instances shown on top of the MapView + */ + public void invalidate() { + mapView.setLogoMargins(getLogoMarginLeft(), getLogoMarginTop(), getLogoMarginRight(), getLogoMarginBottom()); + mapView.setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom()); + mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom()); + } } |