public void start() { if (!ticking) { ticking = true; AnimationScheduler.get().requestAnimationFrame(this); } }
/** * Construct a new {@link Animation}. */ public Animation() { this(AnimationScheduler.get()); }
@Override public void execute(double timestamp) { if (update(timestamp)) { // Schedule the next animation frame. requestHandle = scheduler.requestAnimationFrame(callback, element); } else { requestHandle = null; } } };
/** * Called immediately after the animation is canceled. The default * implementation of this method calls {@link #onComplete()} only if the * animation has actually started running. */ protected void onCancel() { if (wasStarted) { onComplete(); } }
/** * Immediately run this animation. If the animation is already running, it * will be canceled first. * <p> * This is equivalent to <code>run(duration, null)</code>. * * @param duration the duration of the animation in milliseconds * @see #run(int, Element) */ public void run(int duration) { run(duration, null); }
/** * Immediately cancel this animation. If the animation is running or is * scheduled to run, {@link #onCancel()} will be called. */ public void cancel() { // Ignore if the animation is not currently running. if (!isRunning) { return; } // Reset the state. wasStarted = isStarted; // Used by onCancel. element = null; isRunning = false; isStarted = false; // Cancel the animation request. if (requestHandle != null) { requestHandle.cancel(); requestHandle = null; } onCancel(); }
/** * 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()); }
/** * Returns the default implementation of the AnimationScheduler API. */ public static AnimationScheduler get() { if (instance == null) { AnimationSupportDetector supportDetector = GWT.create(AnimationSupportDetector.class); instance = (supportDetector != null && supportDetector.isNativelySupported()) ? new AnimationSchedulerImplStandard() : new AnimationSchedulerImplTimer(); } return instance; }
/** * Called immediately after the animation completes. */ protected void onComplete() { onUpdate(interpolate(1.0)); }
@Override public AnimationHandle requestAnimationFrame(AnimationCallback callback, Element element) { final JavaScriptObject handle = requestImpl(callback, element); return new AnimationHandle() { @Override public void cancel() { cancelImpl(handle); } }; }
@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 void execute(double timestamp) { if (ticking) { GamepadSupport.pollGamepads(); GamepadSupport.pollGamepadsStatus(); AnimationScheduler.get().requestAnimationFrame(this); } } }
/** * Schedule an animation, letting the browser decide when to trigger the next * step in the animation. * * <p> * NOTE: If you are animating an element, use * {@link #requestAnimationFrame(AnimationCallback, Element)} instead so the * browser can optimize for the specified element. * </p> * * <p> * Using this method instead of a timeout is preferred because the browser is * in the best position to decide how frequently to trigger the callback for * an animation of the specified element. The browser can balance multiple * animations and trigger callbacks at the optimal rate for smooth * performance. * </p> * * @param callback the callback to fire * @return a handle to the requested animation frame * @see #requestAnimationFrame(AnimationCallback, Element) */ public AnimationHandle requestAnimationFrame(AnimationCallback callback) { return requestAnimationFrame(callback, null); }
/** * 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> * This is equivalent to <code>run(duration, startTime, null)</code>. * * @param duration the duration of the animation in milliseconds * @param startTime the synchronized start time in milliseconds * @see #run(int, double, Element) */ public void run(int duration, double startTime) { run(duration, startTime, null); }
/** * Called immediately before the animation starts. */ protected void onStart() { onUpdate(interpolate(0.0)); }
@Override public void execute (double timestamp) { try { mainLoop(); } catch (Throwable t) { error("GwtApplication", "exception: " + t.getMessage(), t); throw new RuntimeException(t); } AnimationScheduler.get().requestAnimationFrame(this, graphics.canvas); } }, graphics.canvas);
/** * Immediately run this animation. 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 element the element that visually bounds the entire animation */ public void run(int duration, Element element) { run(duration, Duration.currentTimeMillis(), element); }
@Override public void execute (double timestamp) { try { mainLoop(); } catch (Throwable t) { error("GwtApplication", "exception: " + t.getMessage(), t); throw new RuntimeException(t); } AnimationScheduler.get().requestAnimationFrame(this, graphics.canvas); } }, graphics.canvas);
AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() { @Override public void execute (double timestamp) {
AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() { @Override public void execute (double timestamp) {