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;
}
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);
}
}
}
Aggregations