From 3b2bd7ce4f7087f51f2aeace22fe60c5c83ee1d9 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 31 Oct 2017 18:12:04 +0200 Subject: [android] bring back texture view --- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 66 +++++++++++++++------- 1 file changed, 45 insertions(+), 21 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java') 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 b5546f2cc4..ba09df2cbe 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 @@ -15,6 +15,7 @@ import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; +import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; @@ -29,6 +30,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; +import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer; import com.mapbox.mapboxsdk.maps.widgets.CompassView; import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; @@ -139,7 +141,7 @@ public class MapView extends FrameLayout { } else { getViewTreeObserver().removeGlobalOnLayoutListener(this); } - initialiseDrawingSurface(); + initialiseDrawingSurface(options); } }); } @@ -289,31 +291,53 @@ public class MapView extends FrameLayout { } } - private void initialiseDrawingSurface() { - GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); - glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); + private void initialiseDrawingSurface(MapboxMapOptions options) { + if (options.getTextureMode()) { + TextureView textureView = new TextureView(getContext()); + mapRenderer = new TextureViewMapRenderer(getContext(), textureView) { + @Override + protected void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.post(new Runnable() { + @Override + public void run() { + // Initialise only once + if (mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } + } + }); - GLSurfaceViewMapRenderer mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) { - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); + super.onSurfaceCreated(gl, config); + } + }; + addView(textureView, 0); + } else { + GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); + glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); + + mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) { + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.post(new Runnable() { + @Override + public void run() { + // Initialise only once + if (mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } } - } - }); + }); - super.onSurfaceCreated(gl, config); - } - }; + super.onSurfaceCreated(gl, config); + } + }; - glSurfaceView.setVisibility(View.VISIBLE); + glSurfaceView.setVisibility(View.VISIBLE); + + } - this.mapRenderer = mapRenderer; nativeMapView = new NativeMapView(this, mapRenderer); nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight()); } -- cgit v1.2.1