From 8e538b4d06b12a8b0649b6b98386acca5fb5eeef Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 31 Mar 2017 13:48:47 +0200 Subject: [PATCH] Cherry pick v5.0.2 changes (#8586) * [android] execute resource transform callback on the right thread * [android] allow resetting of resource transform callback * update CHANGELOG for v5.0.2 * [android] - correct anchoring when Icon is updated (#8519) --- platform/android/CHANGELOG.md | 8 ++++++++ .../com/mapbox/mapboxsdk/annotations/MarkerView.java | 9 +++++++++ .../mapbox/mapboxsdk/annotations/MarkerViewManager.java | 1 + .../java/com/mapbox/mapboxsdk/storage/FileSource.java | 4 ++-- platform/android/src/file_source.cpp | 6 +++--- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 5c6b8d57b01..01d7b1ab5bf 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,6 +2,14 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. +## 5.0.2 - April 3, 2017 + +5.0.2 is a patch release that contains the following changes: + +* Fix resource transform callback [#8582](https://github.com/mapbox/mapbox-gl-native/pull/8582) +* Restore onTouch behaviour to 4.x version [#8585](https://github.com/mapbox/mapbox-gl-native/pull/8585) +* Restore anchoring after updating MarkerView Icon [#8519](https://github.com/mapbox/mapbox-gl-native/pull/8519) + ## 5.0.1 - March 22nd, 2017 5.0.1 is a patch release that addresses a shader precision issue that created a rendering problem on some devices. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java index 220d3322cbf..30336d4ebd8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java @@ -389,6 +389,15 @@ public void setMapboxMap(MapboxMap mapboxMap) { } } + /** + * Invalidates the MarkerView resulting in remeasuring the View. + */ + void invalidate() { + width = height = 0; + offsetX = offsetY = MapboxConstants.UNMEASURED; + markerViewManager.invalidateViewMarkersInVisibleRegion(); + } + /** * Get the String representation of a MarkerView. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index 315e12d280d..bb51f3bfc29 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -232,6 +232,7 @@ public void updateIcon(@NonNull MarkerView markerView) { View convertView = markerViewMap.get(markerView); if (convertView != null && convertView instanceof ImageView) { ((ImageView) convertView).setImageBitmap(markerView.getIcon().getBitmap()); + markerView.invalidate(); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java index 8681777023b..a12d8f9954f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java @@ -123,9 +123,9 @@ private FileSource(String cachePath, String apkPath) { * The callback will be executed on the main thread once for every requested URL. *

* - * @param callback the callback to be invoked + * @param callback the callback to be invoked or null to reset */ - public native void setResourceTransform(@NonNull final ResourceTransformCallback callback); + public native void setResourceTransform(final ResourceTransformCallback callback); private native void initialize(String accessToken, String cachePath, String apkPath); diff --git a/platform/android/src/file_source.cpp b/platform/android/src/file_source.cpp index 30e1ff50fe2..20715bf920e 100644 --- a/platform/android/src/file_source.cpp +++ b/platform/android/src/file_source.cpp @@ -46,10 +46,10 @@ void FileSource::setResourceTransform(jni::JNIEnv& env, jni::Object(transformCallback.NewGlobalRef(env).release()->Get(), GenericGlobalRefDeleter()), - env + callback = std::shared_ptr(transformCallback.NewGlobalRef(env).release()->Get(), GenericGlobalRefDeleter()) ](mbgl::Resource::Kind kind, std::string&& url_) { - return FileSource::ResourceTransformCallback::onURL(const_cast(env), jni::Object(*callback), int(kind), url_); + android::UniqueEnv _env = android::AttachEnv(); + return FileSource::ResourceTransformCallback::onURL(*_env, jni::Object(*callback), int(kind), url_); }); } else { // Reset the callback