Search in sources :

Example 16 with Transition

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

the class Display method paintTransitionAnimation.

private void paintTransitionAnimation() {
    Animation ani = (Animation) animationQueue.get(0);
    if (!ani.animate()) {
        animationQueue.remove(0);
        if (ani instanceof Transition) {
            Form source = (Form) ((Transition) ani).getSource();
            restoreMenu(source);
            if (animationQueue.size() > 0) {
                ani = (Animation) animationQueue.get(0);
                if (ani instanceof Transition) {
                    ((Transition) ani).initTransition();
                }
            } else {
                Form f = (Form) ((Transition) ani).getDestination();
                restoreMenu(f);
                if (source == null || source == impl.getCurrentForm() || source == getCurrent()) {
                    setCurrentForm(f);
                }
                ((Transition) ani).cleanup();
            }
            return;
        }
    }
    ani.paint(codenameOneGraphics);
    impl.flushGraphics();
    if (transitionDelay > 0) {
        // flush and so require the painting thread to get CPU too.
        try {
            synchronized (lock) {
                lock.wait(transitionDelay);
            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : Transition(com.codename1.ui.animations.Transition) Animation(com.codename1.ui.animations.Animation)

Example 17 with Transition

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

the class MenuBar method initMenuBar.

/**
 * Initialize the MenuBar
 *
 * @param parent the associated Form
 */
protected void initMenuBar(Form parent) {
    this.parent = parent;
    selectMenuItem = createMenuSelectCommand();
    cancelMenuItem = createMenuCancelCommand();
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    // don't minimize the app if it's a Dialog
    minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
    hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
    menuStyle = manager.getComponentStyle("Menu");
    setUIID("SoftButton");
    menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
    // use the slide transition by default
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
        transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
    }
    menuCellRenderer = lf.getMenuRenderer();
    int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
    thirdSoftButton = Display.getInstance().isThirdSoftButton();
    int commandBehavior = getCommandBehavior();
    if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(main);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(main);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            setLayout(new GridLayout(1, 2));
            soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[0];
            right = soft[1];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[0];
                soft[0] = soft[1];
                soft[1] = b;
            }
        }
        // It doesn't make sense for softbuttons to have ... at the end
        for (int iter = 0; iter < soft.length; iter++) {
            soft[iter].setEndsWith3Points(false);
        }
    } else {
        // special case for touch screens we still want the 3 softbutton areas...
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            addComponent(left);
            addComponent(main);
            addComponent(right);
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            soft = new Button[] { createSoftButton("SoftButtonCenter") };
        }
    }
    softCommand = new Command[soft.length];
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

Example 18 with Transition

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

the class Toolbar method showOverflowMenu.

/*
     * A Overflow Menu is implemented as a dialog, this method allows you to 
     * override the dialog display in order to customize the dialog menu in 
     * various ways
     * 
     * @param menu a dialog containing Overflow Menu options that can be 
     * customized
     * @return the command selected by the user in the dialog
     */
protected Command showOverflowMenu(Dialog menu) {
    Form parent = sideMenu.getParentForm();
    int height;
    int marginLeft;
    int marginRight = 0;
    Container dialogContentPane = menu.getDialogComponent();
    marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
    marginLeft = Math.max(0, marginLeft);
    if (parent.getSoftButtonCount() > 1) {
        height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
    } else {
        height = parent.getHeight() - dialogContentPane.getPreferredH();
    }
    height = Math.max(0, height);
    int th = getHeight();
    Transition transitionIn;
    Transition transitionOut;
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        if (transitionIn instanceof BubbleTransition) {
            ((BubbleTransition) transitionIn).setComponentName("OverflowButton");
        }
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createEmpty();
        transitionOut = CommonTransitions.createEmpty();
    }
    menu.setTransitionInAnimator(transitionIn);
    menu.setTransitionOutAnimator(transitionOut);
    if (isRTL()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    int tint = parent.getTintColor();
    parent.setTintColor(0x00FFFFFF);
    parent.tint = false;
    boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
    int topPadding = 0;
    Component statusBar = ((BorderLayout) getLayout()).getNorth();
    if (statusBar != null) {
        topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
    }
    if (showBelowTitle) {
        topPadding = th;
    }
    Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
    parent.setTintColor(tint);
    return r;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Transition(com.codename1.ui.animations.Transition) BubbleTransition(com.codename1.ui.animations.BubbleTransition) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) BubbleTransition(com.codename1.ui.animations.BubbleTransition)

