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 fc46f3e90..884080ee4 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 @@ -17,6 +17,7 @@ import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.PointF; import android.graphics.RectF; +import android.graphics.SurfaceTexture; import android.graphics.drawable.ColorDrawable; import android.location.Location; import android.net.ConnectivityManager; @@ -46,6 +47,7 @@ import android.view.ScaleGestureDetector; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.TextureView; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; @@ -198,8 +200,15 @@ public class MapView extends FrameLayout { View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this); setWillNotDraw(false); - // Reference the TextureView - SurfaceView surfaceView = (SurfaceView) view.findViewById(R.id.surfaceView); + if (options.getTextureMode()) { + TextureView textureView = new TextureView(context); + textureView.setSurfaceTextureListener(new SurfaceTextureListener()); + addView(textureView, 0); + } else { + SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView); + surfaceView.getHolder().addCallback(new SurfaceCallback()); + surfaceView.setVisibility(View.VISIBLE); + } nativeMapView = new NativeMapView(this); @@ -210,7 +219,6 @@ public class MapView extends FrameLayout { setFocusableInTouchMode(true); requestFocus(); - surfaceView.getHolder().addCallback(new SurfaceCallback()); // Touch gesture detectors gestureDetector = new GestureDetectorCompat(context, new GestureListener()); @@ -1452,6 +1460,61 @@ public class MapView extends FrameLayout { } } + // This class handles TextureView callbacks + private class SurfaceTextureListener implements TextureView.SurfaceTextureListener { + + private Surface surface; + + // Called when the native surface texture has been created + // Must do all EGL/GL ES initialization here + @Override + public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { + nativeMapView.createSurface(this.surface = new Surface(surface)); + nativeMapView.resizeFramebuffer(width, height); + hasSurface = true; + } + + // Called when the native surface texture has been destroyed + // Must do all EGL/GL ES destruction here + @Override + public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { + hasSurface = false; + + if (nativeMapView != null) { + nativeMapView.destroySurface(); + } + this.surface.release(); + return true; + } + + // Called when the format or size of the native surface texture has been changed + // Must handle window resizing here. + @Override + public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { + if (destroyed) { + return; + } + + nativeMapView.resizeFramebuffer(width, height); + } + + // Called when the SurfaceTexure frame is drawn to screen + // Must sync with UI here + @Override + public void onSurfaceTextureUpdated(SurfaceTexture surface) { + if (destroyed) { + return; + } + compassView.update(getDirection()); + myLocationView.update(); + mapboxMap.getMarkerViewManager().update(); + + for (InfoWindow infoWindow : mapboxMap.getInfoWindows()) { + infoWindow.update(); + } + } + } + CameraPosition invalidateCameraPosition() { if (destroyed) { return new CameraPosition.Builder().build(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 6bf421285..352b3ad12 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -77,6 +77,10 @@ public class MapboxMapOptions implements Parcelable { private int myLocationAccuracyAlpha; private String apiBaseUrl; + + @Deprecated + private boolean textureMode; + private String style; @Deprecated private String accessToken; @@ -139,6 +143,7 @@ public class MapboxMapOptions implements Parcelable { style = in.readString(); accessToken = in.readString(); apiBaseUrl = in.readString(); + textureMode = in.readByte() != 0; } public static Bitmap getBitmapFromDrawable(Drawable drawable) { @@ -231,6 +236,7 @@ public class MapboxMapOptions implements Parcelable { , (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_bottom, 0) * screenDensity)}); mapboxMapOptions.myLocationAccuracyAlpha(typedArray.getInt(R.styleable.MapView_my_location_accuracy_alpha, 100)); mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(R.styleable.MapView_my_location_accuracy_tint, ColorUtils.getPrimaryColor(context))); + mapboxMapOptions.textureMode(typedArray.getBoolean(R.styleable.MapView_texture_mode, false)); } finally { typedArray.recycle(); } @@ -594,6 +600,22 @@ public class MapboxMapOptions implements Parcelable { return this; } + /** + * Enable TextureView as rendered surface. + *
+ * Since the 4.2.0 release we replaced our TextureView with an SurfaceView implemenation. + * Enabling this option will use the deprecated TextureView instead. + *
+ * + * @param textureMode True to enable texture mode + * @return This + * @deprecated As of the 4.2.0 release, using TextureView is deprecated. + */ + public MapboxMapOptions textureMode(boolean textureMode) { + this.textureMode = textureMode; + return this; + } + /** * Get the current configured API endpoint base URL. * @@ -878,6 +900,16 @@ public class MapboxMapOptions implements Parcelable { return debugActive; } + /** + * Returns true if TextureView is being used a render view. + * + * @return True if TextureView is used. + * @deprecated As of the 4.2.0 release, using TextureView is deprecated. + */ + public boolean getTextureMode() { + return textureMode; + } + public static final Parcelable.Creator