Friday, December 20, 2013

To stop animator determitively, nineoldandroid's Animator.end() is not enough.




Requirements

  1. Animators sometimes should be stopped onPause
  2. The status of properties that animators have been changing should be known to us (activity(?)). It should be determinable.


I wanted to pause animators. And, I used the nineoldandroids for the back compatibility.

If you cancel the animator, you may not be sure that the properties of View are changed for which amount.
This often yields various bugs.

voidcancel()
Cancels the animation.

So, I wanted to

voidend()
Ends the animation.Note that ending a AnimatorSet also ends all of the animations that it is responsible for.


I tried calling animator.end() by hand, but, property value callback was not called
even though nineoldandroids has the mechanism to call child animators of AnimatorSet.

  334
             if (.size() > 0) {
335
                 for (Node node : ) {
336
                     node.animation.end();
337
                 }
338
             }


I'm not sure it's not working for both Android Animator and Animation,

Anyway, I used an workaround of setDuration(0).
If I call animator.setDuration(0), it will be finished soon. But, I'm not sure that it will be finished on the same (UI) thread in the same call stack.

You should know the original duration value since you should roll back the duration after the animator ended.

But, getDuration may not be working... ( for the nineoldandroid only?)
Durations should be set on the AnimatorSet (root animator).
Otherwise, animatorSet.getDuration() returns -1.
And, objectAnimator's duration should be set, too, to support this animation on android 2.*.
<set xmlns:android="http://schemas.android.com/apk/res/android"     android:duration="200" >
    <objectAnimator
        android:duration="200"

longgetDuration()
Gets the length of each of the child animations of this AnimatorSet.
abstract AnimatorsetDuration(long duration)
Sets the duration of the animation.


Maybe, you should roll back the duration value of the original animator even though you a cloned animator.
I don't know why.

AnimatorSetclone()
Creates and returns a copy of this Object.






No comments:

Post a Comment