diff options
author | Brad Leege <bleege@gmail.com> | 2016-07-22 12:36:53 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-07-22 12:54:21 -0500 |
commit | e33b9981cb7e0e909198c11690a571cacd2e27bb (patch) | |
tree | 0acce6af5c5a3f2fc5520be7a33e95ef35c9e5a1 | |
parent | 65e2822f21b1a3c797d8da9c00160248845370af (diff) | |
download | qtlocation-mapboxgl-e33b9981cb7e0e909198c11690a571cacd2e27bb.tar.gz |
Revert "[android] #5000 - initial surface view implementation."
This reverts commit 99a4850613931059174ecf0c6a41af4690481e3a.
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 131 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml | 4 |
2 files changed, 97 insertions, 38 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 aca0e416bf..34e0fadb0b 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 @@ -14,8 +14,10 @@ import android.content.pm.PackageManager; 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; @@ -43,8 +45,7 @@ import android.view.LayoutInflater; 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; @@ -195,7 +196,8 @@ public class MapView extends FrameLayout { } // 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()) { @@ -211,8 +213,6 @@ public class MapView extends FrameLayout { setFocusableInTouchMode(true); requestFocus(); - surfaceView.getHolder().addCallback(new SurfaceCallback()); - // Touch gesture detectors mGestureDetector = new GestureDetectorCompat(context, new GestureListener()); mGestureDetector.setIsLongpressEnabled(true); @@ -459,16 +459,7 @@ public class MapView extends FrameLayout { } } 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(); - } } - } }); @@ -637,6 +628,45 @@ public class MapView extends FrameLayout { 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; @@ -1321,32 +1351,62 @@ public class MapView extends FrameLayout { 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(); } } @@ -2600,19 +2660,18 @@ public class MapView extends FrameLayout { @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); } // 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 f116a15c9e..8787b0ba76 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml @@ -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" /> |