summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java48
1 files changed, 30 insertions, 18 deletions
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 03a1d949f4..d2567a114b 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
@@ -42,18 +42,16 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
import com.mapbox.mapboxsdk.storage.FileSource;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
-import timber.log.Timber;
-
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
@@ -137,17 +135,7 @@ public class MapView extends FrameLayout {
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
setWillNotDraw(false);
- getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- getViewTreeObserver().removeOnGlobalLayoutListener(this);
- } else {
- getViewTreeObserver().removeGlobalOnLayoutListener(this);
- }
- initialiseDrawingSurface(options);
- }
- });
+ getViewTreeObserver().addOnGlobalLayoutListener(new MapViewLayoutListener(this, options));
}
private void initialiseMap() {
@@ -313,7 +301,7 @@ public class MapView extends FrameLayout {
addView(textureView, 0);
} else {
- GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
+ GLSurfaceView glSurfaceView = new GLSurfaceView(getContext());
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) {
@Override
@@ -323,7 +311,7 @@ public class MapView extends FrameLayout {
}
};
- glSurfaceView.setVisibility(View.VISIBLE);
+ addView(glSurfaceView, 0);
}
nativeMapView = new NativeMapView(this, mapRenderer);
@@ -890,6 +878,30 @@ public class MapView extends FrameLayout {
void onMapChanged(@MapChange int change);
}
+ private static class MapViewLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
+
+ private WeakReference<MapView> mapViewWeakReference;
+ private MapboxMapOptions options;
+
+ MapViewLayoutListener(MapView mapView, MapboxMapOptions options) {
+ this.mapViewWeakReference = new WeakReference<>(mapView);
+ this.options = options;
+ }
+
+ @Override
+ public void onGlobalLayout() {
+ MapView mapView = mapViewWeakReference.get();
+ if (mapView != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ } else {
+ mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ }
+ mapView.initialiseDrawingSurface(options);
+ }
+ }
+ }
+
private class FocalPointInvalidator implements FocalPointChangeListener {
private final List<FocalPointChangeListener> focalPointChangeListeners = new ArrayList<>();