diff --git a/src/org/ntlab/animations/MagnetRONAnimation.java b/src/org/ntlab/animations/MagnetRONAnimation.java index 42379dd..f73128c 100644 --- a/src/org/ntlab/animations/MagnetRONAnimation.java +++ b/src/org/ntlab/animations/MagnetRONAnimation.java @@ -179,7 +179,7 @@ STOPPED } -// private static int animationCount = 0; + private static int animationCount = 0; /** * The constructor of {@code MagnetRONAnimation}. @@ -364,16 +364,16 @@ updateCurrentCycle(getCurrentCycleCount()); jumpTo(getCurrentCycleCount()); } else if(Math.abs(getCurrentCycleCount()) >= Math.abs(getTotalCycleCount())){ -// animationCount = 0; -// System.out.println(TAG + ": animationCount=" + animationCount); + animationCount = 0; + System.out.println(TAG + ": animationCount=" + animationCount); onFinished(); } } }, getInitialDelay(), getDelay(), TimeUnit.MILLISECONDS); setScheduledFuture(scheduledFuture); setCurrentStatus(Status.RUNNING); -// animationCount = 1; -// System.out.println(TAG + ": animationCount=" + animationCount); + animationCount = 1; + System.out.println(TAG + ": animationCount=" + animationCount); }; break; case PAUSED: @@ -388,22 +388,28 @@ }; } -// public static void waitAnimationEnd() { -// while (animationCount > 0) { -// try { -// Thread.sleep(1L); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } -// // Buffer for another waiting animation. -// try { -// Thread.sleep(30L); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } + /** + * Sleep main thread and wait for {@link MagnetRONAnimation#play()} to finish running. + */ + public static void waitAnimationEnd() { + while (animationCount > 0) { + try { + Thread.sleep(1L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // Buffer for another waiting animation. + try { + Thread.sleep(30L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + /** + * Play animation in sync with main thread. + */ public void syncPlay() { if (getCurrentStatus() == Status.STOPPED) { try {