diff options
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.java | 44 |
1 files changed, 41 insertions, 3 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 0fa1072cd2..aaed71ddec 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 @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.maps; import android.content.Context; import android.graphics.Bitmap; import android.graphics.PointF; +import android.graphics.drawable.ColorDrawable; import android.opengl.GLSurfaceView; import android.os.Build; import android.os.Bundle; @@ -126,6 +127,11 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { // in IDE layout editor, just return return; } + + // hide surface until map is fully loaded #10990 + setForeground(new ColorDrawable(options.getForegroundLoadColor())); + addOnMapChangedListener(new InitialRenderCallback(this)); + mapboxMapOptions = options; // inflate view @@ -283,11 +289,12 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } private void initialiseDrawingSurface(MapboxMapOptions options) { + String localFontFamily = options.getLocalIdeographFontFamily(); if (options.getTextureMode()) { TextureView textureView = new TextureView(getContext()); - String localFontFamily = options.getLocalIdeographFontFamily(); boolean translucentSurface = options.getTranslucentTextureSurface(); - mapRenderer = new TextureViewMapRenderer(getContext(), textureView, localFontFamily, translucentSurface) { + mapRenderer = new TextureViewMapRenderer(getContext(), + textureView, localFontFamily, translucentSurface) { @Override protected void onSurfaceCreated(GL10 gl, EGLConfig config) { MapView.this.onSurfaceCreated(); @@ -299,7 +306,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } else { GLSurfaceView glSurfaceView = new GLSurfaceView(getContext()); glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); - mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) { + mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, localFontFamily) { @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { MapView.this.onSurfaceCreated(); @@ -981,6 +988,37 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } } + /** + * The initial render callback waits for rendering to happen before making the map visible for end-users. + * We wait for the second DID_FINISH_RENDERING_FRAME map change event as the first will still show a black surface. + */ + private static class InitialRenderCallback implements OnMapChangedListener { + + private WeakReference<MapView> weakReference; + private int renderCount; + private boolean styleLoaded; + + InitialRenderCallback(MapView mapView) { + this.weakReference = new WeakReference<>(mapView); + } + + @Override + public void onMapChanged(int change) { + if (change == MapView.DID_FINISH_LOADING_STYLE) { + styleLoaded = true; + } else if (styleLoaded && change == MapView.DID_FINISH_RENDERING_FRAME) { + renderCount++; + if (renderCount == 2) { + MapView mapView = weakReference.get(); + if (mapView != null && !mapView.isDestroyed()) { + mapView.setForeground(null); + mapView.removeOnMapChangedListener(this); + } + } + } + } + } + private class GesturesManagerInteractionListener implements MapboxMap.OnGesturesManagerInteractionListener { @Override |