From 67f0108389cdd51f3c59ae7638ea2ecd1c4fa899 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Mon, 12 Oct 2015 10:56:41 +1100 Subject: [PATCH] [android] #2588 - Make getTopOffsetPixelsForAnnotationSymbol private. --- android/java/.gitignore | 3 +++ .../mapboxsdk/annotations/InfoWindow.java | 6 ++--- .../mapbox/mapboxsdk/annotations/Marker.java | 25 +++++++++++-------- .../mapboxsdk/annotations/MarkerOptions.java | 11 +++++--- .../com/mapbox/mapboxsdk/views/MapView.java | 18 ++++--------- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/android/java/.gitignore b/android/java/.gitignore index 626b995946b..173ce20c947 100644 --- a/android/java/.gitignore +++ b/android/java/.gitignore @@ -25,3 +25,6 @@ MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt # Twitter Fabric / Crashlytics fabric.properties + +# Capture files +captures/ diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index 534122e279c..2d153412753 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -84,12 +84,10 @@ public InfoWindow open(Marker object, LatLng position, int offsetX, int offsetY) mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); PointF coords = mMapView.toScreenLocation(position); - double y = mMapView.getTopOffsetPixelsForAnnotationSymbol(object.getSprite()); - y = y * mMapView.getScreenDensity(); - lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2); + lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2) + offsetX; // Add y because it's a negative value - lp.topMargin = (int) coords.y - mView.getMeasuredHeight() + (int) y; + lp.topMargin = (int) coords.y - mView.getMeasuredHeight() + offsetY; close(); //if it was already opened mMapView.addView(mView, lp); diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java index d32b097d559..f82bf605cd1 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java @@ -15,14 +15,15 @@ public class Marker extends Annotation { private boolean flat; private float infoWindowAnchorU; private float infoWindowAnchorV; - LatLng position; + private LatLng position; private float rotation; private String snippet; - String sprite = "default_marker"; + private String sprite = "default_marker"; private String title; private InfoWindow infoWindow = null; private boolean infoWindowShown = false; + private int topOffsetPixels; /** * Constructor @@ -124,7 +125,7 @@ public void setInfoWindowAnchor(float u, float v) { infoWindowAnchorV = v; } - public void setPosition(LatLng latlng) { + public void setPosition(LatLng position) { this.position = position; } @@ -161,26 +162,26 @@ public void setTitle(String title) { } public void showInfoWindow() { - if (!isVisible() || mapView == null) { return; } getInfoWindow().adaptDefaultMarker(this); - getInfoWindow().open(this, getPosition(), (int) anchorU, (int) anchorV); - getInfoWindow().setBoundMarker(this); - infoWindowShown = true; + showInfoWindow(getInfoWindow()); } public void showInfoWindow(View view){ - if (!isVisible() || mapView == null) { return; } infoWindow = new InfoWindow(view, mapView); - infoWindow.open(this, getPosition(), (int) anchorU, (int) anchorV); - infoWindow.setBoundMarker(this); + showInfoWindow(infoWindow); + } + + private void showInfoWindow(InfoWindow iw) { + iw.open(this, getPosition(), (int) anchorU, (int) anchorV + topOffsetPixels); + iw.setBoundMarker(this); infoWindowShown = true; } @@ -222,4 +223,8 @@ public void setVisible(boolean visible) { // void setIcon(BitmapDescriptor icon) { // // } + + void setTopOffsetPixels(int topOffsetPixels) { + this.topOffsetPixels = topOffsetPixels; + } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java index a62f7dbf58e..9ef1724730c 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java @@ -46,7 +46,8 @@ public float getInfoWindowAnchorV() { return ((Marker)annotation).getInfoWindowAnchorV(); } - public Marker getMarker() { + public Marker getMarker(int topOffsetPixels) { + ((Marker)annotation).setTopOffsetPixels(topOffsetPixels); return (Marker)annotation; } @@ -66,6 +67,10 @@ public String getTitle() { return ((Marker)annotation).getTitle(); } + public String getSprite() { + return ((Marker)annotation).getSprite(); + } + public MarkerOptions infoWindowAnchor(float u, float v) { ((Marker)annotation).setInfoWindowAnchor(u, v); return this; @@ -84,7 +89,7 @@ public boolean isVisible() { } public MarkerOptions position(LatLng position) { - ((Marker)annotation).position = position; + ((Marker)annotation).setPosition(position); return this; } @@ -100,7 +105,7 @@ public MarkerOptions snippet(String snippet) { public MarkerOptions sprite(@Nullable String sprite) { if (!TextUtils.isEmpty(sprite)) { - ((Marker)annotation).sprite = sprite; + ((Marker)annotation).setSprite(sprite); } return this; } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 76fd32fc797..9f723f3e6a5 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -1596,7 +1596,7 @@ public Marker addMarker(@NonNull MarkerOptions markerOptions) { throw new NullPointerException("markerOptions is null"); } - Marker marker = markerOptions.getMarker(); + Marker marker = markerOptions.getMarker(getTopOffsetPixelsForAnnotationSymbol(markerOptions.getSprite())); // Load the default marker sprite if (marker.getSprite() == null) { @@ -1634,7 +1634,7 @@ public List addMarkers(@NonNull List markerOptionsList) { List markers = new ArrayList<>(markerOptionsList.size()); for (MarkerOptions markerOptions : markerOptionsList) { - Marker marker = markerOptions.getMarker(); + Marker marker = markerOptions.getMarker(getTopOffsetPixelsForAnnotationSymbol(markerOptions.getSprite())); // Load the default marker sprite if (marker.getSprite() == null) { @@ -1646,7 +1646,7 @@ public List addMarkers(@NonNull List markerOptionsList) { marker.setSprite("default_marker"); //marker.setSprite(DEFAULT_SPRITE); } - markers.add(markerOptions.getMarker()); + markers.add(marker); } long[] ids = mNativeMapView.addMarkers(markers); @@ -1857,8 +1857,8 @@ private List getMarkersInBounds(@NonNull BoundingBox bbox) { * @param symbolName Annotation Symbol * @return Top Offset in pixels */ - public double getTopOffsetPixelsForAnnotationSymbol(@NonNull String symbolName) { - return mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(symbolName); + private int getTopOffsetPixelsForAnnotationSymbol(String symbolName) { + return (int) (mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(symbolName) * mScreenDensity); } /** @@ -1875,14 +1875,6 @@ public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) dou return mNativeMapView.getMetersPerPixelAtLatitude(latitude, getZoomLevel()); } - /** - * Get ScreenDensity of device - * @return Screen Density ratio - */ - public float getScreenDensity() { - return mScreenDensity; - } - private void selectMarker(Marker marker) { if (marker == null) { return;