Ejemplo n.º 1
0
  public void run() {
    isAnimating = true;
    animation.setAnimating(true);
    shouldLoop = true;

    AnimationPreferences preferences = animation.getPreferences();
    while (shouldLoop) {
      if (Thread.interrupted()) {
        shouldLoop = false;
        break;
      }

      AnimationType animationType = preferences.getType();

      try {
        long delay = preferences.getFrameDelay();
        if (animation.getCurrentIndex() == animation.size() - 1
            || (animationType == AnimationType.ROCK && animation.getCurrentIndex() == 0)) {
          delay = preferences.getLoopDelay();

          if (animationType == AnimationType.STOP || preferences.getFrames() == 1) {
            shouldLoop = false;
            break;
          }
        }

        Thread.sleep(delay);
      } catch (InterruptedException exception) {
        shouldLoop = false;
        break;
      }

      animation.setCurrentIndex(nextAnimationIndex(animationType, isForwardRock));

      if (animation.getCurrentIndex() == animation.size() - 1
          || (animationType == AnimationType.ROCK && animation.getCurrentIndex() == 0)) {
        if (animationType == AnimationType.ROCK) {
          isForwardRock = !isForwardRock;
        } else {
          isForwardRock = true;
        }
      }
    }

    isAnimating = false;
    animation.setAnimating(false);
  }
Ejemplo n.º 2
0
 public void previous() {
   animation.setCurrentIndex(previousDisplayableIndex());
 }
Ejemplo n.º 3
0
 public void next() {
   animation.setCurrentIndex(nextDisplayableIndex());
 }