Pergunta

I have trouble with animations in my application and the fact that the system time can be changed. I create animator object this way :

animator = new Animator(600, Animator.INFINITE, Animator.RepeatBehavior.REVERSE, setter);

The setter is an alpha property that is varying from 0.0 to 1.0. The problem is that whenever i change the system time, the animation stops/blocks. It restarts sometimes after a while, depending on the system time i set. Is there a way that i can fix this ? Thanks a lot.

Foi útil?

Solução

Put in a Timer and schedule to work during the same time duration of the animator (timer's run method will instantiate the animator object). So whenever the animator stops it will be re-instantiated like the following way:
The timer methods check if the animator is working or not, and when the answer is negative, it will instantiate another animator with the same parameters but only to animate in a period time duration equal to the remaining time.

Code example:

public void execute() {
start();
timer_.scheduleRepeating(100);
}

public void start() {
    timer_ = new Timer() {
       public void run() {
        update();
        }
    };
}


public void update() {
    if (time > neededTime) {
        timer_.cancel();
    }else {
      if(!animator) {  //needs some optimization
        animator = new Animator( ....
      }
    }   
 }  
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top