summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-01-18 09:10:17 +0100
committerTobrun <tobrun@mapbox.com>2016-01-18 09:10:17 +0100
commit74a9c505f9e390ec25fc16904c432dd19cc900f2 (patch)
treeb5fd4aafc3bb35adc0a8c01a41afcf4d6540484a /platform
parent2dae355cbd7097cb8adbc34e2cdf51db789b6739 (diff)
downloadqtlocation-mapboxgl-74a9c505f9e390ec25fc16904c432dd19cc900f2.tar.gz
[android] #3573 - Marker clicks stop working after orientation change
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java68
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java8
2 files changed, 22 insertions, 54 deletions
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 65f89c48e3..2ace201c9a 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;
@@ -31,18 +31,12 @@ public class InfoWindow {
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 +80,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 +93,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 +158,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;
@@ -196,25 +190,15 @@ public class InfoWindow {
*/
void adaptDefaultMarker(Marker overlayItem, MapView mapView) {
View view = mView.get();
- if (view != null) {
- mMapView = new WeakReference<>(mapView);
- overlayItem.setMapView(mapView);
- 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() {
@@ -233,22 +217,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 9482afaa26..8b4b66a2a3 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
@@ -93,17 +93,17 @@ public final class Marker extends Annotation {
View content = infoWindowAdapter.getInfoWindow(this);
if (content != null) {
infoWindow = new InfoWindow(content, getMapView());
- showInfoWindow(infoWindow);
+ showInfoWindow(infoWindow, mapView);
return infoWindow;
}
}
getInfoWindow().adaptDefaultMarker(this, mapView);
- return showInfoWindow(getInfoWindow());
+ 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;
}