Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #3781 #3899 - add map padding, user location view, ViewSett…
Browse files Browse the repository at this point in the history
…ings, TrackingSettings
  • Loading branch information
tobrun committed Feb 11, 2016
1 parent 7661f0a commit ee960ec
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public class MapView extends FrameLayout {
private int mContentPaddingRight;
private int mContentPaddingBottom;


@UiThread
public MapView(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -357,9 +356,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}

//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));
}

// Force a check for an access token
Expand Down Expand Up @@ -397,8 +396,8 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
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();
Expand Down Expand Up @@ -631,6 +630,46 @@ void resetNorth() {
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
//
Expand All @@ -646,51 +685,6 @@ void resetNorth() {
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.
Expand Down Expand Up @@ -1492,6 +1486,10 @@ protected void onSizeChanged(int width, int height, int oldw, int oldh) {
return mNativeMapView.getScale();
}

public void setUserLocationPadding(int left, int top, int right, int bottom) {
mUserLocationView.setContentPadding(new int[]{left, top, right, bottom});
}

// This class handles TextureView callbacks
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {

Expand Down Expand Up @@ -1799,7 +1797,9 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}

// reset tracking modes if gesture occurs
resetTrackingModes();
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
resetTrackingModes();
}

// Fling the map
float ease = 0.25f;
Expand Down Expand Up @@ -1831,8 +1831,10 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
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();
Expand Down Expand Up @@ -1862,8 +1864,10 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
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;
Expand Down Expand Up @@ -1935,8 +1939,10 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
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;
Expand Down Expand Up @@ -2014,8 +2020,10 @@ public boolean onShoveBegin(ShoveGestureDetector detector) {
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;
Expand Down Expand Up @@ -2834,6 +2842,10 @@ private void setWidgetGravity(@NonNull final View view, int gravity) {

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class MapboxMap {
mMapView = mapView;
mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener());
mUiSettings = new UiSettings(mapView);
mTrackingSettings = new TrackingSettings(mapView);
mProjection = new Projection(mapView);
mSelectedMarkers = new ArrayList<>();
mInfoWindows = new ArrayList<>();
Expand All @@ -86,6 +88,19 @@ public UiSettings getUiSettings() {
return mUiSettings;
}

//
// TrackingSettings
//

/**
* Gets the tracking interface settings for the map.
*
* @return
*/
public TrackingSettings getTrackingSettings(){
return mTrackingSettings;
}

//
// Projection
//
Expand Down Expand Up @@ -804,7 +819,11 @@ private boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
*/
public void setPadding(int left, int top, int right, int bottom) {
mMapView.setContentPadding(left, top, right, bottom);
mUiSettings.invalidate();
}

public void setUserLocationPadding(int left, int top, int right, int bottom){
mMapView.setUserLocationPadding(left, top, right, bottom);
}

//
Expand Down Expand Up @@ -1026,40 +1045,6 @@ public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChange
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.
*
Expand All @@ -1076,42 +1061,6 @@ MapboxMap.OnMyLocationTrackingModeChangeListener getOnMyLocationTrackingModeChan
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.
*
Expand Down
Loading

0 comments on commit ee960ec

Please sign in to comment.