summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-02-10 12:29:13 +0100
committerTobrun <tobrun@mapbox.com>2016-02-15 12:25:18 +0100
commit1b7ebca2792f79de8c5309fb3e1dda3c96bf1e54 (patch)
tree2183f85518e89dae31c6bc5bf6939c842fbb0e1d /platform
parent7d6ac6adfc2c898ba65d05d25c06693ce5eedd20 (diff)
downloadqtlocation-mapboxgl-1b7ebca2792f79de8c5309fb3e1dda3c96bf1e54.tar.gz
[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
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java174
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java111
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java117
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java99
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java24
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java36
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java7
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java162
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_map_padding.xml9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_padding.xml49
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml7
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_padding.xml12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml2
17 files changed, 633 insertions, 208 deletions
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 36478dce3e..43c228fd25 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
@@ -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();
@@ -649,6 +647,46 @@ public class MapView extends FrameLayout {
}
//
+ // 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.
@@ -1373,6 +1366,35 @@ public class MapView extends FrameLayout {
}
/**
+ * 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.
* </p>
@@ -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);
}
+
}
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 ce2f1e8981..e252cad5b7 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
@@ -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<>();
@@ -87,6 +89,19 @@ public class MapboxMap {
}
//
+ // TrackingSettings
+ //
+
+ /**
+ * Gets the tracking interface settings for the map.
+ *
+ * @return
+ */
+ public TrackingSettings getTrackingSettings(){
+ return mTrackingSettings;
+ }
+
+ //
// Projection
//
@@ -796,6 +811,32 @@ public class MapboxMap {
}
//
+ // 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
//
@@ -1015,40 +1056,6 @@ public class MapboxMap {
}
/**
- * <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.
*
* @param listener The callback that's invoked when the location tracking mode changes.
@@ -1065,42 +1072,6 @@ public class MapboxMap {
}
/**
- * <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.
*
* @param listener The callback that's invoked when the bearing tracking mode changes.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
new file mode 100644
index 0000000000..57faefb92e
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -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));
+ }
+ }
+ }
+}
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..ede6217a47 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
@@ -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());
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
index 9f8261a0a7..70976dde7c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
@@ -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;
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java
new file mode 100644
index 0000000000..a192a1b576
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java
@@ -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;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index 7b4af726cb..4b44efdfe5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -89,6 +89,10 @@
<activity
android:name=".DynamicMarkerChangeActivity"
android:label="@string/activity_dynamic_marker" />
+ <activity
+ android:name=".MapPaddingActivity"
+ android:screenOrientation="portrait"
+ android:label="@string/activity_map_padding" />
<meta-data
android:name="com.mapbox.AccessToken"
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 9bf168ee75..168979a9f5 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.TrackingSettings;
import com.mapbox.mapboxsdk.maps.UiSettings;
public class DoubleMapActivity extends AppCompatActivity {
@@ -72,7 +73,8 @@ public class DoubleMapActivity extends AppCompatActivity {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
try {
- mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ TrackingSettings settings = mapboxMap.getTrackingSettings();
+ settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
} catch (SecurityException e) {
// permission is handled in MainActivity
getActivity().finish();
@@ -96,7 +98,8 @@ public class DoubleMapActivity extends AppCompatActivity {
uiSettings.setLogoEnabled(false);
try {
- mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ TrackingSettings settings = mapboxMap.getTrackingSettings();
+ settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
}catch (SecurityException e){
// permission is handled in MainActivity
getActivity().finish();
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 a7b1d0270c..91fcb8f5c5 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.TrackingSettings;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
@@ -466,6 +467,10 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_dynamic_marker:
startActivity(new Intent(getApplicationContext(), DynamicMarkerChangeActivity.class));
return true;
+
+ case R.id.action_map_padding:
+ startActivity(new Intent(getApplicationContext(),MapPaddingActivity.class));
+ return true;
default:
return changeMapStyle(menuItem.getItemId());
@@ -551,8 +556,11 @@ public class MainActivity extends AppCompatActivity {
}
});
mMapboxMap.setMyLocationEnabled(true);
- mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
- mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
+
+ TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
+ trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
+ trackingSettings.setMyBearingTrackingMode(MyBearingTracking.GPS);
+
mLocationFAB.setColorFilter(ContextCompat.getColor(this, R.color.primary));
}
} else {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java
new file mode 100644
index 0000000000..50b235433b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapPaddingActivity.java
@@ -0,0 +1,162 @@
+package com.mapbox.mapboxsdk.testapp;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.constants.MyLocationTracking;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.maps.TrackingSettings;
+import com.mapbox.mapboxsdk.utils.ApiAccess;
+
+public class MapPaddingActivity extends AppCompatActivity {
+
+ private MapView mMapView;
+ private MapboxMap mMapboxMap;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_map_padding);
+
+ final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
+ }
+
+ mMapView = (MapView) findViewById(R.id.mapView);
+ mMapView.setTag(true);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mapboxMap.setStyle(Style.MAPBOX_STREETS);
+
+ moveToBangalore();
+
+ int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left);
+ int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom);
+ int paddingRight = (int) getResources().getDimension(R.dimen.map_padding_right);
+ mapboxMap.setPadding(paddingLeft, toolbar.getHeight(), paddingRight, paddingBottom);
+ }
+ });
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mMapView.onStart();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mMapView.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mMapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mMapView.onStop();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mMapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mMapView.onDestroy();
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mMapView.onLowMemory();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_padding, menu);
+ return true;
+ }
+
+ private void toggleGps(boolean enable) {
+ try {
+ // Enable user location
+ mMapboxMap.setMyLocationEnabled(enable);
+
+ TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
+ trackingSettings.setDismissTrackingOnGesture(false);
+ trackingSettings.setMyLocationTrackingMode(enable ? MyLocationTracking.TRACKING_FOLLOW : MyLocationTracking.TRACKING_NONE);
+ } catch (SecurityException e) {
+ // permission not granted is handled in MainActivity
+ finish();
+ }
+ }
+
+ private void moveToBangalore() {
+ toggleGps(false);
+ LatLng bangalore = new LatLng(12.9810816, 77.6368034);
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder()
+ .zoom(16)
+ .target(bangalore)
+ .bearing(40)
+ .tilt(45)
+ .build()));
+ mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+
+ case R.id.action_user_tracking:
+ if (mMapboxMap != null) {
+ toggleGps(true);
+ }
+ return true;
+
+ case R.id.action_bangalore:
+ if (mMapboxMap != null) {
+ moveToBangalore();
+ }
+ return true;
+
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+}
+
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
index 1f30a4f0ea..ab421c71dd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
@@ -21,6 +21,7 @@ import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -135,28 +136,29 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) throws SecurityException {
+ TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
if (parent.getId() == R.id.spinner_location) {
switch (position) {
case 0:
- mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
+ trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
break;
case 1:
- mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
break;
}
} else if (parent.getId() == R.id.spinner_bearing) {
switch (position) {
case 0:
- mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.NONE);
+ trackingSettings.setMyBearingTrackingMode(MyBearingTracking.NONE);
break;
case 1:
- mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
+ trackingSettings.setMyBearingTrackingMode(MyBearingTracking.GPS);
break;
case 2:
- mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
+ trackingSettings.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
break;
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_map_padding.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_map_padding.xml
new file mode 100644
index 0000000000..60b75a5493
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_map_padding.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M19,19H5V5h7V3H5c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2v-7h-2v7zM14,3v2h3.59l-9.83,9.83 1.41,1.41L19,6.41V10h2V3h-7z"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_padding.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_padding.xml
new file mode 100644
index 0000000000..aa3c50d65c
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_padding.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <View
+ android:layout_width="@dimen/map_padding_left"
+ android:layout_height="match_parent"
+ android:layout_marginTop="?attr/actionBarSize"
+ android:alpha="0.5"
+ android:background="@color/mapbox_blue" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/map_padding_bottom"
+ android:layout_gravity="bottom"
+ android:layout_marginEnd="@dimen/map_padding_right"
+ android:layout_marginLeft="@dimen/map_padding_left"
+ android:layout_marginRight="@dimen/map_padding_right"
+ android:layout_marginStart="@dimen/map_padding_left"
+ android:alpha="0.5"
+ android:background="@color/mapbox_blue" />
+
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:alpha="0.5"
+ android:background="@color/primary"
+ android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
+
+ <View
+ android:layout_width="@dimen/map_padding_right"
+ android:layout_height="match_parent"
+ android:layout_gravity="end"
+ android:layout_marginLeft="@dimen/map_padding_left"
+ android:layout_marginStart="@dimen/map_padding_left"
+ android:alpha="0.5"
+ android:layout_marginTop="?attr/actionBarSize"
+ android:background="@color/mapbox_blue" />
+
+</FrameLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
index 5b2f0f1d53..512d195593 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
@@ -198,7 +198,12 @@
android:icon="@drawable/ic_dynamic_marker"
android:title="@string/action_dynamic_marker" />
+ <item
+ android:id="@+id/action_map_padding"
+ android:checkable="false"
+ android:icon="@drawable/ic_map_padding"
+ android:title="@string/action_map_padding" />
+
</menu>
</item>
-
</menu>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_padding.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_padding.xml
new file mode 100644
index 0000000000..0db887c4e7
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_padding.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:mapbox="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_user_tracking"
+ android:title="My Location Tracking"
+ mapbox:showAsAction="never" />
+ <item
+ android:id="@+id/action_bangalore"
+ android:title="Bangalore"
+ mapbox:showAsAction="never" />
+</menu> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
index 87cfebffd6..c852ed0e7a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
@@ -3,4 +3,8 @@
<dimen name="fab_margin">16dp</dimen>
<dimen name="attr_margin">10dp</dimen>
<dimen name="coordinatebounds_margin">32dp</dimen>
+ <dimen name="map_padding_left">96dp</dimen>
+ <dimen name="map_padding_bottom">256dp</dimen>
+ <dimen name="map_padding_right">32dp</dimen>
+
</resources>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
index f0b87ddbbc..ea346674b5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
@@ -26,6 +26,7 @@
<string name="activity_double_map">Double Map Activity</string>
<string name="activity_scroll_by">Scroll By Activity</string>
<string name="activity_dynamic_marker">Dynamic Marker Activity</string>
+ <string name="activity_map_padding">Map Padding Activity</string>
<string name="navdrawer_menu_title_mainactivity_controls">Main Activity Controls</string>
<string name="navdrawer_menu_title_mainactivity_styles">Main Activity Styles</string>
@@ -54,6 +55,7 @@
<string name="action_remove_polylines">Remove polylines</string>
<string name="action_double_mapview">Double MapView</string>
<string name="action_dynamic_marker">Dynamic Marker</string>
+ <string name="action_map_padding">Map Padding</string>
<string name="button_camera_move">Move</string>
<string name="button_camera_ease">Ease</string>