Package org.gwtoolbox.commons.ui.client.animation

Source Code of org.gwtoolbox.commons.ui.client.animation.Animator$Callback

package org.gwtoolbox.commons.ui.client.animation;

import com.google.gwt.animation.client.Animation;
import com.google.gwt.core.client.Duration;

/**
* @author Uri Boness
*/
public class Animator {

    private final int duration;
    private final Transition transition;

    public Animator(int duration) {
        this(duration, Transitions.linear());
    }

    public Animator(int duration, Transition transition) {
        this.duration = duration;
        this.transition = transition;
    }

    public Cancellable start(Callback callback) {
        return start(Duration.currentTimeMillis(), callback);
    }

    public Cancellable start(double startTime, final Callback callback) {
        Animation animation = new Animation() {
            @Override
            protected void onUpdate(double progress) {
                callback.update(transition.translate(progress));
                if (progress == 1.0) {
                    callback.finished();
                }
            }
        };
        animation.run(duration, startTime);
        return new AnimationCancellable(animation);
    }

    public interface Callback {

        void update(double progress);

        void finished();
    }


    //================================================= Inner Classes ==================================================

    private final static class AnimationCancellable implements Cancellable {

        private final Animation animation;

        private AnimationCancellable(Animation animation) {
            this.animation = animation;
        }

        public void cancel() {
            animation.cancel();
        }
    }

}
TOP

Related Classes of org.gwtoolbox.commons.ui.client.animation.Animator$Callback

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.