/** * Iterate over all animations and update them. */ private void updateAnimations() { // Copy the animation requests to avoid concurrent modifications. AnimationHandleImpl[] curAnimations = new AnimationHandleImpl[animationRequests.size()]; curAnimations = animationRequests.toArray(curAnimations); // Iterate over the animation requests. Duration duration = new Duration(); for (AnimationHandleImpl requestId : curAnimations) { // Remove the current request. animationRequests.remove(requestId); // Execute the callback. requestId.getCallback().execute(duration.getStartMillis()); } // Reschedule the timer if there are more animation requests. if (animationRequests.size() > 0) { /* * In order to achieve as close to 60fps as possible, we calculate the new * delay based on the execution time of this method. The delay will be * less than 16ms, assuming this method takes more than 1ms to complete. */ timer.schedule(Math.max(MIN_FRAME_DELAY, DEFAULT_FRAME_DELAY - duration.elapsedMillis())); } } }
animationCallback.execute(startTime);
animationCallback.execute(startTime);
/** * Run this animation at the given startTime. If the startTime has already * passed, the animation will run synchronously as if it started at the * specified start time. If the animation is already running, it will be * canceled first. * <p> * If the element is not <code>null</code>, the {@link #onUpdate(double)} * method might be called only if the element may be visible (generally left * at the appreciation of the browser). Otherwise, it will be called * unconditionally. * * @param duration the duration of the animation in milliseconds * @param startTime the synchronized start time in milliseconds * @param element the element that visually bounds the entire animation */ public void run(int duration, double startTime, Element element) { // Cancel the animation if it is running cancel(); // Save the duration and startTime isRunning = true; isStarted = false; this.duration = duration; this.startTime = startTime; this.element = element; ++runId; // Execute the first callback. callback.execute(Duration.currentTimeMillis()); }
/** * Iterate over all animations and update them. */ private void updateAnimations() { // Copy the animation requests to avoid concurrent modifications. AnimationHandleImpl[] curAnimations = new AnimationHandleImpl[animationRequests.size()]; curAnimations = animationRequests.toArray(curAnimations); // Iterate over the animation requests. Duration duration = new Duration(); for (AnimationHandleImpl requestId : curAnimations) { // Remove the current request. animationRequests.remove(requestId); // Execute the callback. requestId.getCallback().execute(duration.getStartMillis()); } // Reschedule the timer if there are more animation requests. if (animationRequests.size() > 0) { /* * In order to achieve as close to 60fps as possible, we calculate the new * delay based on the execution time of this method. The delay will be * less than 16ms, assuming this method takes more than 1ms to complete. */ timer.schedule(Math.max(MIN_FRAME_DELAY, DEFAULT_FRAME_DELAY - duration.elapsedMillis())); } } }
/** * Iterate over all animations and update them. */ private void updateAnimations() { // Copy the animation requests to avoid concurrent modifications. AnimationHandleImpl[] curAnimations = new AnimationHandleImpl[animationRequests.size()]; curAnimations = animationRequests.toArray(curAnimations); // Iterate over the animation requests. Duration duration = new Duration(); for (AnimationHandleImpl requestId : curAnimations) { // Remove the current request. animationRequests.remove(requestId); // Execute the callback. requestId.getCallback().execute(duration.getStartMillis()); } // Reschedule the timer if there are more animation requests. if (animationRequests.size() > 0) { /* * In order to achieve as close to 60fps as possible, we calculate the new * delay based on the execution time of this method. The delay will be * less than 16ms, assuming this method takes more than 1ms to complete. */ timer.schedule(Math.max(MIN_FRAME_DELAY, DEFAULT_FRAME_DELAY - duration.elapsedMillis())); } } }
/** * Run this animation at the given startTime. If the startTime has already * passed, the animation will run synchronously as if it started at the * specified start time. If the animation is already running, it will be * canceled first. * <p> * If the element is not <code>null</code>, the {@link #onUpdate(double)} * method might be called only if the element may be visible (generally left * at the appreciation of the browser). Otherwise, it will be called * unconditionally. * * @param duration the duration of the animation in milliseconds * @param startTime the synchronized start time in milliseconds * @param element the element that visually bounds the entire animation */ public void run(int duration, double startTime, Element element) { // Cancel the animation if it is running cancel(); // Save the duration and startTime isRunning = true; isStarted = false; this.duration = duration; this.startTime = startTime; this.element = element; ++runId; // Execute the first callback. callback.execute(Duration.currentTimeMillis()); }
/** * Run this animation at the given startTime. If the startTime has already * passed, the animation will run synchronously as if it started at the * specified start time. If the animation is already running, it will be * canceled first. * <p> * If the element is not <code>null</code>, the {@link #onUpdate(double)} * method might be called only if the element may be visible (generally left * at the appreciation of the browser). Otherwise, it will be called * unconditionally. * * @param duration the duration of the animation in milliseconds * @param startTime the synchronized start time in milliseconds * @param element the element that visually bounds the entire animation */ public void run(int duration, double startTime, Element element) { // Cancel the animation if it is running cancel(); // Save the duration and startTime isRunning = true; isStarted = false; this.duration = duration; this.startTime = startTime; this.element = element; ++runId; // Execute the first callback. callback.execute(Duration.currentTimeMillis()); }