[Android] #3761 - add map padding, introduce new feature activity

[android] #3781 #3899 - add map padding, user location view, ViewSettings, TrackingSettings

[android] #3761 - update map padding sample

[android] #3761 - add map padding
This commit is contained in:
Tobrun
2016-02-10 12:29:13 +01:00
parent 7d6ac6adfc
commit 1b7ebca279
17 changed files with 633 additions and 208 deletions

View File

@@ -144,12 +144,10 @@ public class MapView extends FrameLayout {
private boolean mZoomStarted = false;
private boolean mQuickZoom = false;
/*
private int mContentPaddingLeft;
private int mContentPaddingTop;
private int mContentPaddingRight;
private int mContentPaddingBottom;
*/
@UiThread
public MapView(@NonNull Context context) {
@@ -368,9 +366,9 @@ public class MapView extends FrameLayout {
}
//noinspection ResourceType
mMapboxMap.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
//noinspection ResourceType
mMapboxMap.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
} else {
// Force a check for Telemetry
validateTelemetryServiceConfigured();
@@ -414,8 +412,8 @@ public class MapView extends FrameLayout {
outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken());
outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, mMapboxMap.getMyLocationTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, mMapboxMap.getMyBearingTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, getMyLocationTrackingMode());
outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, getMyBearingTrackingMode());
// UiSettings
UiSettings uiSettings = mMapboxMap.getUiSettings();
@@ -648,6 +646,46 @@ public class MapView extends FrameLayout {
mNativeMapView.resetNorth();
}
//
// Content padding
//
/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding left
*/
int getContentPaddingLeft() {
return mContentPaddingLeft;
}
/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding left
*/
int getContentPaddingTop() {
return mContentPaddingTop;
}
/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding right
*/
int getContentPaddingRight() {
return mContentPaddingRight;
}
/**
* Return The current content padding left of the map view viewport.
*
* @return The current content padding bottom
*/
int getContentPaddingBottom() {
return mContentPaddingBottom;
}
//
// Zoom
//
@@ -663,51 +701,6 @@ public class MapView extends FrameLayout {
return mNativeMapView.getZoom();
}
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingLeft() {
// return mContentPaddingLeft;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingTop() {
// return mContentPaddingTop;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @return The current content padding left
// */
///*
// public int getContentPaddingRight() {
// return mContentPaddingRight;
// }
//*/
//
// /**
// * Return The current content padding left of the map view viewport.
// *
// * @param zoomLevel The new zoom level.
// * @param animated If true, animates the change. If false, immediately changes the map.
// * @see MapboxMap#MAXIMUM_ZOOM
// */
///*
// public int getContentPaddingBottom() {
// return mContentPaddingBottom;
//*/
/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
@@ -1372,6 +1365,35 @@ public class MapView extends FrameLayout {
* mScreenDensity);
}
/**
* Sets the distance from the edges of the map view’s frame to the edges of the map
* view’s logical viewport.
* <p/>
* When the value of this property is equal to {0,0,0,0}, viewport
* properties such as `centerCoordinate` assume a viewport that matches the map
* view’s frame. Otherwise, those properties are inset, excluding part of the
* frame from the viewport. For instance, if the only the top edge is inset, the
* map center is effectively shifted downward.
*
* @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
void setContentPadding(int left, int top, int right, int bottom) {
if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
return;
}
mContentPaddingLeft = left;
mContentPaddingTop = top;
mContentPaddingRight = right;
mContentPaddingBottom = bottom;
mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
}
/**
* <p>
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
@@ -1750,8 +1772,9 @@ public class MapView extends FrameLayout {
// Zoom in on gesture
zoom(true, e.getX(), e.getY());
} else {
// Zoom in on center map
zoom(true, getWidth() / 2, getHeight() / 2);
// Zoom in on user location view
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
zoom(true, centerPoint.x, centerPoint.y);
}
break;
}
@@ -1852,7 +1875,9 @@ public class MapView extends FrameLayout {
}
// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
resetTrackingModes();
}
// Fling the map
float ease = 0.25f;
@@ -1884,8 +1909,10 @@ public class MapView extends FrameLayout {
return false;
}
// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
// Cancel any animation
mNativeMapView.cancelTransitions();
@@ -1915,8 +1942,10 @@ public class MapView extends FrameLayout {
return false;
}
// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
mBeginTime = detector.getEventTime();
return true;
@@ -1968,7 +1997,8 @@ public class MapView extends FrameLayout {
mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity);
} else {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.scaleBy(detector.getScaleFactor(), centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
}
return true;
}
@@ -1988,8 +2018,10 @@ public class MapView extends FrameLayout {
return false;
}
// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
mBeginTime = detector.getEventTime();
return true;
@@ -2044,10 +2076,9 @@ public class MapView extends FrameLayout {
detector.getFocusX() / mScreenDensity,
detector.getFocusY() / mScreenDensity);
} else {
// around center map
mNativeMapView.setBearing(bearing,
(getWidth() / 2) / mScreenDensity,
(getHeight() / 2) / mScreenDensity);
// around center userlocation
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.setBearing(bearing, centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
}
return true;
}
@@ -2067,8 +2098,10 @@ public class MapView extends FrameLayout {
return false;
}
// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
mBeginTime = detector.getEventTime();
return true;
@@ -2137,8 +2170,6 @@ public class MapView extends FrameLayout {
if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) {
return;
}
// Zoom in or out
zoom(zoomIn);
}
}
@@ -2889,6 +2920,10 @@ public class MapView extends FrameLayout {
private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) {
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
left += mContentPaddingLeft;
top += mContentPaddingTop;
right += mContentPaddingRight;
bottom += mContentPaddingBottom;
layoutParams.setMargins(left, top, right, bottom);
view.setLayoutParams(layoutParams);
}
@@ -3171,4 +3206,5 @@ public class MapView extends FrameLayout {
void onMapChanged(@MapChange int change);
}
}

View File

@@ -40,6 +40,7 @@ public class MapboxMap {
private MapView mMapView;
private UiSettings mUiSettings;
private TrackingSettings mTrackingSettings;
private Projection mProjection;
private CameraPosition mCameraPosition;
private boolean mInvalidCameraPosition;
@@ -68,6 +69,7 @@ public class MapboxMap {
mMapView = mapView;
mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener());
mUiSettings = new UiSettings(mapView);
mTrackingSettings = new TrackingSettings(mMapView, mUiSettings);
mProjection = new Projection(mapView);
mSelectedMarkers = new ArrayList<>();
mInfoWindows = new ArrayList<>();
@@ -86,6 +88,19 @@ public class MapboxMap {
return mUiSettings;
}
//
// TrackingSettings
//
/**
* Gets the tracking interface settings for the map.
*
* @return
*/
public TrackingSettings getTrackingSettings(){
return mTrackingSettings;
}
//
// Projection
//
@@ -795,6 +810,32 @@ public class MapboxMap {
return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
}
//
// Padding
//
/**
* Sets the distance from the edges of the map view’s frame to the edges of the map
* view’s logical viewport.
* <p/>
* When the value of this property is equal to {0,0,0,0}, viewport
* properties such as `centerCoordinate` assume a viewport that matches the map
* view’s frame. Otherwise, those properties are inset, excluding part of the
* frame from the viewport. For instance, if the only the top edge is inset, the
* map center is effectively shifted downward.
*
* @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 setPadding(int left, int top, int right, int bottom) {
mMapView.setContentPadding(left, top, right, bottom);
mUiSettings.invalidate();
moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(mCameraPosition).build()));
}
//
// Map events
//
@@ -1014,40 +1055,6 @@ public class MapboxMap {
mMapView.setOnMyLocationChangeListener(listener);
}
/**
* <p>
* Set the current my location tracking mode.
* </p>
* <p>
* Will enable my location if not active.
* </p>
* See {@link MyLocationTracking} for different values.
*
* @param myLocationTrackingMode The location tracking mode to be used.
* @throws SecurityException if no suitable permission is present
* @see MyLocationTracking
*/
@UiThread
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
mMapView.setMyLocationTrackingMode(myLocationTrackingMode);
}
/**
* Returns the current user location tracking mode.
*
* @return The current user location tracking mode.
* One of the values from {@link MyLocationTracking.Mode}.
* @see MyLocationTracking.Mode
*/
@UiThread
@MyLocationTracking.Mode
public int getMyLocationTrackingMode() {
return mMapView.getMyLocationTrackingMode();
}
/**
* Sets a callback that's invoked when the location tracking mode changes.
*
@@ -1064,42 +1071,6 @@ public class MapboxMap {
return mOnMyLocationTrackingModeChangeListener;
}
/**
* <p>
* Set the current my bearing tracking mode.
* </p>
* Shows the direction the user is heading.
* <p>
* When location tracking is disabled the direction of {@link UserLocationView} is rotated
* When location tracking is enabled the {@link MapView} is rotated based on bearing value.
* </p>
* See {@link MyBearingTracking} for different values.
*
* @param myBearingTrackingMode The bearing tracking mode to be used.
* @throws SecurityException if no suitable permission is present
* @see MyBearingTracking
*/
@UiThread
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
mMapView.setMyBearingTrackingMode(myBearingTrackingMode);
}
/**
* Returns the current user bearing tracking mode.
* See {@link MyBearingTracking} for possible return values.
*
* @return the current user bearing tracking mode.
* @see MyBearingTracking
*/
@UiThread
@MyLocationTracking.Mode
public int getMyBearingTrackingMode() {
return mMapView.getMyBearingTrackingMode();
}
/**
* Sets a callback that's invoked when the bearing tracking mode changes.
*

View File

@@ -0,0 +1,117 @@
package com.mapbox.mapboxsdk.maps;
import android.Manifest;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import android.support.annotation.UiThread;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
public class TrackingSettings {
private MapView mapView;
private UiSettings uiSettings;
private boolean dismissTrackingOnGesture = true;
TrackingSettings(@NonNull MapView mapView, UiSettings uiSettings) {
this.mapView = mapView;
this.uiSettings = uiSettings;
}
/**
* <p>
* Set the current my location tracking mode.
* </p>
* <p>
* Will enable my location if not active.
* </p>
* See {@link MyLocationTracking} for different values.
*
* @param myLocationTrackingMode The location tracking mode to be used.
* @throws SecurityException if no suitable permission is present
* @see MyLocationTracking
*/
@UiThread
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
mapView.setMyLocationTrackingMode(myLocationTrackingMode);
validateGesturesForTrackingModes();
}
/**
* Returns the current user location tracking mode.
*
* @return The current user location tracking mode.
* One of the values from {@link MyLocationTracking.Mode}.
* @see MyLocationTracking.Mode
*/
@UiThread
@MyLocationTracking.Mode
public int getMyLocationTrackingMode() {
return mapView.getMyLocationTrackingMode();
}
/**
* <p>
* Set the current my bearing tracking mode.
* </p>
* Shows the direction the user is heading.
* <p>
* When location tracking is disabled the direction of {@link UserLocationView} is rotated
* When location tracking is enabled the {@link MapView} is rotated based on bearing value.
* </p>
* See {@link MyBearingTracking} for different values.
*
* @param myBearingTrackingMode The bearing tracking mode to be used.
* @throws SecurityException if no suitable permission is present
* @see MyBearingTracking
*/
@UiThread
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
mapView.setMyBearingTrackingMode(myBearingTrackingMode);
}
/**
* Returns the current user bearing tracking mode.
* See {@link MyBearingTracking} for possible return values.
*
* @return the current user bearing tracking mode.
* @see MyBearingTracking
*/
@UiThread
@MyLocationTracking.Mode
public int getMyBearingTrackingMode() {
return mapView.getMyBearingTrackingMode();
}
public boolean isDismissTrackingOnGesture() {
return dismissTrackingOnGesture;
}
public void setDismissTrackingOnGesture(boolean dismissTrackingOnGesture) {
this.dismissTrackingOnGesture = dismissTrackingOnGesture;
validateGesturesForTrackingModes();
}
private void validateGesturesForTrackingModes() {
if(!dismissTrackingOnGesture) {
int myLocationTrackingMode = getMyLocationTrackingMode();
int myBearingTrackingMode = getMyBearingTrackingMode();
// Enable/disable gestures based on tracking mode
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
uiSettings.setScrollGesturesEnabled(true);
uiSettings.setRotateGesturesEnabled(true);
} else {
uiSettings.setScrollGesturesEnabled(false);
uiSettings.setRotateGesturesEnabled((myBearingTrackingMode == MyBearingTracking.NONE));
}
}
}
}

