diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-09-29 15:05:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-29 15:05:50 +0200 |
commit | 87a438ec75ef1e1f34be4f99225d8f1ede88a8a8 (patch) | |
tree | a06fb119e138150c8ca9857b7bd419c53bd78fb4 /platform | |
parent | 1fd142a4492211de9a37c11014d105dfb8ececf2 (diff) | |
download | qtlocation-mapboxgl-87a438ec75ef1e1f34be4f99225d8f1ede88a8a8.tar.gz |
Optionable textureview (#6480)
* [android] - make using TextureView optional
* add deprecation comment on texture mode
Diffstat (limited to 'platform')
5 files changed, 106 insertions, 4 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 fc46f3e903..884080ee4a 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 6bf4212857..352b3ad12a 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(); } @@ -595,6 +601,22 @@ public class MapboxMapOptions implements Parcelable { } /** + * Enable TextureView as rendered surface. + * <p> + * Since the 4.2.0 release we replaced our TextureView with an SurfaceView implemenation. + * Enabling this option will use the deprecated TextureView instead. + * </p> + * + * @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. * * @return Base URL to be used API endpoint. @@ -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<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() { public MapboxMapOptions createFromParcel(Parcel in) { @@ -935,6 +967,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeString(style); dest.writeString(accessToken); dest.writeString(apiBaseUrl); + dest.writeByte((byte) (textureMode ? 1 : 0)); } @Override diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml index 1a9d1fc7bb..4f032c1008 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml @@ -4,7 +4,8 @@ <SurfaceView android:id="@+id/surfaceView" android:layout_width="match_parent" - android:layout_height="match_parent" /> + android:layout_height="match_parent" + android:visibility="gone" /> <FrameLayout android:id="@+id/markerViewContainer" diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 1d40879d27..f0740a4e53 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -111,5 +111,8 @@ <attr name="attribution_margin_bottom" format="dimension" /> <attr name="attribution_enabled" format="boolean" /> <attr name="attribution_tint" format="color" /> + + <!-- Deprecated to use TextureView--> + <attr name="texture_mode" format="boolean" /> </declare-styleable> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index 6638f8a2de..1382ab8141 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -79,6 +79,8 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall // configure inital map state MapboxMapOptions options = new MapboxMapOptions() .attributionTintColor(RED_COLOR) + // deprecated feature! + .textureMode(true) .styleUrl(Style.MAPBOX_STREETS) .camera(new CameraPosition.Builder() .target(new LatLng(45.520486, -122.673541)) |