[android] expose symbol placement transition duration option
This commit is contained in:
committed by
Łukasz Paczos
parent
e45c3926c2
commit
8ad13cd577
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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,12 +46,30 @@ 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.
|
||||
*
|
||||
@@ -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
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user