View File

@@ -4,6 +4,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.view.Gravity;
import android.view.View;
import android.widget.VideoView;
/**
* Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings().
@@ -12,17 +13,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;
@@ -32,9 +25,9 @@ public class UiSettings {
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();
}
/**
@@ -49,8 +42,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 +52,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 +67,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 +77,7 @@ public class UiSettings {
* @return The gravity
*/
public int getCompassGravity() {
return compassGravity;
return compassSettings.getGravity();
}
/**
@@ -98,8 +91,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 +101,7 @@ public class UiSettings {
* @return The left margin in pixels
*/
public int getCompassMarginLeft() {
return compassMargins[0];
return compassSettings.getMargins()[0];
}
/**
@@ -117,7 +110,7 @@ public class UiSettings {
* @return The top margin in pixels
*/
public int getCompassMarginTop() {
return compassMargins[1];
return compassSettings.getMargins()[1];
}
/**
@@ -126,7 +119,7 @@ public class UiSettings {
* @return The right margin in pixels
*/
public int getCompassMarginRight() {
return compassMargins[2];
return compassSettings.getMargins()[2];
}
/**
@@ -135,7 +128,7 @@ public class UiSettings {
* @return The bottom margin in pixels
*/
public int getCompassMarginBottom() {
return compassMargins[3];
return compassSettings.getMargins()[3];
}
/**
@@ -147,8 +140,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 +150,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 +164,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 +174,7 @@ public class UiSettings {
* @return The gravity
*/
public int getLogoGravity() {
return logoGravity;
return logoSettings.getGravity();
}
/**
@@ -194,8 +187,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);
}
/**
@@ -204,7 +197,7 @@ public class UiSettings {
* @return The left margin in pixels
*/
public int getLogoMarginLeft(){
return logoMargins[0];
return logoSettings.getMargins()[0];
}
/**
@@ -213,7 +206,7 @@ public class UiSettings {
* @return The top margin in pixels
*/
public int getLogoMarginTop(){
return logoMargins[1];
return logoSettings.getMargins()[1];
}
/**
@@ -222,7 +215,7 @@ public class UiSettings {
* @return The right margin in pixels
*/
public int getLogoMarginRight(){
return logoMargins[2];
return logoSettings.getMargins()[2];
}
/**
@@ -231,7 +224,7 @@ public class UiSettings {
* @return The bottom margin in pixels
*/
public int getLogoMarginBottom(){
return logoMargins[3];
return logoSettings.getMargins()[3];
}
/**
@@ -243,8 +236,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 +246,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 +260,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 +270,7 @@ public class UiSettings {
* @return The gravity
*/
public int getAttributionGravity() {
return attributionGravity;
return attributionSettings.getGravity();
}
/**
@@ -290,8 +283,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);
}
/**
@@ -300,7 +293,7 @@ public class UiSettings {
* @return The left margin in pixels
*/
public int getAttributionMarginLeft(){
return attributionMargins[0];
return attributionSettings.getMargins()[0];
}
/**
@@ -309,7 +302,7 @@ public class UiSettings {
* @return The top margin in pixels
*/
public int getAttributionMarginTop(){
return attributionMargins[1];
return attributionSettings.getMargins()[1];
}
/**
@@ -318,7 +311,7 @@ public class UiSettings {
* @return The right margin in pixels
*/
public int getAttributionMarginRight(){
return attributionMargins[2];
return attributionSettings.getMargins()[2];
}
/**
@@ -327,7 +320,7 @@ public class UiSettings {
* @return The bottom margin in pixels
*/
public int getAttributionMarginBottom(){
return attributionMargins[3];
return attributionSettings.getMargins()[3];
}
/**
@@ -477,4 +470,10 @@ public class UiSettings {
setTiltGesturesEnabled(enabled);
setZoomGesturesEnabled(enabled);
}
public void invalidate(){
mapView.setLogoMargins(getLogoMarginLeft(), getLogoMarginTop(), getLogoMarginRight(), getLogoMarginBottom());
mapView.setCompassMargins(getCompassMarginLeft(),getCompassMarginTop(),getCompassMarginRight(),getCompassMarginBottom());
mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom());
}
}

View File

@@ -84,7 +84,6 @@ public final class UserLocationView extends View {
private LatLng mCurrentMapViewCoordinate;
private double mCurrentBearing;
private boolean mPaused = false;
private Location mUserLocation;
private UserLocationListener mUserLocationListener;
@@ -97,9 +96,9 @@ public final class UserLocationView extends View {
@MyBearingTracking.Mode
private int mMyBearingTrackingMode;
// Compass data
private MyBearingListener mBearingChangeListener;
private static final long BEARING_DURATION = 100;
public UserLocationView(Context context) {
super(context);
@@ -251,9 +250,8 @@ public final class UserLocationView extends View {
// center view directly
mMarkerScreenMatrix.reset();
mMarkerScreenMatrix.setTranslate(
getMeasuredWidth() / 2,
getMeasuredHeight() / 2);
mMarkerScreenPoint = getMarkerScreenPoint();
mMarkerScreenMatrix.setTranslate(mMarkerScreenPoint.x, mMarkerScreenPoint.y);
}
}
@@ -278,7 +276,7 @@ public final class UserLocationView extends View {
// compute new marker position
// TODO add JNI method that takes existing pointf
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
mMarkerScreenPoint = mMapView.toScreenLocation(mMarkerCoordinate);
mMarkerScreenPoint = getMarkerScreenPoint();
mMarkerScreenMatrix.reset();
mMarkerScreenMatrix.setTranslate(
mMarkerScreenPoint.x,
@@ -304,9 +302,8 @@ public final class UserLocationView extends View {
.build();
mMapView.getMapboxMap().animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMarkerScreenMatrix.reset();
mMarkerScreenMatrix.setTranslate(
getMeasuredWidth() / 2,
getMeasuredHeight() / 2);
mMarkerScreenPoint = getMarkerScreenPoint();
mMarkerScreenMatrix.setTranslate(mMarkerScreenPoint.x, mMarkerScreenPoint.y);
// set values for next check for actual change
mCurrentMapViewCoordinate = mMarkerCoordinate;
@@ -770,4 +767,13 @@ public final class UserLocationView extends View {
return mPaused;
}
public PointF getMarkerScreenPoint() {
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
mMarkerScreenPoint = mMapView.toScreenLocation(mMarkerCoordinate);
} else {
mMarkerScreenPoint = new PointF(((getMeasuredWidth() + mMapView.getContentPaddingLeft() - mMapView.getContentPaddingRight()) / 2)
, ((getMeasuredHeight() - mMapView.getContentPaddingBottom() + mMapView.getContentPaddingTop()) / 2));
}
return mMarkerScreenPoint;
}
}

View File

@@ -0,0 +1,36 @@
package com.mapbox.mapboxsdk.maps;
public class ViewSettings {
private boolean enabled;
private int gravity;
private int[]margins;
public ViewSettings() {
margins = new int[4];
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public int getGravity() {
return gravity;
}
public void setGravity(int gravity) {
this.gravity = gravity;
}
public int[] getMargins() {
return margins;
}
public void setMargins(int[] margins) {
this.margins = margins;
}
}