diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-01-22 15:24:54 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-01-24 14:40:17 +0100 |
commit | 41fa4bda516dd5dbe35c03c30c4e966fc629777a (patch) | |
tree | 619e0ab81633c734f98ffdde89907879c3f252bf /platform/android | |
parent | c1643a03e808b2677dc51713d7a07d7f62823a7a (diff) | |
download | qtlocation-mapboxgl-41fa4bda516dd5dbe35c03c30c4e966fc629777a.tar.gz |
[android] fix CameraAnimatorActivity leaks
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java | 61 |
1 files changed, 28 insertions, 33 deletions
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 48d61abc2a..e278d033be 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 @@ -35,35 +35,30 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe private static final double ANIMATION_DELAY_FACTOR = 1.5; private static final LatLng START_LAT_LNG = new LatLng(37.787947, -122.407432); - private final LongSparseArray<AnimatorBuilder> animators = new LongSparseArray<AnimatorBuilder>() { - { - put(R.id.menu_action_accelerate_decelerate_interpolator, () -> { - AnimatorSet animatorSet = new AnimatorSet(); - animatorSet.playTogether( - createLatLngAnimator(START_LAT_LNG, new LatLng(37.826715, -122.422795)), - obtainExampleInterpolator(new FastOutSlowInInterpolator(), 2500) - ); - return animatorSet; - }); - - put(R.id.menu_action_bounce_interpolator, () -> { - AnimatorSet animatorSet = new AnimatorSet(); - animatorSet.playTogether( - createLatLngAnimator(START_LAT_LNG, new LatLng(37.787947, -122.407432)), - obtainExampleInterpolator(new BounceInterpolator(), 3750) - ); - return animatorSet; - }); - - put(R.id.menu_action_anticipate_overshoot_interpolator, () -> - obtainExampleInterpolator(new AnticipateOvershootInterpolator(), 2500) - ); - - put(R.id.menu_action_path_interpolator, () -> obtainExampleInterpolator( - PathInterpolatorCompat.create(.22f, .68f, 0, 1.71f), 2500)); - } - }; + private final LongSparseArray<Animator> animators = new LongSparseArray<>(); + + { + AnimatorSet accelerateDecelerateAnimatorSet = new AnimatorSet(); + accelerateDecelerateAnimatorSet.playTogether( + createLatLngAnimator(START_LAT_LNG, new LatLng(37.826715, -122.422795)), + obtainExampleInterpolator(new FastOutSlowInInterpolator(), 2500) + ); + animators.put(R.id.menu_action_accelerate_decelerate_interpolator, accelerateDecelerateAnimatorSet); + AnimatorSet bounceAnimatorSet = new AnimatorSet(); + bounceAnimatorSet.playTogether( + createLatLngAnimator(START_LAT_LNG, new LatLng(37.787947, -122.407432)), + obtainExampleInterpolator(new BounceInterpolator(), 3750) + ); + animators.put(R.id.menu_action_bounce_interpolator, bounceAnimatorSet); + + animators.put(R.id.menu_action_anticipate_overshoot_interpolator, + obtainExampleInterpolator(new AnticipateOvershootInterpolator(), 2500) + ); + + animators.put(R.id.menu_action_path_interpolator, obtainExampleInterpolator( + PathInterpolatorCompat.create(.22f, .68f, 0, 1.71f), 2500)); + } private MapView mapView; private MapboxMap mapboxMap; @@ -161,7 +156,7 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe // private Animator obtainExampleInterpolator(int menuItemId) { - return animators.get(menuItemId).build(); + return animators.get(menuItemId); } @Override @@ -198,6 +193,7 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe private void playAnimation(int itemId) { Animator animator = obtainExampleInterpolator(itemId); if (animator != null) { + animator.cancel(); animator.start(); } } @@ -238,6 +234,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe protected void onStop() { super.onStop(); mapView.onStop(); + for (int i = 0; i < animators.size(); i++) { + animators.get(animators.keyAt(i)).cancel(); + } } @Override @@ -274,8 +273,4 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe return latLng; } } - - interface AnimatorBuilder { - Animator build(); - } } |