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

[android] - Style wide transition options in milliseconds #8576

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to

5.1.0 builds further on 5.0.1 and adds:

* Style wide transition duration and transition offset in milliseconds [#8576](https://github.com/mapbox/mapbox-gl-native/pull/8576)
* LatLngBounds includes with another bounds [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517)
* LatLngBounds includes takes in account LatLng on the edges (cfr. core) [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517)
* LatLngBounds facility getters/setters for LatLnbg on the edges of the bounds [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void onUpdateFullyRendered() {
* </p>
* The default value is zero, so any changes take effect without animation.
*
* @return Duration in seconds
* @return Duration in milliseconds
*/
@UiThread
public long getTransitionDuration() {
Expand All @@ -204,11 +204,11 @@ public long getTransitionDuration() {
/**
* Set the animation duration for style changes.
*
* @param duration Duration in seconds
* @param durationMs Duration in milliseconds
*/
@UiThread
public void setTransitionDuration(long duration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we consider this a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use java.time.Duration for durations and avoid unit bugs through type safety?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ivo mentioned the same on chat regards using Duration from joda.time, will ticket it out.

nativeMapView.setTransitionDuration(duration);
public void setTransitionDuration(long durationMs) {
nativeMapView.setTransitionDuration(durationMs);
}

/**
Expand All @@ -217,7 +217,7 @@ public void setTransitionDuration(long duration) {
* </p>
* The default value is zero, so any changes begin to animate immediately.
*
* @return Delay in seconds
* @return Delay in milliseconds
*/
@UiThread
public long getTransitionDelay() {
Expand All @@ -227,11 +227,11 @@ public long getTransitionDelay() {
/**
* Set the animation delay for style changes.
*
* @param delay Delay in seconds
* @param delayMs Delay in milliseconds
*/
@UiThread
public void setTransitionDelay(long delay) {
nativeMapView.setTransitionDelay(delay);
public void setTransitionDelay(long delayMs) {
nativeMapView.setTransitionDelay(delayMs);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@ public void testSanity() {
assertNotNull("mapboxMap should not be null", mapboxMap);
}

//
// Style wide transition options
//

@Test
public void testTransitionDuration() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
final MapboxMap mapboxMap = activity.getMapboxMap();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
long transitionDuration = 600;
mapboxMap.setTransitionDuration(transitionDuration);
assertEquals("TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0);
}
}));
}

@Test
public void testTransitionDelay() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
final MapboxMap mapboxMap = activity.getMapboxMap();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
long transitionDelay = 50;
mapboxMap.setTransitionDelay(transitionDelay);
assertEquals("TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0);
}
}));
}

//
// MinZoomLevel
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ private void setBackgroundOpacity() {
private void setWaterColor() {
Layer water = mapboxMap.getLayer("water");
if (water != null) {
mapboxMap.setTransitionDuration(5);
mapboxMap.setTransitionDelay(1);
mapboxMap.setTransitionDuration(5000);
mapboxMap.setTransitionDelay(1000);
water.setProperties(
visibility(VISIBLE),
fillColor(Color.RED)
Expand Down
8 changes: 4 additions & 4 deletions platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,23 +752,23 @@ jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, jni::S

jlong NativeMapView::getTransitionDuration(JNIEnv&) {
const auto transitionOptions = map->getTransitionOptions();
return transitionOptions.duration.value_or(mbgl::Duration::zero()).count();
return std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.duration.value_or(mbgl::Duration::zero())).count();
}

void NativeMapView::setTransitionDuration(JNIEnv&, jlong duration) {
auto transitionOptions = map->getTransitionOptions();
transitionOptions.duration = std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<jlong>(duration));
transitionOptions.duration.emplace(mbgl::Milliseconds(duration));
map->setTransitionOptions(transitionOptions);
}

jlong NativeMapView::getTransitionDelay(JNIEnv&) {
const auto transitionOptions = map->getTransitionOptions();
return transitionOptions.delay.value_or(mbgl::Duration::zero()).count();
return std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.delay.value_or(mbgl::Duration::zero())).count();
}

void NativeMapView::setTransitionDelay(JNIEnv&, jlong delay) {
auto transitionOptions = map->getTransitionOptions();
transitionOptions.delay = std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<jlong>(delay));
transitionOptions.delay.emplace(mbgl::Milliseconds(delay));
map->setTransitionOptions(transitionOptions);
}

Expand Down