Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsd…
Browse files Browse the repository at this point in the history
…k/maps/MapView.java
  • Loading branch information
tobrun committed Jul 12, 2018
1 parent f7e2fe5 commit 97fdde8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -126,6 +127,11 @@ protected void initialize(@NonNull final Context context, @NonNull final MapboxM
// in IDE layout editor, just return
return;
}

// hide surface until map is fully loaded #10990
setForeground(new ColorDrawable(options.getForegroundLoadColor()));
mapCallback.addOnMapReadyCallback(new InitialStyleLoadedCallback(this));

mapboxMapOptions = options;

// inflate view
Expand Down Expand Up @@ -981,6 +987,23 @@ public void onFocalPointChanged(PointF pointF) {
}
}

private static class InitialStyleLoadedCallback implements OnMapReadyCallback {

private WeakReference<MapView> weakReference;

InitialStyleLoadedCallback(MapView mapView) {
this.weakReference = new WeakReference<>(mapView);
}

@Override
public void onMapReady(MapboxMap mapboxMap) {
MapView mapView = weakReference.get();
if (mapView != null && !mapView.isDestroyed()) {
mapView.setForeground(null);
}
}
}

private class GesturesManagerInteractionListener implements MapboxMap.OnGesturesManagerInteractionListener {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
Expand Down Expand Up @@ -73,6 +74,9 @@ public class MapboxMapOptions implements Parcelable {
private boolean textureMode;
private boolean translucentTextureSurface;

@ColorInt
private int foregroundLoadColor;

private String style;

private float pixelRatio;
Expand Down Expand Up @@ -124,6 +128,7 @@ private MapboxMapOptions(Parcel in) {
zMediaOverlay = in.readByte() != 0;
localIdeographFontFamily = in.readString();
pixelRatio = in.readFloat();
foregroundLoadColor = in.readInt();
}

/**
Expand Down Expand Up @@ -222,6 +227,9 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
mapboxMapOptions.pixelRatio(
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_pixelRatio, 0));
mapboxMapOptions.foregroundLoadColor(
typedArray.getInt(R.styleable.mapbox_MapView_mapbox_foregroundLoadColor, Color.WHITE)
);
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -521,6 +529,17 @@ public MapboxMapOptions translucentTextureSurface(boolean translucentTextureSurf
return this;
}

/**
* Set the MapView foreground color that is used when the map surface is being created.
*
* @param loadColor the color to show during map creation
* @return This
*/
public MapboxMapOptions foregroundLoadColor(@ColorInt int loadColor) {
this.foregroundLoadColor = loadColor;
return this;
}

/**
* Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
* a low resolution preview while more detailed tiles are loaded.
Expand Down Expand Up @@ -819,6 +838,16 @@ public boolean getTranslucentTextureSurface() {
return translucentTextureSurface;
}

/**
* Returns the current configured foreground color that is used during map creation.
*
* @return the load color
*/
@ColorInt
public int getForegroundLoadColor() {
return foregroundLoadColor;
}

/**
* Returns the font-family for locally overriding generation of glyphs in the
* &#x27;CJK Unified Ideographs&#x27; and &#x27;Hangul Syllables&#x27; ranges.
Expand Down Expand Up @@ -892,6 +921,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
dest.writeString(localIdeographFontFamily);
dest.writeFloat(pixelRatio);
dest.writeInt(foregroundLoadColor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<!-- Use TextureView-->
<public name="mapbox_renderTextureMode" type="attr" />
<public name="mapbox_renderTextureTranslucentSurface" type="attr" />
<public name="mapbox_foregroundLoadColor" type="attr" />

<public name="mapbox_enableTilePrefetch" type="attr" />
<public name="mapbox_enableZMediaOverlay" type="attr" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<!-- Use TextureView-->
<attr name="mapbox_renderTextureMode" format="boolean"/>
<attr name="mapbox_renderTextureTranslucentSurface" format="boolean"/>
<attr name="mapbox_foregroundLoadColor" format="color"/>

<attr name="mapbox_enableTilePrefetch" format="boolean"/>
<attr name="mapbox_enableZMediaOverlay" format="boolean"/>
Expand Down

0 comments on commit 97fdde8

Please sign in to comment.