Optionable textureview (#6480)
* [android] - make using TextureView optional * add deprecation comment on texture mode
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
* <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.
|
||||
*
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user