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

Add interpolator examples #10067

Merged
merged 1 commit into from
Oct 12, 2017
Merged

Add interpolator examples #10067

merged 1 commit into from
Oct 12, 2017

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented Sep 26, 2017

This PR adds a couple of examples around using animators and interpolators.

ezgif com-video-to-gif 28

cc @mapbox/android

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Sep 26, 2017
@tobrun tobrun added this to the android-v5.2.0 milestone Sep 26, 2017
@tobrun tobrun self-assigned this Sep 26, 2017
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

These examples are awesome 👏

Minor details.

}
findViewById(R.id.fab).setVisibility(View.GONE);

// reset camera to init position
Copy link
Contributor

Choose a reason for hiding this comment

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

What about extracting this block of code into a private method and give it a name based on the comment? This way onOptionsItemSelected will be easier to read and understand and comment will become superfluous so it won't be necessary.

.build()
));

// play animation
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here ☝️

}

private Animator createExamepleInterpolator(int menuItemId) {
switch (menuItemId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about removing the switch using a map/dictionary? AnimatorSets could be created beforehand and inserted into a map using the different menu ids as values.

@Guardiola31337
Copy link
Contributor

@tobrun I found a crash when testing these examples when clicking the different options back and forth

logcat

 --------- beginning of crash
10-04 18:56:18.407 30067-31017/com.mapbox.mapboxsdk.testapp A/libc: heap corruption detected by dlfree
10-04 18:56:18.407 30067-31017/com.mapbox.mapboxsdk.testapp A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 31017 (GLThread 3369)
10-04 18:56:18.443 356-568/? I/MDMCTBK: NetlinkHandler, power_supply subsys
10-04 18:56:18.443 356-568/? I/MDMCTBK: NetlinkHandler, usbChargerStateChanged
10-04 18:56:18.443 356-568/? I/MDMCTBK: checkDefaultInst, current pid is = 356
10-04 18:56:18.443 356-568/? I/MDMCTBK: checkDefaultInst, pid match
10-04 18:56:18.443 356-568/? I/MDMCTBK: MdmCutbackHndler,readFromFile = /sys/class/power_supply/usb/online
10-04 18:56:18.443 356-568/? I/MDMCTBK: MdmCutbackHndler,readFromFile = /sys/class/power_supply/qpnp-dc/online
10-04 18:56:18.443 927-1277/? D/BatteryService: uevent={POWER_SUPPLY_TEMP=324, POWER_SUPPLY_STATUS=Charging, POWER_SUPPLY_CAPACITY=88, ACTION=change, DEVPATH=/devices/qpnp-charger-ed20e400/power_supply/battery, POWER_SUPPLY_VOLTAGE_OCV=-22, POWER_SUPPLY_ONLINE=1, SUBSYSTEM=power_supply, POWER_SUPPLY_NUM_SYSTEM_TEMP_LEVELS=17, POWER_SUPPLY_INPUT_CURRENT_MAX=500000, POWER_SUPPLY_VOLTAGE_MAX_DESIGN=4350000, POWER_SUPPLY_CHARGE_FULL=2270000, POWER_SUPPLY_NAME=battery, POWER_SUPPLY_VOLTAGE_MIN_DESIGN=4300000, POWER_SUPPLY_VOLTAGE_MIN=4300000, POWER_SUPPLY_HEALTH=Good, POWER_SUPPLY_CYCLE_COUNT=0, POWER_SUPPLY_TECHNOLOGY=Li-ion, POWER_SUPPLY_CHARGE_TYPE=Fast, POWER_SUPPLY_PRESENT=1, POWER_SUPPLY_INPUT_CURRENT_SETTLED=0, POWER_SUPPLY_MODEL_NAME=EY30-LG, POWER_SUPPLY_VOLTAGE_NOW=4165027, SEQNUM=265628, POWER_SUPPLY_TEMP_WARM=450, POWER_SUPPLY_TEMP_COOL=0, POWER_SUPPLY_CHARGE_FULL_DESIGN=2281000, POWER_SUPPLY_CURRENT_NOW=-64443, POWER_SUPPLY_CHARGE_COUNTER=-1210256, POWER_SUPPLY_SYSTEM_TEMP_LEVEL=0, POWER_SUPPLY_INPUT_CURRENT_TRIM=36, POWER_SUPPLY_VOLTAGE_EMPTY=3000000, POWER_SUPPLY_CHARGE_RATE=Normal, POWER_SUPPLY_INPUT_VOLTAGE_REGULATION=1, POWER_SUPPLY_CHARGING_ENABLED=1}
10-04 18:56:18.510 20076-20076/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-04 18:56:18.511 20076-20076/? I/DEBUG: Build fingerprint: 'motorola/victara_reteu/victara:5.0/LXE22.46-19/18:user/release-keys'
10-04 18:56:18.511 20076-20076/? I/DEBUG: Revision: 'p2bf'
10-04 18:56:18.511 20076-20076/? I/DEBUG: ABI: 'arm'
10-04 18:56:18.511 20076-20076/? I/DEBUG: pid: 30067, tid: 31017, name: GLThread 3369  >>> com.mapbox.mapboxsdk.testapp <<<
10-04 18:56:18.512 20076-20076/? I/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
10-04 18:56:18.586 20076-20076/? I/DEBUG: Abort message: 'heap corruption detected by dlfree'
10-04 18:56:18.586 20076-20076/? I/DEBUG:     r0 00000000  r1 00007929  r2 00000006  r3 00000000
10-04 18:56:18.586 20076-20076/? I/DEBUG:     r4 a07a6dd8  r5 00000006  r6 0000000b  r7 0000010c
10-04 18:56:18.587 20076-20076/? I/DEBUG:     r8 b6f340f4  r9 00000001  sl a07a5f90  fp b92ec7a4
10-04 18:56:18.587 20076-20076/? I/DEBUG:     ip 00007929  sp a07a2b88  lr b6eee681  pc b6f1422c  cpsr 60070010
10-04 18:56:18.587 20076-20076/? I/DEBUG: backtrace:
10-04 18:56:18.587 20076-20076/? I/DEBUG:     #00 pc 0003c22c  /system/lib/libc.so (tgkill+12)
10-04 18:56:18.587 20076-20076/? I/DEBUG:     #01 pc 0001667d  /system/lib/libc.so (pthread_kill+52)
10-04 18:56:18.587 20076-20076/? I/DEBUG:     #02 pc 0001728f  /system/lib/libc.so (raise+10)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #03 pc 00013ae1  /system/lib/libc.so (__libc_android_abort+36)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #04 pc 00012264  /system/lib/libc.so (abort+4)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #05 pc 00014dab  /system/lib/libc.so (__libc_fatal+16)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #06 pc 00029059  /system/lib/libc.so (__bionic_heap_corruption_error+8)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #07 pc 0002b0cd  /system/lib/libc.so (dlfree+312)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #08 pc 00011fcf  /system/lib/libc.so (free+10)
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #09 pc 00018eab  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.588 20076-20076/? I/DEBUG:     #10 pc 004c9b89  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.591 20076-20076/? I/DEBUG:     #11 pc 004c9b69  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.591 20076-20076/? I/DEBUG:     #12 pc 004c9ae7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #13 pc 004c9a75  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #14 pc 004c98d7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #15 pc 004c9895  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #16 pc 004c6e69  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #17 pc 00526411  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #18 pc 00526431  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #19 pc 00524103  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #20 pc 00597539  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #21 pc 00444147  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #22 pc 001f552f  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #23 pc 001ecaa1  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #24 pc 000f84d3  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #25 pc 000fddc7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #26 pc 000fdd5d  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.592 20076-20076/? I/DEBUG:     #27 pc 000fdd25  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.593 20076-20076/? I/DEBUG:     #28 pc 000fde51  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.593 20076-20076/? I/DEBUG:     #29 pc 000fde11  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so
10-04 18:56:18.593 20076-20076/? I/DEBUG:     #30 pc 001819a3  /data/dalvik-cache/arm/data@app@com.mapbox.mapboxsdk.testapp-1@base.apk@classes.dex

Symbolicated Android crash

Crash dump is completed

********** Crash dump: **********
Build fingerprint: 'motorola/victara_reteu/victara:5.0/LXE22.46-19/18:user/release-keys'
pid: 30067, tid: 31017, name: GLThread 3369  >>> com.mapbox.mapboxsdk.testapp <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Stack frame #00 pc 0003c22c  /system/lib/libc.so (tgkill+12)
Stack frame #01 pc 0001667d  /system/lib/libc.so (pthread_kill+52)
Stack frame #02 pc 0001728f  /system/lib/libc.so (raise+10)
Stack frame #03 pc 00013ae1  /system/lib/libc.so (__libc_android_abort+36)
Stack frame #04 pc 00012264  /system/lib/libc.so (abort+4)
Stack frame #05 pc 00014dab  /system/lib/libc.so (__libc_fatal+16)
Stack frame #06 pc 00029059  /system/lib/libc.so (__bionic_heap_corruption_error+8)
Stack frame #07 pc 0002b0cd  /system/lib/libc.so (dlfree+312)
Stack frame #08 pc 00011fcf  /system/lib/libc.so (free+10)
Stack frame #09 pc 00018eab  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine std::__ndk1::__deallocate(void*) at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/new:176
Stack frame #10 pc 004c9b89  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~IndexedSubfeature at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../src/mbgl/geometry/feature_index.hpp:20
Stack frame #11 pc 004c9b69  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~__tuple_leaf at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/tuple:183
Stack frame #12 pc 004c9ae7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine std::__ndk1::allocator<std::__ndk1::pair<mbgl::IndexedSubfeature, mapbox::geometry::box<short> > >::destroy(std::__ndk1::pair<mbgl::IndexedSubfeature, mapbox::geometry::box<short> >*) at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1801
Stack frame #13 pc 004c9a75  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~vector at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/iterator:1254
Stack frame #14 pc 004c98d7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~GridIndex at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../src/mbgl/util/grid_index.hpp:13
Stack frame #15 pc 004c9895  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~FeatureIndex at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../src/mbgl/geometry/feature_index.hpp:29
Stack frame #16 pc 004c6e69  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine std::__ndk1::default_delete<mbgl::FeatureIndex>::operator()(mbgl::FeatureIndex*) const at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:2540
Stack frame #17 pc 00526411  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~VectorTile at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../src/mbgl/tile/vector_tile.hpp:11
Stack frame #18 pc 00526431  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine ~VectorTile at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../src/mbgl/tile/vector_tile.hpp:11
Stack frame #19 pc 00524103  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine std::__ndk1::default_delete<mbgl::Tile>::operator()(mbgl::Tile*) const at /Users/pguardiola/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:2540
Stack frame #20 pc 00597539  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine mbgl::TilePyramid::update(std::__ndk1::vector<mbgl::Immutable<mbgl::style::Layer::Impl>, std::__ndk1::allocator<mbgl::Immutable<mbgl::style::Layer::Impl> > > const&, bool, bool, mbgl::TileParameters const&, mbgl::SourceType, unsigned short, mbgl::Range<unsigned char>, std::__ndk1::function<std::__ndk1::unique_ptr<mbgl::Tile, std::__ndk1::default_delete<mbgl::Tile> > (mbgl::OverscaledTileID const&)>) at /Users/pguardiola/mapbox/mapbox-gl-native/src/mbgl/renderer/tile_pyramid.cpp:183
Stack frame #21 pc 00444147  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine mbgl::RenderVectorSource::update(mbgl::Immutable<mbgl::style::Source::Impl>, std::__ndk1::vector<mbgl::Immutable<mbgl::style::Layer::Impl>, std::__ndk1::allocator<mbgl::Immutable<mbgl::style::Layer::Impl> > > const&, bool, bool, mbgl::TileParameters const&) at /Users/pguardiola/mapbox/mapbox-gl-native/src/mbgl/renderer/sources/render_vector_source.cpp:51
Stack frame #22 pc 001f552f  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine mbgl::Renderer::Impl::render(mbgl::UpdateParameters const&) at /Users/pguardiola/mapbox/mapbox-gl-native/src/mbgl/renderer/renderer_impl.cpp:234
Stack frame #23 pc 001ecaa1  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine mbgl::Renderer::render(mbgl::UpdateParameters const&) at /Users/pguardiola/mapbox/mapbox-gl-native/src/mbgl/renderer/renderer.cpp:32
Stack frame #24 pc 000f84d3  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine mbgl::android::MapRenderer::render(_JNIEnv&) at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/src/map_renderer.cpp:130
Stack frame #25 pc 000fddc7  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine operator() at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:245
Stack frame #26 pc 000fdd5d  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine operator() at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:112
Stack frame #27 pc 000fdd25  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine __invoke at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:110
Stack frame #28 pc 000fde51  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine operator()<jni::jobject *> at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:59
Stack frame #29 pc 000fde11  /data/app/com.mapbox.mapboxsdk.testapp-1/lib/arm/libmapbox-gl.so: Routine __invoke<jni::jobject *> at /Users/pguardiola/mapbox/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/armeabi-v7a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:55
Stack frame #30 pc 001819a3  /data/dalvik-cache/arm/data@app@com.mapbox.mapboxsdk.testapp-1@base.apk@classes.dex

Moto X (2nd gen) Android 5.0

}

private Animator createExamepleInterpolator(int menuItemId) {
switch (menuItemId) {
Copy link
Contributor

@Guardiola31337 Guardiola31337 Oct 4, 2017

Choose a reason for hiding this comment

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

I was thinking something like this

diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java
index 134086145..c6e3c7a05 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java
@@ -25,6 +25,9 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
 import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
 import com.mapbox.mapboxsdk.testapp.R;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Test activity showcasing using Android SDK animators to animate camera position changes.
  */
@@ -206,27 +209,50 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe
     }
   }
 
-  private Animator createExamepleInterpolator(int menuItemId) {
-    switch (menuItemId) {
-      case R.id.menu_action_accelerate_decelerate_interpolator:
-        AnimatorSet animatorSet = new AnimatorSet();
-        animatorSet.playTogether(
-          createLatLngAnimator(START_LAT_LNG, new LatLng(37.826715, -122.422795)),
-          createExampleInterpolator(new FastOutSlowInInterpolator(), 2500));
-        return animatorSet;
-      case R.id.menu_action_bounce_interpolator:
-        AnimatorSet bounceAnimatorSet = new AnimatorSet();
-        bounceAnimatorSet.playTogether(
-          createLatLngAnimator(START_LAT_LNG, new LatLng(37.787947, -122.407432)),
-          createExampleInterpolator(new BounceInterpolator(), 3750)
-        );
-        return bounceAnimatorSet;
-      case R.id.menu_action_anticipate_overshoot_interpolator:
-        return createExampleInterpolator(new AnticipateOvershootInterpolator(), 2500);
-      case R.id.menu_action_path_interpolator:
-        return createExampleInterpolator(PathInterpolatorCompat.create(.22f, .68f, 0, 1.71f), 2500);
+  private final Map<Integer, AnimatorBuilder> ANIMATORS = new HashMap<Integer, AnimatorBuilder>() {
+    {
+      put(R.id.menu_action_accelerate_decelerate_interpolator, new AnimatorBuilder() {
+        @Override
+        public Animator build() {
+          AnimatorSet animatorSet = new AnimatorSet();
+          animatorSet.playTogether(
+            createLatLngAnimator(START_LAT_LNG, new LatLng(37.826715, -122.422795)),
+            createExampleInterpolator(new FastOutSlowInInterpolator(), 2500));
+          return animatorSet;
+        }
+      });
+      put(R.id.menu_action_bounce_interpolator, new AnimatorBuilder() {
+        @Override
+        public Animator build() {
+          AnimatorSet bounceAnimatorSet = new AnimatorSet();
+          bounceAnimatorSet.playTogether(
+            createLatLngAnimator(START_LAT_LNG, new LatLng(37.787947, -122.407432)),
+            createExampleInterpolator(new BounceInterpolator(), 3750)
+          );
+          return bounceAnimatorSet;
+        }
+      });
+      put(R.id.menu_action_anticipate_overshoot_interpolator, new AnimatorBuilder() {
+        @Override
+        public Animator build() {
+          return createExampleInterpolator(new AnticipateOvershootInterpolator(), 2500);
+        }
+      });
+      put(R.id.menu_action_path_interpolator, new AnimatorBuilder() {
+        @Override
+        public Animator build() {
+          return createExampleInterpolator(PathInterpolatorCompat.create(.22f, .68f, 0, 1.71f), 2500);
+        }
+      });
     }
-    return null;
+  };
+
+  interface AnimatorBuilder {
+    Animator build();
+  }
+
+  private Animator createExamepleInterpolator(int menuItemId) {
+    return ANIMATORS.get(menuItemId).build();
   }
 
   private Animator createExampleInterpolator(Interpolator interpolator, long duration) {

What do you think @tobrun?

@tobrun tobrun changed the base branch from master to release-agua October 10, 2017 10:38
@tobrun
Copy link
Member Author

tobrun commented Oct 10, 2017

@Guardiola31337 neat, has been adapted, additionally changed target branch to release-agua.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

One minor detail.
These examples are awesome 🚀


private final LatLng latLng = new LatLng();
private Animator createExampleInterpolator(int menuItemId) {
Copy link
Contributor

@Guardiola31337 Guardiola31337 Oct 10, 2017

Choose a reason for hiding this comment

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

One minor thing, what about changing the name of the method here to obtainExampleAnimator(int menuItemId) instead? We're not actually creating the animators here and there's another method with the same exact name (createExampleInterpolator(Interpolator interpolator, long duration)) which makes it kinda confusing.

@tobrun tobrun merged commit 56446c5 into release-agua Oct 12, 2017
@tobrun tobrun deleted the tvn-interpolator-example branch October 12, 2017 11:56
@Guardiola31337 Guardiola31337 mentioned this pull request Oct 19, 2017
20 tasks
@Guardiola31337 Guardiola31337 mentioned this pull request Oct 26, 2017
20 tasks
@tobrun tobrun mentioned this pull request Nov 3, 2017
21 tasks
This was referenced Nov 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants