Merge remote-tracking branch 'origin/release-android-v4.1.0'

This commit is contained in:
John Firebaugh
2016-06-29 17:03:00 -07:00
56 changed files with 1853 additions and 250 deletions

View File

@@ -39,6 +39,22 @@ public abstract class BaseMarkerOptions<U extends Marker, T extends BaseMarkerOp
return getThis();
}
public T setIcon(Icon icon) {
return icon(icon);
}
public T setPosition(LatLng position) {
return position(position);
}
public T setSnippet(String snippet) {
return snippet(snippet);
}
public T setTitle(String title) {
return title(title);
}
public abstract T getThis();
public abstract U getMarker();

View File

@@ -29,6 +29,7 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
protected float rotation;
protected boolean visible = true;
protected boolean selected;
protected float alpha = 1.0f;
/**
* Default constructor
@@ -132,13 +133,24 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
* Set the visibility state of the MarkerView.
*
* @param visible the visible state
* @return the object for which the method was calleds
* @return the object for which the method was called
*/
public T visible(boolean visible) {
this.visible = visible;
return getThis();
}
/**
* Set the alpha of the MarkerView.
*
* @param alpha the alpha value
* @return the object for which the method was called
*/
public T alpha(float alpha) {
this.alpha = alpha;
return getThis();
}
/**
* Get the geographical location of the MarkerView.
*
@@ -238,6 +250,15 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
return visible;
}
/**
* Get the alpha of the MarkerView.
*
* @return the alpha value
*/
public float getAlpha() {
return alpha;
}
/**
* Get the instance of the object for which this method was called.
*

View File

@@ -33,6 +33,7 @@ public final class IconFactory {
private Context mContext;
private static IconFactory sInstance;
private Icon mDefaultMarker;
private Icon mDefaultMarkerView;
private BitmapFactory.Options mOptions;
private int mNextId = 0;
@@ -121,6 +122,13 @@ public final class IconFactory {
return mDefaultMarker;
}
public Icon defaultMarkerView() {
if (mDefaultMarkerView == null) {
mDefaultMarkerView = fromResource(R.drawable.default_markerview);
}
return mDefaultMarkerView;
}
private Icon fromInputStream(@NonNull InputStream is) {
Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions);
return fromBitmap(bitmap);

View File

@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.annotations;
import android.content.res.Resources;
import android.graphics.PointF;
import android.support.annotation.LayoutRes;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -222,9 +223,22 @@ public class InfoWindow {
}
mMapboxMap = new WeakReference<>(mapboxMap);
String title = overlayItem.getTitle();
((TextView) view.findViewById(R.id.infowindow_title)).setText(title);
TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title));
if (!TextUtils.isEmpty(title)) {
titleTextView.setText(title);
titleTextView.setVisibility(View.VISIBLE);
} else {
titleTextView.setVisibility(View.GONE);
}
String snippet = overlayItem.getSnippet();
((TextView) view.findViewById(R.id.infowindow_description)).setText(snippet);
TextView snippetTextView = ((TextView) view.findViewById(R.id.infowindow_description));
if (!TextUtils.isEmpty(snippet)) {
snippetTextView.setText(snippet);
snippetTextView.setVisibility(View.VISIBLE);
} else {
snippetTextView.setVisibility(View.GONE);
}
}
InfoWindow setBoundMarker(Marker boundMarker) {
@@ -245,11 +259,20 @@ public class InfoWindow {
View view = mView.get();
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset);
if (view instanceof InfoWindowView) {
view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset);
} else {
view.setX(mCoordinates.x - (view.getMeasuredWidth() / 2) - mMarkerWidthOffset);
}
view.setY(mCoordinates.y + mMarkerHeightOffset);
}
}
public View getView() {
return mView != null ? mView.get() : null;
}
boolean isVisible() {
return mIsVisible;
}

View File

@@ -117,6 +117,11 @@ public class Marker extends Annotation {
refreshInfoWindowContent();
}
@Nullable
public InfoWindow getInfoWindow() {
return infoWindow;
}
/**
* Update only for default Marker's InfoWindow content for Title and Snippet
*/

View File

