diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-11-16 18:08:48 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-11-16 18:08:48 +0100 |
commit | 568eaaa108ed9e6e55d306ef2ea670c215c8d0ac (patch) | |
tree | 7e1d009e7b7f926a3bc80368005c4080d70c44fb /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox | |
parent | 5479b75c9fa971332aadfede6b380267eebbd566 (diff) | |
download | qtlocation-mapboxgl-568eaaa108ed9e6e55d306ef2ea670c215c8d0ac.tar.gz |
[android] - migrate to GLSurfaceViewupstream/5766-gl-surfaceview
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox')
3 files changed, 105 insertions, 16 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java new file mode 100644 index 0000000000..4ce921d656 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapSurfaceView.java @@ -0,0 +1,89 @@ +package com.mapbox.mapboxsdk.maps; + +import android.content.Context; +import android.opengl.GLSurfaceView; +import android.os.Handler; +import android.util.AttributeSet; +import android.util.Log; + +import com.mapbox.mapboxsdk.constants.Style; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import static com.mapbox.mapboxsdk.constants.MapboxConstants.TAG; + +public class MapSurfaceView extends GLSurfaceView { + + private MapRenderer renderer; + private NativeMapView nativeMapView; + + public MapSurfaceView(Context context) { + super(context); + init(context, null); + } + + public MapSurfaceView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS); + setEGLContextClientVersion(2); + nativeMapView = new NativeMapView(this); + nativeMapView.setAccessToken("pk.eyJ1IjoidG9icnVuIiwiYSI6ImNpajVlajR0cjAwNjN2NmtyY204eWw2eG0ifQ.x3_WEoExNW5Qyv9T3Vj7Mw"); + nativeMapView.setStyleUrl(Style.LIGHT); + renderer = new MapRenderer(); + setRenderer(renderer); + setRenderMode(RENDERMODE_WHEN_DIRTY); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + nativeMapView.flyTo(90, new LatLng(22, 22), 3000, 2, 11); + } + }, 3000); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + } + + public void onInvalidate() { + throw new RuntimeException("OnInvalidate"); + } + + public void onMapChanged(int rawChange) { + throw new RuntimeException("OnMapChanged " + rawChange); + } + + public void onFpsChanged(double fps) { + throw new RuntimeException("OnFpsChanged " + fps); + } + + public void onSnapshotReady(byte[] bytes) { + throw new RuntimeException("OnSnapshotReady"); + } + + private class MapRenderer implements GLSurfaceView.Renderer { + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + Log.d(TAG, "onSurfaceCreated"); + nativeMapView.createSurface(getHolder().getSurface()); + } + + public void onSurfaceChanged(GL10 gl, final int w, final int h) { + Log.d(TAG, "onSurfaceChanged " + w + " " + h); + gl.glViewport(0, 0, w, h); + nativeMapView.resizeView(w, h); + nativeMapView.resizeFramebuffer(w, h); + nativeMapView.update(); + } + + public void onDrawFrame(GL10 gl) { + Log.d(TAG, "onDrawFrame render"); + nativeMapView.render(); + } + } +} 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 e5848f5090..3f6bd31471 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 @@ -45,7 +45,6 @@ import android.view.MotionEvent; 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; @@ -124,6 +123,8 @@ public class MapView extends FrameLayout { private MyLocationView myLocationView; private LocationListener myLocationListener; + private MapSurfaceView mapSurfaceView; + private Projection projection; private CopyOnWriteArrayList<OnMapChangedListener> onMapChangedListener; @@ -202,12 +203,11 @@ public class MapView extends FrameLayout { textureView.setSurfaceTextureListener(new SurfaceTextureListener()); addView(textureView, 0); } else { - SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView); - surfaceView.getHolder().addCallback(new SurfaceCallback()); - surfaceView.setVisibility(View.VISIBLE); + mapSurfaceView = (MapSurfaceView) findViewById(R.id.surfaceView); + //surfaceView.getHolder().addCallback(new SurfaceCallback()); + mapSurfaceView.setVisibility(View.VISIBLE); } - nativeMapView = new NativeMapView(this); iconManager = new IconManager(nativeMapView); mapboxMap = new MapboxMap(this, iconManager); annotationManager = mapboxMap.getAnnotationManager(); @@ -576,6 +576,8 @@ public class MapView extends FrameLayout { public void onStart() { onStartCalled = true; + mapSurfaceView.onResume(); + // Register for connectivity changes connectivityReceiver = new ConnectivityReceiver(); getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); @@ -616,6 +618,8 @@ public class MapView extends FrameLayout { public void onStop() { onStopCalled = true; + mapSurfaceView.onPause(); + // Unregister for connectivity changes if (connectivityReceiver != null) { getContext().unregisterReceiver(connectivityReceiver); @@ -705,11 +709,11 @@ public class MapView extends FrameLayout { // Center coordinate // - LatLng getCenterCoordinate(){ + LatLng getCenterCoordinate() { return nativeMapView.getLatLng(); } - void setCenterCoordinate(LatLng centerCoordinate){ + void setCenterCoordinate(LatLng centerCoordinate) { nativeMapView.setLatLng(centerCoordinate); } @@ -1071,7 +1075,7 @@ public class MapView extends FrameLayout { // Mapbox Core GL Camera // - private void cancelTransitions(){ + private void cancelTransitions() { if (cameraCancelableCallback != null) { cameraCancelableCallback.onCancel(); cameraCancelableCallback = null; @@ -1522,10 +1526,6 @@ public class MapView extends FrameLayout { // Called for double taps @Override public boolean onDoubleTapEvent(MotionEvent e) { - if (destroyed || !mapboxMap.getUiSettings().isZoomGesturesEnabled()) { - return false; - } - switch (e.getAction()) { case MotionEvent.ACTION_DOWN: break; @@ -2656,7 +2656,7 @@ public class MapView extends FrameLayout { } } - private static class ZoomInvalidator implements Runnable { + public static class ZoomInvalidator implements Runnable { private MapboxMap mapboxMap; @@ -2667,7 +2667,7 @@ public class MapView extends FrameLayout { @Override public void run() { // invalidate camera position - mapboxMap.getCameraPosition(); + // mapboxMap.getCameraPosition(); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index e7e3e647af..ff64a56beb 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -40,7 +40,7 @@ final class NativeMapView { private long nativeMapViewPtr = 0; // Used for callbacks - private MapView mapView; + private MapSurfaceView mapView; private final float pixelRatio; @@ -56,7 +56,7 @@ final class NativeMapView { // Constructors // - public NativeMapView(MapView mapView) { + public NativeMapView(MapSurfaceView mapView) { Context context = mapView.getContext(); String dataPath = OfflineManager.getDatabasePath(context); |