Пример #1
0
  private int nextAnimationIndex(
      AnimationType animationType, boolean isForwardRock, int currentIndex) {
    switch (animationType) {
      case LOOP:
        {
          return nextDisplayableIndex();
        }

      case STOP:
        {
          return nextDisplayableIndex();
        }

      case ROCK:
        {
          if ((isForwardRock && animation.getCurrentIndex() != animation.size())
              || animation.getCurrentIndex() == 0) {
            return nextDisplayableIndex();
          }

          return previousDisplayableIndex();
        }

      default:
        {
          return 0;
        }
    }
  }
Пример #2
0
  private int nextDisplayableIndex() {
    AnimationType animationType = animation.getPreferences().getType();
    int nextIndex = nextIndex();

    // Skip images set to not display
    for (@SuppressWarnings("unused") int index = 0;
        !animation.getRadarGroups().get(nextIndex).shouldDisplay();
        nextIndex = nextAnimationIndex(animationType, isForwardRock, nextIndex)) ;

    return nextIndex;
  }
Пример #3
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);
  }
Пример #4
0
  private int nextIndex(int currentIndex) {
    int nextIndex = currentIndex + 1;
    if (nextIndex > animation.size() - 1) {
      nextIndex = 0;
    }

    return nextIndex;
  }
Пример #5
0
  private int previousDisplayableIndex() {
    int previousIndex = previousIndex();

    // Skip images set to not display
    for (@SuppressWarnings("unused") int index = 0;
        !animation.getRadarGroups().get(previousIndex).shouldDisplay();
        previousIndex = previousIndex(previousIndex)) ;

    return previousIndex;
  }
Пример #6
0
  private int previousIndex(int currentIndex) {
    int previousIndex = currentIndex - 1;
    if (previousIndex < 0) {
      previousIndex = animation.size() - 1;
    }

    if (previousIndex < 0) {
      previousIndex = 0;
    }

    return previousIndex;
  }
Пример #7
0
 private int nextAnimationIndex(AnimationType animationType, boolean isForwardRock) {
   return nextAnimationIndex(animationType, isForwardRock, animation.getCurrentIndex());
 }
Пример #8
0
 public void previous() {
   animation.setCurrentIndex(previousDisplayableIndex());
 }
Пример #9
0
 public void next() {
   animation.setCurrentIndex(nextDisplayableIndex());
 }
Пример #10
0
 private int nextIndex() {
   return nextIndex(animation.getCurrentIndex());
 }
Пример #11
0
 private int previousIndex() {
   return previousIndex(animation.getCurrentIndex());
 }