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

Commit

Permalink
[android] - transition options in milliseconds, added test cases, fix…
Browse files Browse the repository at this point in the history
…up test activity code
  • Loading branch information
tobrun committed Mar 30, 2017
1 parent 1616140 commit 3238dc4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
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) {
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

0 comments on commit 3238dc4

Please sign in to comment.