summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-01-04 19:57:15 +0100
committerTobrun <tobrun@mapbox.com>2019-01-10 19:04:49 +0100
commit847c293a3e8eb5d16843a5b9daead2680e557e3a (patch)
treeaa89d81d04b10a2b7008c74827951dd319a345cc /platform
parent371d2e524fb72dafbde5651e916d6b3beb8aa6d8 (diff)
downloadqtlocation-mapboxgl-847c293a3e8eb5d16843a5b9daead2680e557e3a.tar.gz
[android] - avoid leaking dialog when context is being stopped
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java9
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java19
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java2
3 files changed, 24 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
index 8e436954c8..15ddfe644e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
@@ -45,6 +45,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
@NonNull
private final MapboxMap mapboxMap;
private Set<Attribution> attributionSet;
+ private AlertDialog dialog;
public AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap mapboxMap) {
this.context = context;
@@ -72,7 +73,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionTitles), this);
- builder.show();
+ dialog = builder.show();
}
private String[] getAttributionTitles() {
@@ -93,6 +94,12 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
}
}
+ public void onStop() {
+ if (dialog != null && dialog.isShowing()) {
+ dialog.dismiss();
+ }
+ }
+
private boolean isLatestEntry(int attributionKeyIndex) {
return attributionKeyIndex == getAttributionTitles().length - 1;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 896d67483d..f5a31d2c6a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -69,6 +69,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
private NativeMapView nativeMapView;
@Nullable
private MapboxMap mapboxMap;
+ private AttributionClickListener attributionClickListener;
private MapboxMapOptions mapboxMapOptions;
private MapRenderer mapRenderer;
private boolean destroyed;
@@ -180,7 +181,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
mapboxMap.injectLocationComponent(new LocationComponent(mapboxMap));
// inject widgets with MapboxMap
- attrView.setOnClickListener(new AttributionClickListener(context, mapboxMap));
+ attrView.setOnClickListener(attributionClickListener = new AttributionClickListener(context, mapboxMap));
// Ensure this view is interactable
setClickable(true);
@@ -379,6 +380,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
*/
@UiThread
public void onStop() {
+ attributionClickListener.onStop();
+
if (mapboxMap != null) {
// map was destroyed before it was started
mapGestureDetector.cancelAnimators();
@@ -731,7 +734,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
/**
- /**
+ /**
* Set a callback that's invoked when the style has finished loading.
*
* @param listener The callback that's invoked when the style has finished loading
@@ -1219,11 +1222,19 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
@Override
public void onClick(View v) {
+ getDialogManager().onClick(v);
+ }
+
+ public void onStop() {
+ getDialogManager().onStop();
+ }
+
+ private AttributionDialogManager getDialogManager() {
AttributionDialogManager customDialogManager = uiSettings.getAttributionDialogManager();
if (customDialogManager != null) {
- uiSettings.getAttributionDialogManager().onClick(v);
+ return uiSettings.getAttributionDialogManager();
} else {
- defaultDialogManager.onClick(v);
+ return defaultDialogManager;
}
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
index 4caccec80d..ab29b026f1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
@@ -538,7 +538,7 @@ public final class UiSettings {
*
* @return the active manager class used for showing attribution
*/
- @NonNull
+ @Nullable
public AttributionDialogManager getAttributionDialogManager() {
return attributionDialogManager;
}