diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
24 files changed, 325 insertions, 192 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index 55beb8dea8..c194a8c34c 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -25,7 +25,7 @@ dependencies { compile "com.android.support:support-annotations:${supportLibVersion}" compile "com.android.support:support-v4:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" - compile 'com.squareup.okhttp3:okhttp:3.0.0' + compile 'com.squareup.okhttp3:okhttp:3.0.1' compile 'com.mapzen.android:lost:1.0.1' } diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index 8b50b5b17a..bd2d4f3859 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=3.1.0-SNAPSHOT +VERSION_NAME=3.1.0 POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java index 98d0f79656..5725989964 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java @@ -10,6 +10,20 @@ import android.view.ViewGroup; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.views.MapView; +/** + * Fragment wrapper around a {@link MapView}. + * <p> + * A Map component in an app. This fragment is the simplest way to place a map in an application. + * It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. + * Being a fragment, this component can be added to an activity's layout or can dynamically be added + * using a FragmentManager. + * </p> + * <p> + * To get a reference to the MapView, use {@link #getMap()} + * </p> + * + * @see #getMap() + */ public class MapFragment extends Fragment { // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java index bf89998788..813e489e94 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java @@ -5,10 +5,12 @@ import android.support.annotation.NonNull; import com.mapbox.mapboxsdk.views.MapView; /** - * Annotation is the most general kind of overlay on top of a map, - * from which {@link InfoWindow} and {@link Marker} are derived: it manages - * attachment to a map and identification, but does not require + * Annotation is a overlay on top of a {@link MapView}, + * from which {@link Polygon}, {@link Polyline} and {@link Marker} are derived. + * <p> + * it manages attachment to a map and identification, but does not require * content to be placed at a geographical point. + * </p> */ public abstract class Annotation implements Comparable<Annotation> { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java index d7e28dde73..b9691914e2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java @@ -2,6 +2,10 @@ package com.mapbox.mapboxsdk.annotations; import android.graphics.Bitmap; +/** + * Icon is the visual representation of a {@link Marker} on a {@link com.mapbox.mapboxsdk.views.MapView}. + * @see Marker + */ public final class Icon { private Bitmap mBitmap; private String mId; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java index 8d58866acd..bee4ec47c5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java @@ -22,6 +22,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +/** + * Factory for creating {@link Icon} objects. + * @see Icon + */ public final class IconFactory { private static final String ICON_ID_PREFIX = "com.mapbox.icons.icon_"; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index c74cf478d1..696301cf54 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -1,8 +1,8 @@ package com.mapbox.mapboxsdk.annotations; -import android.content.Context; import android.content.res.Resources; import android.graphics.PointF; +import android.support.annotation.LayoutRes; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -17,32 +17,29 @@ import java.lang.ref.WeakReference; /** * <p> - * A tooltip view. This is a UI element placed over a map at a specific geographic - * location. + * InfoWindow is a tooltip shown when a {@link Marker} is tapped. + * </p> + * <p> + * This is a UI element placed over a map at a specific geographic location. * </p> */ public class InfoWindow { private WeakReference<Marker> mBoundMarker; private WeakReference<MapView> mMapView; + protected WeakReference<View> mView; + private float mMarkerHeightOffset; private float mViewWidthOffset; private PointF mCoordinates; private boolean mIsVisible; - protected WeakReference<View> mView; - static int mTitleId = 0; - static int mDescriptionId = 0; - static int mSubDescriptionId = 0; - static int mImageId = 0; + @LayoutRes + private int mLayoutRes; InfoWindow(int layoutResId, MapView mapView) { + mLayoutRes = layoutResId; View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false); - - if (mTitleId == 0) { - setResIds(mapView.getContext()); - } - initialize(view, mapView); } @@ -86,7 +83,7 @@ public class InfoWindow { * This allows to offset the view from the object position. * @return this infowindow */ - InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) { + InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offsetX, int offsetY) { setBoundMarker(boundMarker); MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT); @@ -99,21 +96,21 @@ public class InfoWindow { mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY; // Calculate default Android x,y coordinate - mCoordinates = mMapView.get().toScreenLocation(position); + mCoordinates = mapView.toScreenLocation(position); float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX; float y = mCoordinates.y - view.getMeasuredHeight() + offsetY; if (view instanceof InfoWindowView) { // only apply repositioning/margin for InfoWindowView - Resources resources = mMapView.get().getContext().getResources(); + Resources resources = mapView.getContext().getResources(); // get right/left popup window float rightSideInfowWindow = x + view.getMeasuredWidth(); float leftSideInfoWindow = x; // get right/left map view - final float mapRight = mMapView.get().getRight(); - final float mapLeft = mMapView.get().getLeft(); + final float mapRight = mapView.getRight(); + final float mapLeft = mapView.getLeft(); float marginHorizontal = resources.getDimension(R.dimen.infowindow_margin); float tipViewOffset = resources.getDimension(R.dimen.infowindow_tipview_width) / 2; @@ -164,7 +161,7 @@ public class InfoWindow { mViewWidthOffset = x - mCoordinates.x - offsetX; close(); //if it was already opened - mMapView.get().addView(view, lp); + mapView.addView(view, lp); mIsVisible = true; } return this; @@ -194,25 +191,17 @@ public class InfoWindow { * * @param overlayItem the tapped overlay item */ - void adaptDefaultMarker(Marker overlayItem) { + void adaptDefaultMarker(Marker overlayItem, MapView mapView) { View view = mView.get(); - if (view != null) { - String title = overlayItem.getTitle(); - ((TextView) view.findViewById(mTitleId /*R.id.title*/)).setText(title); - String snippet = overlayItem.getSnippet(); - ((TextView) view.findViewById(mDescriptionId /*R.id.description*/)).setText(snippet); - } -/* - //handle sub-description, hiding or showing the text view: - TextView subDescText = (TextView) mView.findViewById(mSubDescriptionId); - String subDesc = overlayItem.getSubDescription(); - if ("".equals(subDesc)) { - subDescText.setVisibility(View.GONE); - } else { - subDescText.setText(subDesc); - subDescText.setVisibility(View.VISIBLE); + if (view == null) { + view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false); + initialize(view, mapView); } -*/ + mMapView = new WeakReference<>(mapView); + String title = overlayItem.getTitle(); + ((TextView) view.findViewById(R.id.infowindow_title)).setText(title); + String snippet = overlayItem.getSnippet(); + ((TextView) view.findViewById(R.id.infowindow_description)).setText(snippet); } private void onClose() { @@ -231,22 +220,6 @@ public class InfoWindow { return mBoundMarker.get(); } - /** - * Given a context, set the resource ids for the layout - * of the InfoWindow. - * - * @param context the apps Context - */ - private static void setResIds(Context context) { - String packageName = context.getPackageName(); //get application package name - mTitleId = context.getResources().getIdentifier("id/infowindow_title", null, packageName); - mDescriptionId = - context.getResources().getIdentifier("id/infowindow_description", null, packageName); - mSubDescriptionId = context.getResources() - .getIdentifier("id/infowindow_subdescription", null, packageName); - mImageId = context.getResources().getIdentifier("id/infowindow_image", null, packageName); - } - public void update() { MapView mapView = mMapView.get(); Marker marker = mBoundMarker.get(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java index 8978d4be48..3463801448 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.annotations; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; @@ -8,9 +9,10 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.views.MapView; /** - * A marker is a map overlay that shows an icon image at a specific - * geographical location and can be associated with a {@link InfoWindow} - * that is shown when the marker is tapped. + * Marker is an annotation that shows an icon image at a geographical location. + * </p> + * An {@link InfoWindow} can be shown when a Marker is pressed + * <p> */ public final class Marker extends Annotation { @@ -53,6 +55,8 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. + * + * @return boolean State of a InfoWindow */ public boolean isInfoWindowShown() { return infoWindowShown; @@ -68,6 +72,8 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. + * + * @param icon The icon to be used as Marker image */ public void setIcon(@Nullable Icon icon) { this.icon = icon; @@ -83,29 +89,29 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. + * + * @param mapView The MapView to show the InfoWindow on. + * @return infoWindow The infoWindow to show */ - public InfoWindow showInfoWindow() { - if (getMapView() == null) { - return null; - } - + public InfoWindow showInfoWindow(@NonNull MapView mapView) { + setMapView(mapView); MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter(); if (infoWindowAdapter != null) { // end developer is using a custom InfoWindowAdapter View content = infoWindowAdapter.getInfoWindow(this); if (content != null) { infoWindow = new InfoWindow(content, getMapView()); - showInfoWindow(infoWindow); + showInfoWindow(infoWindow, mapView); return infoWindow; } } - getInfoWindow().adaptDefaultMarker(this); - return showInfoWindow(getInfoWindow()); + getInfoWindow().adaptDefaultMarker(this, mapView); + return showInfoWindow(getInfoWindow(), mapView); } - private InfoWindow showInfoWindow(InfoWindow iw) { - iw.open(this, getPosition(), 0, topOffsetPixels); + private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) { + iw.open(mapView, this, getPosition(), 0, topOffsetPixels); infoWindowShown = true; return iw; } @@ -129,6 +135,8 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. + * + * @param topOffsetPixels the pixels to have as offset */ public void setTopOffsetPixels(int topOffsetPixels) { this.topOffsetPixels = topOffsetPixels; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java index 69e8b03bda..a83a6991b2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java @@ -10,9 +10,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng; /** * <p> - * A builder object for the options configuration {@link com.mapbox.mapboxsdk.annotations.Marker} and - * {@link com.mapbox.mapboxsdk.annotations.InfoWindow} - * instances on maps. + * Builder for composing {@link com.mapbox.mapboxsdk.annotations.Marker} objects. * </p> * * <h3>Example</h3> @@ -70,6 +68,8 @@ public final class MarkerOptions implements Parcelable { /** * Do not use this method. Used internally by the SDK. + * + * @return Marker The build marker */ public Marker getMarker() { return marker; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java index 5c1dfb119f..d2aaea1d17 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java @@ -5,6 +5,9 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import java.util.ArrayList; import java.util.List; +/** + * Multipoint is an abstract annotation for combining geographical locations. + */ public abstract class MultiPoint extends Annotation { private List<LatLng> points; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java index c716d10edf..30847807b9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java @@ -9,6 +9,9 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import java.util.ArrayList; import java.util.List; +/** + * Builder for composing {@link Polygon} objects. + */ public final class PolygonOptions implements Parcelable { public static final Parcelable.Creator<PolygonOptions> CREATOR @@ -96,6 +99,8 @@ public final class PolygonOptions implements Parcelable { /** * Do not use this method. Used internally by the SDK. + * + * @return Polygon the Polygon to return */ public Polygon getPolygon() { return polygon; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java index d48858c7d9..1e625c10fc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java @@ -8,6 +8,9 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import java.util.ArrayList; import java.util.List; +/** + * Builder for composing {@link Polyline} objects. + */ public final class PolylineOptions implements Parcelable { @@ -83,6 +86,7 @@ public final class PolylineOptions implements Parcelable { * Sets the color of the polyline. * * @param color - the color in ARGB format + * @return PolyLineOptions The builder used to build a Polyline */ public PolylineOptions color(int color) { polyline.setColor(color); @@ -95,6 +99,7 @@ public final class PolylineOptions implements Parcelable { /** * Do not use this method. Used internally by the SDK. + * @return PolyLine The polyline build by this class. */ public Polyline getPolyline() { return polyline; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/BoundingBox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/BoundingBox.java index ca805b38e9..72a851e1af 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/BoundingBox.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/BoundingBox.java @@ -9,7 +9,7 @@ import java.util.List; /** * A rectangular geographical area defined in latitude and longitude units. */ -public final class BoundingBox implements Parcelable, Serializable { +public final class BoundingBox implements Parcelable { private final double mLatNorth; private final double mLatSouth; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java index 1ad584f8c8..fefc2502d3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java @@ -1,41 +1,52 @@ package com.mapbox.mapboxsdk.geometry; +import android.os.Parcel; +import android.os.Parcelable; +import android.support.annotation.NonNull; + /** - * Implementation of iOS MGLCoordinateBounds + * A rectangular geograpical region defined by a south west {@link LatLng} and a north east {@link LatLng}. */ -public class CoordinateBounds { +public class CoordinateBounds implements Parcelable { + + private LatLng mSouthWest; + private LatLng mNorthEast; - private LatLng southWest; - private LatLng northEast; + public CoordinateBounds(@NonNull Parcel in) { + mSouthWest = in.readParcelable(LatLng.class.getClassLoader()); + mNorthEast = in.readParcelable(LatLng.class.getClassLoader()); + } - public CoordinateBounds(LatLng southWest, LatLng northEast) { - this.southWest = southWest; - this.northEast = northEast; + public CoordinateBounds(@NonNull LatLng southWest, @NonNull LatLng northEast) { + mSouthWest = southWest; + mNorthEast = northEast; } + @NonNull public LatLng getSouthWest() { - return southWest; + return mSouthWest; } - public void setSouthWest(LatLng southWest) { - this.southWest = southWest; + public void setSouthWest(@NonNull LatLng mSouthWest) { + this.mSouthWest = mSouthWest; } + @NonNull public LatLng getNorthEast() { - return northEast; + return mNorthEast; } - public void setNorthEast(LatLng northEast) { - this.northEast = northEast; + public void setNorthEast(@NonNull LatLng mNorthEast) { + this.mNorthEast = mNorthEast; } @Override public int hashCode() { int result; long temp; - temp = southWest.hashCode(); + temp = mSouthWest.hashCode(); result = (int) (temp ^ (temp >>> 32)); - temp = northEast.hashCode(); + temp = mNorthEast.hashCode(); result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } @@ -53,6 +64,30 @@ public class CoordinateBounds { @Override public String toString() { - return "CoordinateBounds [northEast[" + getNorthEast() + "], southWest[]" + getSouthWest() + "]"; + return "CoordinateBounds [mNorthEast[" + getNorthEast() + "], mSouthWest[]" + getSouthWest() + "]"; + } + + public static final Parcelable.Creator<CoordinateBounds> CREATOR = + new Parcelable.Creator<CoordinateBounds>() { + @Override + public CoordinateBounds createFromParcel(Parcel in) { + return new CoordinateBounds(in); + } + + @Override + public CoordinateBounds[] newArray(int size) { + return new CoordinateBounds[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int arg1) { + out.writeParcelable(mSouthWest, arg1); + out.writeParcelable(mNorthEast, arg1); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java index a70bb05a41..c7c0aa1c49 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java @@ -1,30 +1,64 @@ package com.mapbox.mapboxsdk.geometry; +import android.os.Parcel; +import android.os.Parcelable; +import android.support.annotation.NonNull; + /** - * Implementation of iOS MKCoordinateRegion + * A geographical region defined by a {@link LatLng} and a {@link CoordinateSpan}. */ -public class CoordinateRegion { - private LatLng center; - private CoordinateSpan span; +public class CoordinateRegion implements Parcelable{ + + private LatLng mCenter; + private CoordinateSpan mSpan; - public CoordinateRegion(final LatLng center, final CoordinateSpan span) { - this.center = center; - this.span = span; + public CoordinateRegion(@NonNull Parcel in){ + mCenter = in.readParcelable(LatLng.class.getClassLoader()); + mSpan = in.readParcelable(CoordinateSpan.class.getClassLoader()); + } + + public CoordinateRegion(@NonNull LatLng center, @NonNull CoordinateSpan span) { + mCenter = center; + mSpan = span; } public LatLng getCenter() { - return center; + return mCenter; } - public void setCenter(final LatLng center) { - this.center = center; + public void setCenter(@NonNull LatLng center) { + mCenter = center; } public CoordinateSpan getSpan() { - return span; + return mSpan; + } + + public void setSpan(@NonNull CoordinateSpan span) { + this.mSpan = span; + } + + public static final Parcelable.Creator<CoordinateRegion> CREATOR = + new Parcelable.Creator<CoordinateRegion>() { + @Override + public CoordinateRegion createFromParcel(Parcel in) { + return new CoordinateRegion(in); + } + + @Override + public CoordinateRegion[] newArray(int size) { + return new CoordinateRegion[size]; + } + }; + + @Override + public int describeContents() { + return 0; } - public void setSpan(final CoordinateSpan span) { - this.span = span; + @Override + public void writeToParcel(Parcel out, int arg1) { + out.writeParcelable(mCenter, arg1); + out.writeParcelable(mSpan, arg1); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateSpan.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateSpan.java index 79361f725a..a43757713d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateSpan.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateSpan.java @@ -1,32 +1,41 @@ package com.mapbox.mapboxsdk.geometry; +import android.os.Parcel; +import android.os.Parcelable; +import android.support.annotation.NonNull; + /** - * Implementation of iOS MKCoordinateSpan + * A geographical span defined by its latitude and longitude span. */ -public class CoordinateSpan { +public class CoordinateSpan implements Parcelable { + + private double mLatitudeSpan; + private double mLongitudeSpan; - private double latitudeSpan; - private double longitudeSpan; + public CoordinateSpan(@NonNull Parcel in){ + mLatitudeSpan = in.readDouble(); + mLongitudeSpan = in.readDouble(); + } - public CoordinateSpan(final double latitudeSpan, final double longitudeSpan) { - this.latitudeSpan = latitudeSpan; - this.longitudeSpan = longitudeSpan; + public CoordinateSpan(double latitudeSpan, double longitudeSpan) { + mLatitudeSpan = latitudeSpan; + mLongitudeSpan = longitudeSpan; } public double getLatitudeSpan() { - return latitudeSpan; + return mLatitudeSpan; } - public void setLatitudeSpan(final double latitudeSpan) { - this.latitudeSpan = latitudeSpan; + public void setLatitudeSpan(double latitudeSpan) { + mLatitudeSpan = latitudeSpan; } public double getLongitudeSpan() { - return longitudeSpan; + return mLongitudeSpan; } - public void setLongitudeSpan(final double longitudeSpan) { - this.longitudeSpan = longitudeSpan; + public void setLongitudeSpan(double longitudeSpan) { + mLongitudeSpan = longitudeSpan; } @Override @@ -34,10 +43,33 @@ public class CoordinateSpan { if (this == o) return true; if (o instanceof CoordinateSpan) { CoordinateSpan other = (CoordinateSpan) o; - return longitudeSpan == other.getLongitudeSpan() - && latitudeSpan == other.getLatitudeSpan(); + return mLongitudeSpan == other.getLongitudeSpan() + && mLatitudeSpan == other.getLatitudeSpan(); } return false; } -} + public static final Parcelable.Creator<CoordinateSpan> CREATOR = + new Parcelable.Creator<CoordinateSpan>() { + @Override + public CoordinateSpan createFromParcel(Parcel in) { + return new CoordinateSpan(in); + } + + @Override + public CoordinateSpan[] newArray(int size) { + return new CoordinateSpan[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int arg1) { + out.writeDouble(mLatitudeSpan); + out.writeDouble(mLongitudeSpan); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java index 892d0ad4ae..afd22e5ddb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java @@ -1,7 +1,7 @@ package com.mapbox.mapboxsdk.geometry; /** - * A Latitude, Longitude point. + * Describes a latitude, longitude point. */ public interface ILatLng { double getLatitude(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java index 5aa5f607eb..43fe25f8e5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java @@ -1,5 +1,8 @@ package com.mapbox.mapboxsdk.geometry; +/** + * Describes a projection in Mercator meters. + */ public interface IProjectedMeters { double getNorthing(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java index c340b09e05..f24c2ed431 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java @@ -10,9 +10,10 @@ import com.mapbox.mapboxsdk.constants.MathConstants; import java.io.Serializable; /** + * A geographical location which contains a single latitude, longitude pair, with + * optional altitude. * <p> - * This class is container for a single latitude, longitude pair, with - * optional altitude. Latitude and longitude are expressed as decimal degrees + * Latitude and longitude are expressed as decimal degrees * in the WGS84 datum. By default, altitude is 0.0, or sea level. * </p> * <p> @@ -20,7 +21,7 @@ import java.io.Serializable; * data automatically, so all data enters in the WGS84 datum. * </p> */ -public class LatLng implements ILatLng, Parcelable, Serializable { +public class LatLng implements ILatLng, Parcelable { public static final Parcelable.Creator<LatLng> CREATOR = new Parcelable.Creator<LatLng>() { public LatLng createFromParcel(Parcel in) { @@ -129,7 +130,6 @@ public class LatLng implements ILatLng, Parcelable, Serializable { LatLng latLng = (LatLng) o; return Double.compare(latLng.altitude, altitude) == 0 && Double.compare(latLng.latitude, latitude) == 0 && Double.compare(latLng.longitude, longitude) == 0; - } @Override @@ -168,6 +168,10 @@ public class LatLng implements ILatLng, Parcelable, Serializable { * @return distance in meters */ public double distanceTo(LatLng other) { + if(latitude == other.latitude && longitude == other.longitude){ + // return 0.0 to avoid a NaN + return 0.0; + } final double a1 = MathConstants.DEG2RAD * this.latitude; final double a2 = MathConstants.DEG2RAD * this.longitude; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java index 9e453a391c..6e24faaa9d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java @@ -5,7 +5,10 @@ import android.os.Parcelable; import java.io.Serializable; -public class LatLngZoom extends LatLng implements Parcelable, Serializable { +/** + * A geographical location which contains a {@link LatLng}, zoom pair. + */ +public class LatLngZoom extends LatLng implements Parcelable { public static final Parcelable.Creator<LatLngZoom> CREATOR = new Parcelable.Creator<LatLngZoom>() { public LatLngZoom createFromParcel(Parcel in) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java index fc821e887c..06a58fe8ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java @@ -6,12 +6,14 @@ import android.os.Parcelable; import java.io.Serializable; /** - * ProjectedMeters is an internal representation of longitude, latitude points that - * have been projected into Mapbox GL's Mercator projection. Instead of decimal + * ProjectedMeters is a projection of longitude, latitude points in Mercator meters. + * <p> + * these have been projected into Mapbox GL's Mercator projection. Instead of decimal * degrees, it uses Mercator meters (which are notably not equivalent to SI meters) * except at the equator. + * </p> */ -public class ProjectedMeters implements IProjectedMeters, Parcelable, Serializable { +public class ProjectedMeters implements IProjectedMeters, Parcelable { public static final Creator<ProjectedMeters> CREATOR = new Creator<ProjectedMeters>() { public ProjectedMeters createFromParcel(Parcel in) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 9f6a675715..7ffe338d87 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -139,6 +139,7 @@ public final class MapView extends FrameLayout { private static final String STATE_DEFAULT_TRANSITION_DURATION = "defaultTransitionDuration"; private static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled"; private static final String STATE_MY_LOCATION_TRACKING_MODE = "myLocationTracking"; + private static final String STATE_MY_BEARING_TRACKING_MODE = "myBearingTracking"; private static final String STATE_COMPASS_ENABLED = "compassEnabled"; private static final String STATE_COMPASS_GRAVITY = "compassGravity"; private static final String STATE_COMPASS_MARGIN_LEFT = "compassMarginLeft"; @@ -804,7 +805,7 @@ public final class MapView extends FrameLayout { mZoomButtonsController.setOnZoomListener(new OnZoomListener()); // Check current connection status - ConnectivityManager connectivityManager = (ConnectivityManager) context + ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); boolean isConnected = (activeNetwork != null) && activeNetwork.isConnectedOrConnecting(); @@ -973,6 +974,8 @@ public final class MapView extends FrameLayout { //noinspection ResourceType setMyLocationTrackingMode(savedInstanceState.getInt(STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE)); + //noinspection ResourceType + setMyBearingTrackingMode(savedInstanceState.getInt(STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE)); } // Force a check for an access token @@ -1025,6 +1028,7 @@ public final class MapView extends FrameLayout { outState.putLong(STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration()); outState.putBoolean(STATE_MY_LOCATION_ENABLED, isMyLocationEnabled()); outState.putInt(STATE_MY_LOCATION_TRACKING_MODE, mUserLocationView.getMyLocationTrackingMode()); + outState.putInt(STATE_MY_BEARING_TRACKING_MODE, mUserLocationView.getMyBearingTrackingMode()); // Compass LayoutParams compassParams = (LayoutParams) mCompassView.getLayoutParams(); @@ -2694,8 +2698,9 @@ public final class MapView extends FrameLayout { } if (!handledDefaultClick) { - // default behaviour show InfoWindow - mInfoWindows.add(marker.showInfoWindow()); + if (isInfoWindowValidForMarker(marker)) { + mInfoWindows.add(marker.showInfoWindow(this)); + } } mSelectedMarkers.add(marker); @@ -2736,6 +2741,10 @@ public final class MapView extends FrameLayout { mSelectedMarkers.remove(marker); } + private boolean isInfoWindowValidForMarker(@NonNull Marker marker) { + return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet()); + } + // // Mapbox Core GL Camera // @@ -2873,10 +2882,8 @@ public final class MapView extends FrameLayout { for (Marker marker : mSelectedMarkers) { if (marker.isInfoWindowShown()) { - Marker temp = marker; - temp.hideInfoWindow(); - temp.showInfoWindow(); - marker = temp; + marker.hideInfoWindow(); + marker.showInfoWindow(this); } } } @@ -3173,9 +3180,9 @@ public final class MapView extends FrameLayout { // Open / Close InfoWindow PointF tapPoint = new PointF(e.getX(), e.getY()); - final float toleranceSides = 30 * mScreenDensity; - final float toleranceTop = 40 * mScreenDensity; - final float toleranceBottom = 10 * mScreenDensity; + final float toleranceSides = 15 * mScreenDensity; + final float toleranceTop = 20 * mScreenDensity; + final float toleranceBottom = 5 * mScreenDensity; RectF tapRect = new RectF(tapPoint.x - toleranceSides, tapPoint.y + toleranceTop, tapPoint.x + toleranceSides, tapPoint.y - toleranceBottom); @@ -3188,52 +3195,27 @@ public final class MapView extends FrameLayout { ); BoundingBox tapBounds = BoundingBox.fromLatLngs(corners); - List<Marker> nearbyMarkers = getMarkersInBounds(tapBounds); + long newSelectedMarkerId = -1; - long newSelectedMarkerId; - - if (nearbyMarkers.size() > 0) { - - // there is at least one nearby marker; select one - // - // first, sort for comparison and iteration + if (nearbyMarkers!=null && nearbyMarkers.size() > 0) { Collections.sort(nearbyMarkers); - - if (nearbyMarkers == mMarkersNearLastTap) { - - // TODO: We still need to adapt this logic to the new mSelectedMarkers list, - // though the basic functionality is there. - - // the selection candidates haven't changed; cycle through them -// if (mSelectedMarker != null -// && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) { -// // the selected marker is the last in the set; cycle back to the first -// // note: this could be the selected marker if only one in set -// newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); -// } else if (mSelectedMarker != null) { -// // otherwise increment the selection through the candidates -// long result = mMarkersNearLastTap.indexOf(mSelectedMarker); -// newSelectedMarkerId = mMarkersNearLastTap.get((int) result + 1).getId(); -// } else { - // no current selection; select the first one - newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); -// } - } else { - // start tracking a new set of nearby markers - mMarkersNearLastTap = nearbyMarkers; - - // select the first one - newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); + for (Marker nearbyMarker : nearbyMarkers) { + boolean found = false; + for (Marker selectedMarker : mSelectedMarkers) { + if(selectedMarker.equals(nearbyMarker)){ + found = true; + } + } + if(!found){ + newSelectedMarkerId = nearbyMarker.getId(); + break; + } } - - } else { - // there are no nearby markers; deselect if necessary - newSelectedMarkerId = -1; + mMarkersNearLastTap = nearbyMarkers; } if (newSelectedMarkerId >= 0) { - int count = mAnnotations.size(); for (int i = 0; i < count; i++) { Annotation annotation = mAnnotations.get(i); @@ -3246,7 +3228,6 @@ public final class MapView extends FrameLayout { } } } - } else { // deselect any selected marker deselectMarkers(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java index 67dc9a3499..d0f278a521 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java @@ -34,11 +34,13 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.LocationListener; import com.mapbox.mapboxsdk.location.LocationServices; +import java.lang.ref.WeakReference; + /** * This view shows the user's location, as determined from GPS, on the map * as a dot annotation. */ -final class UserLocationView extends View implements LocationListener { +final class UserLocationView extends View { private MapView mMapView; @@ -85,6 +87,7 @@ final class UserLocationView extends View implements LocationListener { private boolean mPaused = false; private Location mUserLocation; + private UserLocationListener mUserLocationListener; MapView.OnMyLocationChangeListener mOnMyLocationChangeListener; @@ -377,14 +380,18 @@ final class UserLocationView extends View implements LocationListener { setLocation(lastLocation); } + if(mUserLocationListener==null){ + mUserLocationListener = new UserLocationListener(this); + } + // Register for Location Updates - locationServices.addLocationListener(this); + locationServices.addLocationListener(mUserLocationListener); } else { // Disable location and user dot setLocation(null); // Deregister for Location Updates - locationServices.removeLocationListener(this); + locationServices.removeLocationListener(mUserLocationListener); } locationServices.toggleGPS(enableGps); @@ -498,17 +505,27 @@ final class UserLocationView extends View implements LocationListener { } } - /** - * Callback method for receiving location updates from LocationServices. - * - * @param location The new Location data - */ - @Override - public void onLocationChanged(Location location) { - if (mPaused) { - return; + private static class UserLocationListener implements LocationListener{ + + private WeakReference<UserLocationView> mUserLocationView; + + public UserLocationListener(UserLocationView userLocationView) { + mUserLocationView = new WeakReference<>(userLocationView); + } + + + /** + * Callback method for receiving location updates from LocationServices. + * + * @param location The new Location data + */ + @Override + public void onLocationChanged(Location location) { + UserLocationView locationView = mUserLocationView.get(); + if(locationView!=null && !locationView.isPaused()){ + locationView.setLocation(location); + } } - setLocation(location); } private boolean isStale(Location location) { @@ -751,4 +768,8 @@ final class UserLocationView extends View implements LocationListener { } } + public boolean isPaused(){ + return mPaused; + } + } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties index 030ebae5ce..e09bb0110d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties +++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties @@ -1,3 +1,3 @@ fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk -fabric-version=3.0.0 +fabric-version=3.1.0 fabric-build-type=binary |