Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Revert "[android] #5000 - initial surface view implementation."
Browse files Browse the repository at this point in the history
This reverts commit 99a4850.
  • Loading branch information
bleege committed Jul 22, 2016
1 parent 65e2822 commit e33b998
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
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;
Expand Down Expand Up @@ -43,8 +45,7 @@
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;
import android.view.ViewGroup;
Expand Down Expand Up @@ -195,7 +196,8 @@ private void initialize(@NonNull Context context, @NonNull MapboxMapOptions opti
}

// Reference the TextureView
SurfaceView surfaceView = (SurfaceView) view.findViewById(R.id.surfaceView);
TextureView textureView = (TextureView) view.findViewById(R.id.textureView);
textureView.setSurfaceTextureListener(new SurfaceTextureListener());

// Check if we are in Android Studio UI editor to avoid error in layout preview
if (isInEditMode()) {
Expand All @@ -211,8 +213,6 @@ private void initialize(@NonNull Context context, @NonNull MapboxMapOptions opti
setFocusableInTouchMode(true);
requestFocus();

surfaceView.getHolder().addCallback(new SurfaceCallback());

// Touch gesture detectors
mGestureDetector = new GestureDetectorCompat(context, new GestureListener());
mGestureDetector.setIsLongpressEnabled(true);
Expand Down Expand Up @@ -459,16 +459,7 @@ public void onMapChanged(@MapChange int change) {
}
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
mMapboxMap.getMarkerViewManager().scheduleViewMarkerInvalidation();

mCompassView.update(getBearing());
mMyLocationView.update();
mMapboxMap.getMarkerViewManager().update();

for (InfoWindow infoWindow : mMapboxMap.getInfoWindows()) {
infoWindow.update();
}
}

}
});

Expand Down Expand Up @@ -637,6 +628,45 @@ void setTilt(Double pitch) {
mNativeMapView.setPitch(pitch, 0);
}


//
// Direction
//

double getDirection() {
if (mDestroyed) {
return 0;
}

double direction = -mNativeMapView.getBearing();

while (direction > 360) {
direction -= 360;
}
while (direction < 0) {
direction += 360;
}

return direction;
}

void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction) {
if (mDestroyed) {
return;
}
setDirection(direction, false);
}

void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction, boolean animated) {
if (mDestroyed) {
return;
}
long duration = animated ? MapboxConstants.ANIMATION_DURATION : 0;
mNativeMapView.cancelTransitions();
// Out of range directions are normalised in setBearing
mNativeMapView.setBearing(-direction, duration);
}

void resetNorth() {
if (mDestroyed) {
return;
Expand Down Expand Up @@ -1321,32 +1351,62 @@ protected void onSizeChanged(int width, int height, int oldw, int oldh) {
return mNativeMapView.getScale();
}

private class SurfaceCallback implements SurfaceHolder.Callback {
// This class handles TextureView callbacks
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {

private Surface mSurface;
private View mViewHolder;

private static final int VIEW_MARKERS_POOL_SIZE = 20;


// Called when the native surface texture has been created
// Must do all EGL/GL ES initialization here
@Override
public void surfaceCreated(SurfaceHolder holder) {
mNativeMapView.createSurface(mSurface = holder.getSurface());
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mNativeMapView.createSurface(mSurface = new Surface(surface));
mNativeMapView.resizeFramebuffer(width, height);
mHasSurface = true;
}

// Called when the native surface texture has been destroyed
// Must do all EGL/GL ES destruction here
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mHasSurface = false;

if (mNativeMapView != null) {
mNativeMapView.destroySurface();
}
mSurface.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 (mDestroyed) {
return;
}

mNativeMapView.resizeFramebuffer(width, height);
}

// Called when the SurfaceTexure frame is drawn to screen
// Must sync with UI here
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mHasSurface = false;
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
if (mDestroyed) {
return;
}
mCompassView.update(getDirection());
mMyLocationView.update();
mMapboxMap.getMarkerViewManager().update();

if (mNativeMapView != null) {
mNativeMapView.destroySurface();
for (InfoWindow infoWindow : mMapboxMap.getInfoWindows()) {
infoWindow.update();
}
mSurface.release();
}
}

Expand Down Expand Up @@ -2600,19 +2660,18 @@ MyLocationView getUserLocationView() {

@UiThread
void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
// TextureView textureView = (TextureView) findViewById(R.id.textureView);
// final boolean canUseBitmap = bitmap != null && textureView.getWidth() == bitmap.getWidth() && textureView.getHeight() == bitmap.getHeight();
//
// setDrawingCacheEnabled(true);
// Bitmap content = Bitmap.createBitmap(getDrawingCache());
// setDrawingCacheEnabled(false);
//
// Bitmap output = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);
// Canvas canvas = new Canvas(output);
// canvas.drawBitmap(canUseBitmap ? textureView.getBitmap(bitmap) : textureView.getBitmap(), 0, 0, null);
// canvas.drawBitmap(content, new Matrix(), null);
// callback.onSnapshotReady(output);
throw new RuntimeException("TextureView code needs to be migrated to SurfaceView");
TextureView textureView = (TextureView) findViewById(R.id.textureView);
final boolean canUseBitmap = bitmap != null && textureView.getWidth() == bitmap.getWidth() && textureView.getHeight() == bitmap.getHeight();

setDrawingCacheEnabled(true);
Bitmap content = Bitmap.createBitmap(getDrawingCache());
setDrawingCacheEnabled(false);

Bitmap output = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawBitmap(canUseBitmap ? textureView.getBitmap(bitmap) : textureView.getBitmap(), 0, 0, null);
canvas.drawBitmap(content, new Matrix(), null);
callback.onSnapshotReady(output);
}

//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<SurfaceView
android:id="@+id/surfaceView"
<TextureView
android:id="@+id/textureView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down

0 comments on commit e33b998

Please sign in to comment.