Example 19 with Transition

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

the class CommonTransitions method paintCoverAtPosition.

private void paintCoverAtPosition(Graphics g, int slideX, int slideY) {
    Component source = getSource();
    // if this is the first form we can't do a slide transition since we have no source form
    if (source == null) {
        return;
    }
    Component dest = getDestination();
    int w = source.getWidth();
    int h = source.getHeight();
    if (slideType == SLIDE_HORIZONTAL) {
        h = 0;
    } else {
        w = 0;
    }
    boolean dir = forward;
    if (dest != null && dest.getUIManager().getLookAndFeel().isRTL()) {
        dir = !dir;
    }
    if (dir) {
        w = -w;
        h = -h;
    } else {
        slideX = -slideX;
        slideY = -slideY;
    }
    g.setClip(source.getAbsoluteX() + source.getScrollX(), source.getAbsoluteY() + source.getScrollY(), source.getWidth(), source.getHeight());
    // dialog animation is slightly different...
    if (source instanceof Dialog) {
        if (buffer != null) {
            g.drawImage(buffer, 0, 0);
        } else {
            paint(g, dest, 0, 0);
        }
        paint(g, source, -slideX, -slideY);
        return;
    }
    if (dest instanceof Dialog) {
        if (buffer != null) {
            g.drawImage(buffer, 0, 0);
        } else {
            paint(g, source, 0, 0);
        }
        paint(g, dest, -slideX - w, -slideY - h);
        return;
    }
    if (transitionType == TYPE_UNCOVER) {
        paint(g, dest, 0, 0);
        if (source.getParent() != null || buffer == null) {
            source.paintBackgrounds(g);
            paint(g, source, slideX + w, slideY + h);
        } else {
            g.drawImage(buffer, slideX + w, slideY + h);
        }
    } else {
        if (source.getParent() != null || buffer == null) {
            source.paintBackgrounds(g);
            paint(g, source, 0, 0);
        } else {
            g.drawImage(buffer, 0, 0);
        }
        paint(g, dest, slideX + w, slideY + h);
    }
}
Also used : Dialog(com.codename1.ui.Dialog) Component(com.codename1.ui.Component)

Example 20 with Transition

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

the class XYMultiSeriesTransition method getBuffer.

/**
 * Gets the buffer/cache for values.  Values set in the buffer will be applied
 * to the target dataset when the transition takes place.
 * @return
 */
public XYMultipleSeriesDataset getBuffer() {
    if (datasetCache == null) {
        datasetCache = new XYMultipleSeriesDataset();
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            datasetCache.addSeries(new XYSeries(dataset.getSeriesAt(i).getTitle()));
        }
        seriesTransitions = new XYSeriesTransition[dataset.getSeries().length];
        int tlen = seriesTransitions.length;
        for (int i = 0; i < tlen; i++) {
            seriesTransitions[i] = new XYSeriesTransition(getChart(), dataset.getSeriesAt(i));
            seriesTransitions[i].setBuffer(datasetCache.getSeriesAt(i));
        }
    }
    return datasetCache;
}
Also used : XYSeries(com.codename1.charts.models.XYSeries) XYMultipleSeriesDataset(com.codename1.charts.models.XYMultipleSeriesDataset)

Aggregations

Form (com.codename1.ui.Form)7 Transition (com.codename1.ui.animations.Transition)7 Component (com.codename1.ui.Component)6 Container (com.codename1.ui.Container)4 Dialog (com.codename1.ui.Dialog)3 Graphics (com.codename1.ui.Graphics)3 Animation (com.codename1.ui.animations.Animation)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 XYSeries (com.codename1.charts.models.XYSeries)2 BubbleTransition (com.codename1.ui.animations.BubbleTransition)2 Rectangle (com.codename1.ui.geom.Rectangle)2 LookAndFeel (com.codename1.ui.plaf.LookAndFeel)2 UIManager (com.codename1.ui.plaf.UIManager)2 XYMultipleSeriesDataset (com.codename1.charts.models.XYMultipleSeriesDataset)1 XYValueSeries (com.codename1.charts.models.XYValueSeries)1 BrowserComponent (com.codename1.ui.BrowserComponent)1 Command (com.codename1.ui.Command)1 Display (com.codename1.ui.Display)1 Image (com.codename1.ui.Image)1 Label (com.codename1.ui.Label)1