Search in sources :

Example 11 with ComponentAnimation

use of com.codename1.ui.animations.ComponentAnimation in project CodenameOne by codenameone.

the class ComponentSelector method fadeOutAndWait.

/**
 * Hide the matched elements by fading them to transparent. Blocks thread until animation is complete.
 * @param duration Duration of animation.
 * @return Self for chaining.
 */
public ComponentSelector fadeOutAndWait(int duration) {
    final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
    AnimationManager mgr = null;
    ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
    final ArrayList<Component> animatingComponents = new ArrayList<Component>();
    for (Component c : this) {
        Container parent = c.getParent();
        if (parent != null) {
            AnimationManager cmgr = c.getAnimationManager();
            if (cmgr != null) {
                mgr = cmgr;
                Container placeholder = new Container();
                // placeholder.setShowEvenIfBlank(true);
                c.putClientProperty(placeholderProperty, placeholder);
                Component.setSameHeight(placeholder, c);
                Component.setSameWidth(placeholder, c);
                $(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
                ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
                animations.add(a);
                animatingComponents.add(c);
            }
        // centerBackground.add(BorderLayout.CENTER, boxy);
        }
    }
    if (mgr != null) {
        mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])));
        for (final Component c : animatingComponents) {
            c.setVisible(false);
            final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
            c.putClientProperty(placeholderProperty, null);
            if (placeholder != null) {
                Container parent = placeholder.getParent();
                if (parent != null) {
                    parent.replace(placeholder, c, CommonTransitions.createEmpty());
                }
            }
        }
    }
    return this;
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) ArrayList(java.util.ArrayList)

Example 12 with ComponentAnimation

use of com.codename1.ui.animations.ComponentAnimation in project CodenameOne by codenameone.

the class AnimationManager method updateAnimations.

void updateAnimations() {
    if (anims.size() > 0) {
        ComponentAnimation c = anims.get(0);
        if (c.isInProgress()) {
            c.updateAnimationState();
        } else {
            c.updateAnimationState();
            anims.remove(c);
        }
    } else {
        while (postAnimations.size() > 0) {
            postAnimations.get(0).run();
            postAnimations.remove(0);
        }
    }
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation)

Aggregations

ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)10 ArrayList (java.util.ArrayList)5 Motion (com.codename1.ui.animations.Motion)2 Style (com.codename1.ui.plaf.Style)2 Point (com.codename1.ui.geom.Point)1 BorderLayout (com.codename1.ui.layouts.BorderLayout)1 BoxLayout (com.codename1.ui.layouts.BoxLayout)1 FlowLayout (com.codename1.ui.layouts.FlowLayout)1 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)1 Layout (com.codename1.ui.layouts.Layout)1 Vector (java.util.Vector)1