@Override public AnimationHandle requestAnimationFrame(final AnimationCallback callback, Element element) { // Save the animation frame request. AnimationHandleImpl requestId = new AnimationHandleImpl(callback); animationRequests.add(requestId); // Start the timer if it isn't started. if (animationRequests.size() == 1) { timer.schedule(DEFAULT_FRAME_DELAY); } // Return the request id. return requestId; }
/** * 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())); } } }
/** * 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())); } } }
@Override public AnimationHandle requestAnimationFrame(final AnimationCallback callback, Element element) { // Save the animation frame request. AnimationHandleImpl requestId = new AnimationHandleImpl(callback); animationRequests.add(requestId); // Start the timer if it isn't started. if (animationRequests.size() == 1) { timer.schedule(DEFAULT_FRAME_DELAY); } // Return the request id. return requestId; }
@Override public AnimationHandle requestAnimationFrame(final AnimationCallback callback, Element element) { // Save the animation frame request. AnimationHandleImpl requestId = new AnimationHandleImpl(callback); animationRequests.add(requestId); // Start the timer if it isn't started. if (animationRequests.size() == 1) { timer.schedule(DEFAULT_FRAME_DELAY); } // Return the request id. return requestId; }