summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-02-04 13:10:17 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-02-04 14:52:14 +0100
commit8ad13cd577cfdc19611e16bf36ed351432e261b9 (patch)
tree39afdf114bbe3c18fbdee26b5f302444a42352b5
parente45c3926c26884aceca5789837e1c1b31a51154e (diff)
downloadqtlocation-mapboxgl-8ad13cd577cfdc19611e16bf36ed351432e261b9.tar.gz
[android] expose symbol placement transition duration option
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java23
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java54
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt12
-rwxr-xr-xplatform/android/src/native_map_view.cpp6
-rw-r--r--platform/android/src/style/conversion/transition_options.cpp3
-rw-r--r--platform/android/src/style/transition_options.cpp12
-rw-r--r--platform/android/src/style/transition_options.hpp4
7 files changed, 97 insertions, 17 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
index 567f0fc768..2e3a5335fe 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
@@ -375,9 +375,16 @@ public class Style {
/**
* <p>
- * Set the transition duration for style changes.
+ * Set the transition options for style changes.
* </p>
- * The default value for delay and duration is zero, so any changes take effect without animation.
+ * If not set, any changes take effect without animation, besides symbols,
+ * which will fade in/out with a default duration after symbol collision detection.
+ * <p>
+ * To disable symbols fade in/out animation,
+ * pass transition options with {@link TransitionOptions#enablePlacementTransitions} equal to false.
+ * <p>
+ * Both {@link TransitionOptions#duration} and {@link TransitionOptions#delay}
+ * will also change the behavior of the symbols fade in/out animation if the placement transition is enabled.
*
* @param transitionOptions the transition options
*/
@@ -388,9 +395,17 @@ public class Style {
/**
* <p>
- * Get the transition for style changes.
+ * Get the transition options for style changes.
* </p>
- * The default value for delay and transition is zero, so any changes take effect without animation.
+ * By default, any changes take effect without animation, besides symbols,
+ * which will fade in/out with a default duration after symbol collision detection.
+ * <p>
+ * To disable symbols fade in/out animation,
+ * pass transition options with {@link TransitionOptions#enablePlacementTransitions} equal to false
+ * into {@link #setTransition(TransitionOptions)}.
+ * <p>
+ * Both {@link TransitionOptions#duration} and {@link TransitionOptions#delay}
+ * will also change the behavior of the symbols fade in/out animation if the placement transition is enabled.
*
* @return TransitionOptions the transition options
*/
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
index acbff20e96..3fa8400eeb 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
@@ -1,8 +1,6 @@
package com.mapbox.mapboxsdk.style.layers;
import android.support.annotation.Keep;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
/**
* Resembles transition property from the style specification.
@@ -15,6 +13,8 @@ public class TransitionOptions {
private long duration;
@Keep
private long delay;
+ @Keep
+ private boolean enablePlacementTransitions;
/**
* Create a transition property based on duration and a delay.
@@ -23,8 +23,21 @@ public class TransitionOptions {
* @param delay the delay to start the transition
*/
public TransitionOptions(long duration, long delay) {
+ this(duration, delay, true);
+ }
+
+ /**
+ * Create a transition property.
+ *
+ * @param duration the duration of the transition
+ * @param delay the delay to start the transition
+ * @param enablePlacementTransitions the flag that describes whether the fade in/out symbol placement transition
+ * should be enabled. Defaults to true.
+ */
+ public TransitionOptions(long duration, long delay, boolean enablePlacementTransitions) {
this.duration = duration;
this.delay = delay;
+ this.enablePlacementTransitions = enablePlacementTransitions;
}
/**
@@ -33,13 +46,31 @@ public class TransitionOptions {
* @param duration the duration of the transition
* @param delay the delay to start the transition
* @return a new transition property object
+ * @deprecated use {@link #fromTransitionOptions(long, long, boolean)} instead
*/
@Keep
+ @Deprecated
public static TransitionOptions fromTransitionOptions(long duration, long delay) {
+ // Invoked from JNI only
return new TransitionOptions(duration, delay);
}
/**
+ * Create a transition property.
+ *
+ * @param duration the duration of the transition
+ * @param delay the delay to start the transition
+ * @param enablePlacementTransitions the flag that describes whether the fade in/out symbol placement transition
+ * should be enabled. Defaults to true.
+ * @return a new transition property object
+ */
+ @Keep
+ static TransitionOptions fromTransitionOptions(long duration, long delay, boolean enablePlacementTransitions) {
+ // Invoked from JNI only
+ return new TransitionOptions(duration, delay, enablePlacementTransitions);
+ }
+
+ /**
* Get the transition duration.
*
* @return the transition duration
@@ -57,8 +88,17 @@ public class TransitionOptions {
return delay;
}
+ /**
+ * Get the flag that describes whether the fade in/out symbol placement transition should be enabled.
+ *
+ * @return true if the fade in/out symbol placement transition should be enabled, false otherwise
+ */
+ public boolean isEnablePlacementTransitions() {
+ return enablePlacementTransitions;
+ }
+
@Override
- public boolean equals(@Nullable Object o) {
+ public boolean equals(Object o) {
if (this == o) {
return true;
}
@@ -71,22 +111,26 @@ public class TransitionOptions {
if (duration != that.duration) {
return false;
}
- return delay == that.delay;
+ if (delay != that.delay) {
+ return false;
+ }
+ return enablePlacementTransitions == that.enablePlacementTransitions;
}
@Override
public int hashCode() {
int result = (int) (duration ^ (duration >>> 32));
result = 31 * result + (int) (delay ^ (delay >>> 32));
+ result = 31 * result + (enablePlacementTransitions ? 1 : 0);
return result;
}
- @NonNull
@Override
public String toString() {
return "TransitionOptions{"
+ "duration=" + duration
+ ", delay=" + delay
+ + ", enablePlacementTransitions=" + enablePlacementTransitions
+ '}';
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt
index 40f74eae22..6958a3519c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt
@@ -12,7 +12,7 @@ import com.mapbox.mapboxsdk.geometry.ProjectedMeters
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
import com.mapbox.mapboxsdk.testapp.utils.TestConstants
-import junit.framework.Assert.assertEquals
+import junit.framework.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -325,6 +325,16 @@ class NativeMapViewTest {
fun testTransitionOptions() {
val transitionOptions = TransitionOptions(500, 500)
nativeMapView.transitionOptions = transitionOptions
+ assertTrue(transitionOptions.isEnablePlacementTransitions)
+ assertEquals(transitionOptions, nativeMapView.transitionOptions)
+ }
+
+ @Test
+ @UiThreadTest
+ fun testTransitionOptions_disablePlacementTransitions() {
+ val transitionOptions = TransitionOptions(500, 500, false)
+ nativeMapView.transitionOptions = transitionOptions
+ assertFalse(transitionOptions.isEnablePlacementTransitions)
assertEquals(transitionOptions, nativeMapView.transitionOptions)
}
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 405ecc5b76..e8bc14c8c2 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -682,13 +682,15 @@ jni::Local<jni::Object<TransitionOptions>> NativeMapView::getTransitionOptions(J
const auto transitionOptions = map->getStyle().getTransitionOptions();
const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.duration.value_or(mbgl::Duration::zero())).count();
const auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.delay.value_or(mbgl::Duration::zero())).count();
- return TransitionOptions::fromTransitionOptions(env, duration, delay);
+ const auto enablePlacementTransitions = (jboolean) transitionOptions.enablePlacementTransitions;
+ return TransitionOptions::fromTransitionOptions(env, duration, delay, enablePlacementTransitions);
}
void NativeMapView::setTransitionOptions(JNIEnv& env, const jni::Object<TransitionOptions>& options) {
const mbgl::style::TransitionOptions transitionOptions(
Duration(mbgl::Milliseconds(TransitionOptions::getDuration(env, options))),
- Duration(mbgl::Milliseconds(TransitionOptions::getDelay(env, options)))
+ Duration(mbgl::Milliseconds(TransitionOptions::getDelay(env, options))),
+ TransitionOptions::isEnablePlacementTransitions(env, options)
);
map->getStyle().setTransitionOptions(transitionOptions);
}
diff --git a/platform/android/src/style/conversion/transition_options.cpp b/platform/android/src/style/conversion/transition_options.cpp
index 66ddc74145..75d9b4cc0d 100644
--- a/platform/android/src/style/conversion/transition_options.cpp
+++ b/platform/android/src/style/conversion/transition_options.cpp
@@ -7,7 +7,8 @@ namespace conversion {
Result<jni::Local<jni::Object<TransitionOptions>>> Converter<jni::Local<jni::Object<TransitionOptions>>, mbgl::style::TransitionOptions>::operator()(jni::JNIEnv& env, const mbgl::style::TransitionOptions& value) const {
return TransitionOptions::fromTransitionOptions(env,
std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())).count(),
- std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())).count()
+ std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())).count(),
+ (jboolean) value.enablePlacementTransitions
);
}
diff --git a/platform/android/src/style/transition_options.cpp b/platform/android/src/style/transition_options.cpp
index 64de3fde8e..d70a04e0d5 100644
--- a/platform/android/src/style/transition_options.cpp
+++ b/platform/android/src/style/transition_options.cpp
@@ -3,10 +3,10 @@
namespace mbgl {
namespace android {
-jni::Local<jni::Object<TransitionOptions>> TransitionOptions::fromTransitionOptions(jni::JNIEnv& env, jlong duration, jlong delay) {
+jni::Local<jni::Object<TransitionOptions>> TransitionOptions::fromTransitionOptions(jni::JNIEnv& env, jlong duration, jlong delay, jboolean enablePlacementTransitions) {
static auto& javaClass = jni::Class<TransitionOptions>::Singleton(env);
- static auto method = javaClass.GetStaticMethod<jni::Object<TransitionOptions> (jlong, jlong)>(env, "fromTransitionOptions");
- return javaClass.Call(env, method, duration, delay);
+ static auto method = javaClass.GetStaticMethod<jni::Object<TransitionOptions> (jlong, jlong, jboolean)>(env, "fromTransitionOptions");
+ return javaClass.Call(env, method, duration, delay, enablePlacementTransitions);
}
long TransitionOptions::getDuration(jni::JNIEnv& env, const jni::Object<TransitionOptions>& transitionOptions) {
@@ -21,6 +21,12 @@ long TransitionOptions::getDelay(jni::JNIEnv& env, const jni::Object<TransitionO
return transitionOptions.Get(env, field);
}
+bool TransitionOptions::isEnablePlacementTransitions(jni::JNIEnv& env, const jni::Object<mbgl::android::TransitionOptions>& transitionOptions) {
+ static auto& javaClass = jni::Class<TransitionOptions>::Singleton(env);
+ static auto field = javaClass.GetField<jboolean >(env, "enablePlacementTransitions");
+ return transitionOptions.Get(env, field);
+}
+
void TransitionOptions::registerNative(jni::JNIEnv& env) {
jni::Class<TransitionOptions>::Singleton(env);
}
diff --git a/platform/android/src/style/transition_options.hpp b/platform/android/src/style/transition_options.hpp
index 5bd0fe9ee7..58656a9463 100644
--- a/platform/android/src/style/transition_options.hpp
+++ b/platform/android/src/style/transition_options.hpp
@@ -11,12 +11,14 @@ class TransitionOptions : private mbgl::util::noncopyable {
public:
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/TransitionOptions"; };
- static jni::Local<jni::Object<TransitionOptions>> fromTransitionOptions(jni::JNIEnv&, jlong duration, jlong offset);
+ static jni::Local<jni::Object<TransitionOptions>> fromTransitionOptions(jni::JNIEnv&, jlong duration, jlong delay, jboolean enablePlacementTransitions);
static long getDuration(jni::JNIEnv&, const jni::Object<TransitionOptions>&);
static long getDelay(jni::JNIEnv&, const jni::Object<TransitionOptions>&);
+ static bool isEnablePlacementTransitions(jni::JNIEnv&, const jni::Object<TransitionOptions>&);
+
static void registerNative(jni::JNIEnv&);
};