@@ -1,13 +1,18 @@
package com.mapbox.mapboxsdk.annotations;
import android.animation.AnimatorSet;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.animation.AnimationUtils;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.utils.AnimatorUtils;
/**
* MarkerView is an annotation that shows an View at a geographical location.
@@ -26,8 +31,8 @@ public class MarkerView extends Marker {
private float anchorU;
private float anchorV;
private float offsetX;
private float offsetY;
private float offsetX = -1;
private float offsetY = -1;
private float infoWindowAnchorU;
private float infoWindowAnchorV;
@@ -81,6 +86,7 @@ public class MarkerView extends Marker {
public void setAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) {
this.anchorU = u;
this.anchorV = v;
setOffset(-1, -1);
}
/**
@@ -102,26 +108,16 @@ public class MarkerView extends Marker {
}
/**
* Internal method to set the horizontal calculated offset.
* Internal method to set the calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param x the x-value of the offset
*/
void setOffsetX(float x) {
offsetX = x;
}
/**
* Internal method to set the vertical calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param y the y-value of the offset
*/
void setOffsetY(float y) {
void setOffset(float x, float y) {
offsetX = x;
offsetY = y;
}
@@ -279,7 +275,7 @@ public class MarkerView extends Marker {
*
* @param alpha the alpha value to animate to
*/
public void setAlpha(@FloatRange(from=0.0, to=255.0)float alpha) {
public void setAlpha(@FloatRange(from = 0.0, to = 255.0) float alpha) {
this.alpha = alpha;
if (markerViewManager != null) {
markerViewManager.animateAlpha(this, alpha);
@@ -336,6 +332,12 @@ public class MarkerView extends Marker {
@Override
public void setMapboxMap(MapboxMap mapboxMap) {
super.setMapboxMap(mapboxMap);
if(isFlat()) {
// initial tilt value if MapboxMap is started with a tilt attribute
tiltValue = (float) mapboxMap.getCameraPosition().tilt;
}
markerViewManager = mapboxMap.getMarkerViewManager();
}

View File

@@ -5,10 +5,10 @@ import android.graphics.PointF;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pools;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
@@ -111,20 +111,20 @@ public class MarkerViewManager {
* </p>
*/
public void update() {
View convertView;
for (MarkerView marker : markerViewMap.keySet()) {
convertView = markerViewMap.get(marker);
for (final MarkerView marker : markerViewMap.keySet()) {
final View convertView = markerViewMap.get(marker);
if (convertView != null) {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
if (marker.getOffsetX() == -1) {
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
marker.setOffset(x, y);
}
marker.setOffsetX(x);
marker.setOffsetY(y);
convertView.setX(point.x - x);
convertView.setY(point.y - y);
convertView.setX(point.x - marker.getOffsetX());
convertView.setY(point.y - marker.getOffsetY());
// animate visibility
if (marker.isVisible() && convertView.getVisibility() == View.GONE) {
convertView.animate().cancel();
convertView.setAlpha(0);
@@ -200,9 +200,10 @@ public class MarkerViewManager {
* <p>
* The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onSelect(MarkerView, View, boolean)} will be called to execute an animation.
* </p>
* @param marker the MarkerView object to select
*
* @param marker the MarkerView object to select
* @param convertView the View presentation of the MarkerView
* @param adapter the adapter used to adapt the marker to the convertView
* @param adapter the adapter used to adapt the marker to the convertView
*/
public void select(@NonNull MarkerView marker, View convertView, MapboxMap.MarkerViewAdapter adapter) {
if (convertView != null) {
@@ -210,6 +211,7 @@ public class MarkerViewManager {
mapboxMap.selectMarker(marker);
}
marker.setSelected(true);
convertView.bringToFront();
}
}
@@ -244,6 +246,8 @@ public class MarkerViewManager {
for (final MapboxMap.MarkerViewAdapter<?> adapter : markerViewAdapters) {
if (adapter.getMarkerClass().equals(marker.getClass())) {
if (adapter.prepareViewForReuse(marker, viewHolder)) {
// reset offset for reuse
marker.setOffset(-1, -1);
adapter.releaseView(viewHolder);
}
}
@@ -355,7 +359,7 @@ public class MarkerViewManager {
adaptedView.setAlpha(marker.getAlpha());
// visible
adaptedView.setVisibility(marker.isVisible() ? View.VISIBLE : View.GONE);
adaptedView.setVisibility(View.GONE);
if (mapboxMap.getSelectedMarkers().contains(marker)) {
// if a marker to be shown was selected
@@ -374,11 +378,7 @@ public class MarkerViewManager {
}
if (!clickHandled) {
// InfoWindow offset
int infoWindowOffsetX = (int) ((adaptedView.getWidth() * marker.getInfoWindowAnchorU()) - marker.getOffsetX());
int infoWindowOffsetY = (int) ((adaptedView.getHeight() * marker.getInfoWindowAnchorV()) - marker.getOffsetY());
marker.setTopOffsetPixels(infoWindowOffsetY);
marker.setRightOffsetPixels(infoWindowOffsetX);
ensureInfoWindowOffset(marker);
select(marker, v, adapter);
}
}
@@ -386,7 +386,8 @@ public class MarkerViewManager {
markerViewMap.put(marker, adaptedView);
if (convertView == null) {
mapView.addView(adaptedView);
adaptedView.setVisibility(View.GONE);
mapView.getMarkerViewContainer().addView(adaptedView);
}
}
}
@@ -395,6 +396,42 @@ public class MarkerViewManager {
}
}
//TODO: This whole method is a stopgap for: https://github.com/mapbox/mapbox-gl-native/issues/5384
public void ensureInfoWindowOffset(MarkerView marker) {
View view = null;
if (markerViewMap.containsKey(marker)) {
view = markerViewMap.get(marker);
} else {
for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) {
if (adapter.getMarkerClass().equals(marker.getClass())) {
View convertView = (View) adapter.getViewReusePool().acquire();
view = adapter.getView(marker, convertView, mapView);
break;
}
}
}
if (view != null) {
//Ensure the marker's view is measured first
if (view.getMeasuredWidth() == 0) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
}
// update position on map
if (marker.getOffsetX() == -1) {
int x = (int) (marker.getAnchorU() * view.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * view.getMeasuredHeight());
marker.setOffset(x, y);
}
// InfoWindow offset
int infoWindowOffsetX = (int) ((view.getMeasuredWidth() * marker.getInfoWindowAnchorU()) - marker.getOffsetX());
int infoWindowOffsetY = (int) ((view.getMeasuredHeight() * marker.getInfoWindowAnchorV()) - marker.getOffsetY());
marker.setTopOffsetPixels(infoWindowOffsetY);
marker.setRightOffsetPixels(infoWindowOffsetX);
}
}
/**
* Default MarkerViewAdapter used for base class of MarkerView to adapt a MarkerView to an ImageView
*/

View File

@@ -30,6 +30,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
infoWindowAnchor(in.readFloat(), in.readFloat());
rotation(in.readFloat());
visible(in.readByte() != 0);
alpha(in.readFloat());
if (in.readByte() != 0) {
// this means we have an icon
String iconId = in.readString();
@@ -61,6 +62,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
out.writeFloat(getInfoWindowAnchorV());
out.writeFloat(getRotation());
out.writeByte((byte) (isVisible() ? 1 : 0));
out.writeFloat(alpha);
Icon icon = getIcon();
out.writeByte((byte) (icon != null ? 1 : 0));
if (icon != null) {
@@ -80,6 +82,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
marker.setInfoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV);
marker.setRotation(rotation);
marker.setVisible(visible);
marker.setAlpha(alpha);
return marker;
}

View File

@@ -48,6 +48,7 @@ import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
@@ -124,6 +125,7 @@ public class MapView extends FrameLayout {
private NativeMapView mNativeMapView;
private boolean mHasSurface = false;
private ViewGroup mMarkerViewContainer;
private CompassView mCompassView;
private ImageView mLogoView;
private ImageView mAttributionsView;
@@ -151,6 +153,8 @@ public class MapView extends FrameLayout {
private int mContentPaddingRight;
private int mContentPaddingBottom;
private PointF mFocalPoint;
private StyleInitializer mStyleInitializer;
private List<OnMapReadyCallback> mOnMapReadyCallbackList;
@@ -225,6 +229,8 @@ public class MapView extends FrameLayout {
// Connectivity
onConnectivityChanged(isConnected());
mMarkerViewContainer = (ViewGroup) view.findViewById(R.id.markerViewContainer);
mMyLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
mMyLocationView.setMapboxMap(mMapboxMap);
@@ -563,6 +569,18 @@ public class MapView extends FrameLayout {
}
}
void setFocalPoint(PointF focalPoint) {
if (focalPoint == null) {
// resetting focal point,
UiSettings uiSettings = mMapboxMap.getUiSettings();
// need to validate if we need to reset focal point with user provided one
if (uiSettings.getFocalPoint() != null) {
focalPoint = uiSettings.getFocalPoint();
}
}
mFocalPoint = focalPoint;
}
/**
* You must call this method from the parent's {@link Activity#onLowMemory()} or {@link Fragment#onLowMemory()}.
*/
@@ -1119,13 +1137,13 @@ public class MapView extends FrameLayout {
for (int i = 0; i < ids.length; i++) {
idsList.add(ids[i]);
}
List<MarkerView> annotations = new ArrayList<>(ids.length);
List<Annotation> annotationList = mMapboxMap.getAnnotations();
int count = annotationList.size();
for (int i = 0; i < count; i++) {
Annotation annotation = annotationList.get(i);
if (annotation instanceof MarkerView && idsList.contains(annotation.getId())) {
if (annotation instanceof MarkerView) {
annotations.add((MarkerView) annotation);
}
}
@@ -1133,6 +1151,13 @@ public class MapView extends FrameLayout {
return new ArrayList<>(annotations);
}
/**
* @return the ViewGroup containing the marker views
*/
public ViewGroup getMarkerViewContainer() {
return mMarkerViewContainer;
}
int getTopOffsetPixelsForIcon(Icon icon) {
if (mDestroyed) {
@@ -1371,7 +1396,6 @@ public class MapView extends FrameLayout {
if (mDestroyed) {
return;
}
mCompassView.update(getDirection());
mMyLocationView.update();
mMapboxMap.getMarkerViewManager().update();
@@ -1538,8 +1562,12 @@ public class MapView extends FrameLayout {
|| mShoveGestureDetector.isInProgress();
if (mTwoTap && isTap && !inProgress) {
PointF focalPoint = TwoFingerGestureDetector.determineFocalPoint(event);
zoom(false, focalPoint.x, focalPoint.y);
if (mFocalPoint != null) {
zoom(false, mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else {
PointF focalPoint = TwoFingerGestureDetector.determineFocalPoint(event);
zoom(false, focalPoint.x, focalPoint.y);
}
mTwoTap = false;
return true;
}
@@ -1598,12 +1626,12 @@ public class MapView extends FrameLayout {
}
// Single finger double tap
if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// User provided focal point
zoom(true, mFocalPoint.x, mFocalPoint.y);
} else {
// Zoom in on gesture
zoom(true, e.getX(), e.getY());
} else {
// Zoom in on user location view
zoom(true, mMyLocationView.getCenterX(), mMyLocationView.getCenterY());
}
break;
}
@@ -1678,8 +1706,10 @@ public class MapView extends FrameLayout {
}
}
} else {
// deselect any selected marker
mMapboxMap.deselectMarkers();
if (mMapboxMap.getUiSettings().isDeselectMarkersOnTap()) {
// deselect any selected marker
mMapboxMap.deselectMarkers();
}
// notify app of map click
MapboxMap.OnMapClickListener listener = mMapboxMap.getOnMapClickListener();
@@ -1835,23 +1865,18 @@ public class MapView extends FrameLayout {
// Gesture is a quickzoom if there aren't two fingers
mQuickZoom = !mTwoTap;
TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
// Scale the map
if (uiSettings.isScrollGesturesEnabled() && !mQuickZoom && trackingSettings.isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// arround user provided focal point
mNativeMapView.scaleBy(detector.getScaleFactor(), mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else if (mQuickZoom) {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
} else {
// around gesture
mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity);
} else {
if (trackingSettings.isLocationTrackingDisabled()) {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
} else {
// around user location view
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
mNativeMapView.scaleBy(detector.getScaleFactor(), x / mScreenDensity, y / mScreenDensity);
}
}
return true;
}
}
@@ -1925,16 +1950,14 @@ public class MapView extends FrameLayout {
bearing += detector.getRotationDegreesDelta();
// Rotate the map
if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// User provided focal point
mNativeMapView.setBearing(bearing, mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else {
// around gesture
mNativeMapView.setBearing(bearing,
detector.getFocusX() / mScreenDensity,
detector.getFocusY() / mScreenDensity);
} else {
// around center userlocation
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
mNativeMapView.setBearing(bearing, x / mScreenDensity, y / mScreenDensity);
}
return true;
}
@@ -2429,6 +2452,13 @@ public class MapView extends FrameLayout {
mMapboxMap.setMyLocationEnabled(true);
}
mMyLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
setFocalPoint(new PointF(mMyLocationView.getCenterX(), mMyLocationView.getCenterY()));
} else {
setFocalPoint(null);
}
MapboxMap.OnMyLocationTrackingModeChangeListener listener = mMapboxMap.getOnMyLocationTrackingModeChangeListener();
if (listener != null) {
listener.onMyLocationTrackingModeChange(myLocationTrackingMode);

View File

@@ -20,6 +20,7 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.InfoWindow;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
@@ -38,7 +39,6 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.location.LocationListener;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import java.lang.reflect.ParameterizedType;
@@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit;
* you must obtain one from the getMapAsync() method on a MapFragment or MapView that you have
* added to your application.
* <p>
* Note: Similar to a View object, a GoogleMap should only be read and modified from the main thread.
* Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.
* </p>
*/
public class MapboxMap {
@@ -1142,6 +1142,11 @@ public class MapboxMap {
}
if (!handledDefaultClick) {
if (marker instanceof MarkerView) {
mMarkerViewManager.ensureInfoWindowOffset((MarkerView) marker);
}
if (isInfoWindowValidForMarker(marker) || getInfoWindowAdapter() != null) {
mInfoWindows.add(marker.showInfoWindow(this, mMapView));
}
@@ -1208,7 +1213,12 @@ public class MapboxMap {
private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
MarkerView marker = markerViewOptions.getMarker();
marker.setIcon(markerViewOptions.getIcon());
Icon icon = markerViewOptions.getIcon();
if (icon == null) {
icon = IconFactory.getInstance(mMapView.getContext()).defaultMarkerView();
}
marker.setIcon(icon);
return marker;
}
@@ -1533,10 +1543,8 @@ public class MapboxMap {
*
* @param listener The callback that's invoked when the user clicks on a marker.
* To unset the callback, use null.
* @deprecated As of release 4.1.0, replaced by {@link com.mapbox.mapboxsdk.location.LocationServices#addLocationListener(LocationListener)})}
*/
@UiThread
@Deprecated
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
mMapView.setOnMyLocationChangeListener(listener);
}
@@ -1945,9 +1953,7 @@ public class MapboxMap {
* Interface definition for a callback to be invoked when the the My Location view changes location.
*
* @see MapboxMap#setOnMyLocationChangeListener(OnMyLocationChangeListener)
* @deprecated As of release 4.1.0, replaced by {@link com.mapbox.mapboxsdk.location.LocationListener}
*/
@Deprecated
public interface OnMyLocationChangeListener {
/**
* Called when the location of the My Location view has changed

View File

@@ -101,7 +101,7 @@ public class TrackingSettings {
*
* @return True to indicate the tracking modes will be dismissed.
* @deprecated use @link #isAllDismissTrackingOnGestureinstead
*/
*/
@Deprecated
public boolean isDismissTrackingOnGesture() {
return dismissLocationTrackingOnGesture && dismissBearingTrackingOnGesture;
@@ -215,7 +215,7 @@ public class TrackingSettings {
private void validateGesturesForBearingTrackingMode() {
int myBearingTrackingMode = getMyBearingTrackingMode();
if (!dismissBearingTrackingOnGesture) {
if (myBearingTrackingMode == MyBearingTracking.NONE) {
if (myBearingTrackingMode == MyBearingTracking.NONE || myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
uiSettings.setRotateGesturesEnabled(true);
} else {
uiSettings.setRotateGesturesEnabled(false);

View File

@@ -1,7 +1,9 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.view.Gravity;
import android.view.View;
@@ -33,6 +35,10 @@ public class UiSettings {
private boolean zoomControlsEnabled;
private boolean deselectMarkersOnTap = true;
private PointF focalPoint;
UiSettings(@NonNull MapView mapView) {
this.mapView = mapView;
this.compassSettings = new ViewSettings();
@@ -483,6 +489,26 @@ public class UiSettings {
return zoomControlsEnabled;
}
/**
* Gets whether the markers are automatically deselected (and therefore, their infowindows
* closed) when a map tap is detected.
* @return If true, markers are deselected on a map tap.
*/
public boolean isDeselectMarkersOnTap() {
return deselectMarkersOnTap;
}
/**
* Sets whether the markers are automatically deselected (and therefore, their infowindows
* closed) when a map tap is detected.
*
* @param deselectMarkersOnTap
*/
public void setDeselectMarkersOnTap(boolean deselectMarkersOnTap) {
this.deselectMarkersOnTap = deselectMarkersOnTap;
}
/**
* <p>
* Changes whether the user may scroll around the map.
@@ -541,6 +567,25 @@ public class UiSettings {
setZoomGesturesEnabled(enabled);
}
/**
* Sets the focal point used as center for a gesture
*
* @param focalPoint the focal point to be used.
*/
public void setFocalPoint(@Nullable PointF focalPoint) {
this.focalPoint = focalPoint;
mapView.setFocalPoint(focalPoint);
}
/**
* Returns the gesture focal point
*
* @return The focal point
*/
public PointF getFocalPoint() {
return focalPoint;
}
/**
* Returns the measured height of the MapView
*

View File

@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.maps.widgets;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Camera;
@@ -28,7 +27,6 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
@@ -67,6 +65,14 @@ public class MyLocationView extends View {
private ValueAnimator accuracyAnimator;
private ValueAnimator directionAnimator;
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidate();
}
};
private Drawable foregroundDrawable;
private Drawable foregroundBearingDrawable;
private Drawable backgroundDrawable;
@@ -260,8 +266,8 @@ public class MyLocationView extends View {
camera.getMatrix(matrix);
//
if (myBearingTrackingMode != MyBearingTracking.NONE) {
matrix.postRotate((Float) directionAnimator.getAnimatedValue());
if (myBearingTrackingMode != MyBearingTracking.NONE && directionAnimator != null) {
matrix.preRotate((Float) directionAnimator.getAnimatedValue());
}
// put matrix at location of MyLocationView
@@ -295,10 +301,6 @@ public class MyLocationView extends View {
this.tilt = (float) tilt;
}
void updateOnNextFrame() {
mapboxMap.invalidate();
}
public void onPause() {
compassListener.onPause();
toggleGps(false);
@@ -444,6 +446,7 @@ public class MyLocationView extends View {
directionAnimator = ValueAnimator.ofFloat(oldDir, newDir);
directionAnimator.setDuration(375);
directionAnimator.addUpdateListener(invalidateSelfOnUpdateListener);
directionAnimator.start();
}
@@ -526,24 +529,19 @@ public class MyLocationView extends View {
return;
}
long currentTime = SystemClock.elapsedRealtime();
if (currentTime < mCompassUpdateNextTimestamp) {
return;
}
int type = event.sensor.getType();
float[] data;
if (type == Sensor.TYPE_ACCELEROMETER) {
data = mGData;
System.arraycopy(event.values, 0, mGData, 0, 3);
} else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
data = mMData;
System.arraycopy(event.values, 0, mMData, 0, 3);
} else {
// we should not be here.
return;
}
for (int i = 0; i < 3; i++) {
data[i] = event.values[i];
long currentTime = SystemClock.elapsedRealtime();
if (currentTime < mCompassUpdateNextTimestamp) {
return;
}
SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
@@ -587,7 +585,7 @@ public class MyLocationView extends View {
double latitude = fromLat + (toLat - fromLat) * frac;
double longitude = fromLng + (toLng - fromLng) * frac;
behavior.updateLatLng(latitude, longitude);
updateOnNextFrame();
update();
}
}

View File

@@ -313,6 +313,16 @@ public class MapboxEventManager {
* @param location Location event
*/
public void addLocationEvent(Location location) {
// NaN and Infinite checks to prevent JSON errors at send to server time
if (Double.isNaN(location.getLatitude()) || Double.isNaN(location.getLongitude()) || Double.isNaN(location.getAltitude())) {
return;
}
if (Double.isInfinite(location.getLatitude()) || Double.isInfinite(location.getLongitude()) || Double.isInfinite(location.getAltitude())) {
return;
}
// Add Location even to queue
Hashtable<String, Object> event = new Hashtable<>();
event.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_LOCATION);