diff --git a/lib/src/android/support/design/widget/FloatingActionButtonImplLollipop.java b/lib/src/android/support/design/widget/FloatingActionButtonImplLollipop.java index 18c93297b..b28b6bdf5 100644 --- a/lib/src/android/support/design/widget/FloatingActionButtonImplLollipop.java +++ b/lib/src/android/support/design/widget/FloatingActionButtonImplLollipop.java @@ -16,6 +16,7 @@ package android.support.design.widget; +import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.StateListAnimator; @@ -31,6 +32,8 @@ import android.os.Build; import android.support.annotation.RequiresApi; import android.support.v4.graphics.drawable.DrawableCompat; import android.view.View; +import java.util.ArrayList; +import java.util.List; @RequiresApi(21) class FloatingActionButtonImplLollipop extends FloatingActionButtonImpl { @@ -119,15 +122,20 @@ class FloatingActionButtonImplLollipop extends FloatingActionButtonImpl { // Animate translationZ to 0 if not pressed set = new AnimatorSet(); - set.playSequentially( - ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0), - // This is a no-op animation which exists here only for introducing the duration - // because setting the delay (on the next animation) via "setDelay" or "after" - // can trigger a NPE between android versions 22 and 24 (due to a framework - // bug). The issue has been fixed in version 25. - ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()) - .setDuration(PRESSED_ANIM_DELAY), + List animators = new ArrayList<>(); + animators.add(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)); + if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) { + // This is a no-op animation which exists here only for introducing the duration + // because setting the delay (on the next animation) via "setDelay" or "after" + // can trigger a NPE between android versions 22 and 24 (due to a framework + // bug). The issue has been fixed in version 25. + animators.add( + ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()) + .setDuration(PRESSED_ANIM_DELAY)); + } + animators.add( ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION)); + set.playSequentially(animators.toArray(new Animator[0])); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(ENABLED_STATE_SET, set);