[android] #3121 Allow InfoWindow to be open while panning, allow standard InfoWindow (without repositioning InfoWindowTipView) to be panned above the map

This commit is contained in:
Tobrun
2015-11-25 10:33:15 +00:00
parent aa018736b2
commit 936d1c01b2
3 changed files with 39 additions and 26 deletions

View File

@@ -18,10 +18,11 @@ import java.lang.ref.WeakReference;
/**
* A tooltip view
*/
final class InfoWindow {
public class InfoWindow {
private WeakReference<Marker> mBoundMarker;
private WeakReference<MapView> mMapView;
private float mMarkerHeightOffset;
private boolean mIsVisible;
protected View mView;
@@ -82,6 +83,7 @@ final class InfoWindow {
*/
InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) {
setBoundMarker(boundMarker);
mMarkerHeightOffset = offsetY;
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
@@ -89,19 +91,20 @@ final class InfoWindow {
// Calculate default Android x,y coordinate
PointF coords = mMapView.get().toScreenLocation(position);
float x = coords.x - (mView.getMeasuredWidth() / 2) + offsetX;
float y = coords.y - mView.getMeasuredHeight() + offsetY;
// get right/left popup window
float rightSideInfowWindow = x + mView.getMeasuredWidth();
float leftSideInfoWindow = x;
// get right/left map view
final float mapRight = mMapView.get().getRight();
final float mapLeft = mMapView.get().getLeft();
float y = coords.y - mView.getMeasuredHeight() + mMarkerHeightOffset;
if (mView instanceof InfoWindowView) {
// only apply repositioning/margin for InfoWindowView
Resources resources = mMapView.get().getContext().getResources();
// get right/left popup window
float rightSideInfowWindow = x + mView.getMeasuredWidth();
float leftSideInfoWindow = x;
// get right/left map view
final float mapRight = mMapView.get().getRight();
final float mapLeft = mMapView.get().getLeft();
float marginHorizontal = resources.getDimension(R.dimen.infowindow_margin);
float tipViewOffset = resources.getDimension(R.dimen.infowindow_tipview_width) / 2;
float tipViewMarginLeft = mView.getMeasuredWidth() / 2 - tipViewOffset;
@@ -226,4 +229,15 @@ final class InfoWindow {
.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();
if (mapView != null && marker != null) {
PointF pointF = mapView.toScreenLocation(marker.getPosition());
mView.setX(pointF.x - mView.getWidth() / 2);
mView.setY(pointF.y - mView.getHeight() + mMarkerHeightOffset);
}
}
}

View File

@@ -79,9 +79,9 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
*/
public void showInfoWindow() {
public InfoWindow showInfoWindow() {
if (getMapView() == null) {
return;
return null;
}
MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter();
@@ -91,17 +91,18 @@ public final class Marker extends Annotation {
if (content != null) {
infoWindow = new InfoWindow(content, getMapView());
showInfoWindow(infoWindow);
return;
return infoWindow;
}
}
getInfoWindow().adaptDefaultMarker(this);
showInfoWindow(getInfoWindow());
return showInfoWindow(getInfoWindow());
}
private void showInfoWindow(InfoWindow iw) {
private InfoWindow showInfoWindow(InfoWindow iw) {
iw.open(this, getPosition(), 0, topOffsetPixels);
infoWindowShown = true;
return iw;
}
private InfoWindow getInfoWindow() {

View File

@@ -56,6 +56,7 @@ import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.InfoWindow;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Polygon;
@@ -81,7 +82,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
@@ -203,6 +203,7 @@ public final class MapView extends FrameLayout {
private final List<Annotation> mAnnotations = new ArrayList<>();
private List<Marker> mMarkersNearLastTap = new ArrayList<>();
private List<Marker> mSelectedMarkers = new ArrayList<>();
private List<InfoWindow> mInfoWindows = new ArrayList<>();
private InfoWindowAdapter mInfoWindowAdapter;
private SpriteFactory mSpriteFactory;
private ArrayList<Sprite> mSprites = new ArrayList<>();
@@ -808,10 +809,6 @@ public final class MapView extends FrameLayout {
addOnMapChangedListener(new OnMapChangedListener() {
@Override
public void onMapChanged(@MapChange int change) {
if ((change == REGION_WILL_CHANGE) || (change == REGION_WILL_CHANGE_ANIMATED)) {
deselectMarkers();
}
if (change == DID_FINISH_LOADING_MAP) {
reloadSprites();
reloadMarkers();
@@ -2033,10 +2030,8 @@ public final class MapView extends FrameLayout {
}
if (!handledDefaultClick) {
// default behaviour
// Can't do this as InfoWindow will get hidden
//setCenterCoordinate(marker.getPosition(), true);
marker.showInfoWindow();
// default behaviour show InfoWindow
mInfoWindows.add(marker.showInfoWindow());
}
mSelectedMarkers.add(marker);
@@ -2051,7 +2046,7 @@ public final class MapView extends FrameLayout {
return;
}
for (Marker marker: mSelectedMarkers) {
for (Marker marker : mSelectedMarkers) {
if (marker.isInfoWindowShown()) {
marker.hideInfoWindow();
}
@@ -2166,7 +2161,7 @@ public final class MapView extends FrameLayout {
}
}
for (Marker marker: mSelectedMarkers) {
for (Marker marker : mSelectedMarkers) {
if (marker.isInfoWindowShown()) {
Marker temp = marker;
temp.hideInfoWindow();
@@ -2252,6 +2247,9 @@ public final class MapView extends FrameLayout {
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
mCompassView.update(getDirection());
mUserLocationView.update();
for (InfoWindow infoWindow : mInfoWindows) {
infoWindow.update();
}
}
}