Search in sources :

Example 11 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodenameOne by codenameone.

the class Sheet method show.

/**
 * Shows the sheet over the current form using a slide-up transition with given duration in milliseconds.
 *
 * <p>If another sheet is currently being shown, then this will replace that sheet, and use an appropriate slide
 * animation to adjust the size.</p>
 * @param duration The duration of the slide transition in milliseconds.
 * @see #show()
 */
public void show(final int duration) {
    // We need to add some margin to the title  to prevent overlap with the
    // back button and the commaneds.
    int titleMargin = Math.max(commandsContainer.getPreferredW() + commandsContainer.getStyle().getHorizontalMargins(), backButton.getPreferredW() + backButton.getStyle().getHorizontalMargins());
    // Set the padding in the content pane to match the corner radius
    Style s = getStyle();
    Style titleParentStyle = title.getParent().getStyle();
    titleParentStyle.setMarginLeft(titleMargin);
    titleParentStyle.setMarginRight(titleMargin);
    Border border = s.getBorder();
    if (border instanceof RoundRectBorder) {
        RoundRectBorder b = (RoundRectBorder) border;
        $(contentPane).setPaddingMillimeters(b.getCornerRadius());
    }
    // Deal with iPhoneX notch.
    UIManager uim = UIManager.getInstance();
    Style statusBarStyle = uim.getComponentStyle("StatusBar");
    Style titleAreaStyle = uim.getComponentStyle("TitleArea");
    int topPadding = statusBarStyle.getPaddingTop() + statusBarStyle.getPaddingBottom() + titleAreaStyle.getPaddingTop();
    int positionInt = getPositionInt();
    Rectangle displaySafeArea = new Rectangle();
    Display.getInstance().getDisplaySafeArea(displaySafeArea);
    int bottomPadding = s.getPaddingBottom();
    int safeAreaBottomPadding = CN.getDisplayHeight() - (displaySafeArea.getY() + displaySafeArea.getHeight());
    bottomPadding = bottomPadding + safeAreaBottomPadding;
    if (positionInt == S || positionInt == C) {
        // For Center and South position we use margin to
        // prevent overlap with top notch.  This looks better as overlap is only
        // an edge case that occurs when the sheet is the full screen height.
        $(this).setMargin(topPadding, 0, 0, 0);
        $(this).setPadding(s.getPaddingTop(), s.getPaddingRightNoRTL(), bottomPadding, s.getPaddingLeftNoRTL());
    } else {
        // For other cases we use padding to prevent overlap with top notch.  This looks
        // better as it appears that the sheet bleeds all the way to the top edge of the screen,
        // but the content is not obscured by the notch.
        $(this).setPadding(topPadding, s.getPaddingRightNoRTL(), bottomPadding, s.getPaddingLeftNoRTL());
    }
    // END Deal with iPhoneX notch
    Form f = CN.getCurrentForm();
    if (f.getAnimationManager().isAnimating()) {
        f.getAnimationManager().flushAnimation(new Runnable() {

            public void run() {
                show(duration);
            }
        });
        return;
    }
    if (getParent() != null) {
        remove();
    }
    Container cnt = CN.getCurrentForm().getFormLayeredPane(Sheet.class, true);
    if (!(cnt.getLayout() instanceof BorderLayout)) {
        cnt.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
        cnt.getStyle().setBgPainter(new Painter() {

            @Override
            public void paint(Graphics g, Rectangle rect) {
                int alph = g.getAlpha();
                g.setAlpha((int) (alph * 30 / 100.0));
                g.setColor(0x0);
                g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
                g.setAlpha(alph);
            }
        });
        cnt.revalidate();
    }
    if (cnt.getComponentCount() > 0) {
        $(".Sheet", cnt).each(new ComponentClosure() {

            @Override
            public void call(Component c) {
                if (c instanceof Sheet) {
                    Sheet s = (Sheet) c;
                    if (s.isAncestorSheetOf(Sheet.this) || s == Sheet.this) {
                        // via a back chain
                        return;
                    }
                    s.fireCloseEvent(false);
                    // Hiding this sheet may eliminate the possibility of
                    // its parent sheets from being shown again,
                    // so their close events should also be fired in this case.
                    Sheet sp = s.getParentSheet();
                    while (sp != null) {
                        if (sp == Sheet.this) {
                            break;
                        }
                        if (!sp.isAncestorSheetOf(Sheet.this)) {
                            sp.fireCloseEvent(false);
                        }
                        sp = sp.getParentSheet();
                    }
                }
            }
        });
        Component existing = cnt.getComponentAt(0);
        cnt.replace(existing, this, null);
        cnt.animateLayout(duration);
    } else {
        cnt.add(getPosition(), this);
        this.setWidth(getPreferredW(cnt));
        this.setHeight(getPreferredH(cnt));
        this.setX(getHiddenX(cnt));
        this.setY(getHiddenY(cnt));
        cnt.animateLayout(duration);
    }
}
Also used : RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) Rectangle(com.codename1.ui.geom.Rectangle) UIManager(com.codename1.ui.plaf.UIManager) BorderLayout(com.codename1.ui.layouts.BorderLayout) ComponentClosure(com.codename1.ui.ComponentSelector.ComponentClosure) Style(com.codename1.ui.plaf.Style) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) Border(com.codename1.ui.plaf.Border)

Example 12 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodenameOne by codenameone.

the class IOSImplementation method displaySafeAreaChanged.

public static void displaySafeAreaChanged(final boolean revalidate) {
    if (!CN.isEdt()) {
        CN.callSerially(new Runnable() {

            public void run() {
                displaySafeAreaChanged(revalidate);
            }
        });
        return;
    }
    Form f = CN.getCurrentForm();
    if (f != null) {
        f.setSafeAreaChanged();
        f.revalidateWithAnimationSafety();
    }
}
Also used : Form(com.codename1.ui.Form)

Example 13 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodeRAD by shannah.

the class ControllerEvent method getApplicationController.

public ApplicationController getApplicationController() {
    ViewController ctl = getViewController();
    if (ctl == null) {
        Form f = CN.getCurrentForm();
        if (f == null) {
            return null;
        }
        ctl = ViewController.getViewController(f);
    }
    if (ctl == null)
        return null;
    return ctl.getApplicationController();
}
Also used : Form(com.codename1.ui.Form)

Example 14 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodeRAD by shannah.

the class FormController method showBack.

/**
 * Shows this controller's form using the "back" animation.  If the current controller is an instance of {@link AutoCloseable},
 * then this will first attempt to call {@link AutoCloseable#close() } on the current form first.  If it throws an exception,
 * then that exception will be swallowed, but the showBack() action will be cancelled.
 */
public void showBack() {
    Form currForm = CN.getCurrentForm();
    if (currForm != null) {
        ViewController currentController = getViewController(currForm);
        if (currentController instanceof AutoCloseable) {
            AutoCloseable ac = (AutoCloseable) currentController;
            try {
                ac.close();
            } catch (Exception ex) {
                return;
            }
        }
    }
    getView().showBack();
}
Also used : Form(com.codename1.ui.Form)

Aggregations

Form (com.codename1.ui.Form)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 Toolbar (com.codename1.ui.Toolbar)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 AudioRecorderComponent (com.codename1.components.AudioRecorderComponent)2 FileSystemStorage (com.codename1.io.FileSystemStorage)2 MediaRecorderBuilder (com.codename1.media.MediaRecorderBuilder)2 Button (com.codename1.ui.Button)2 Label (com.codename1.ui.Label)2 ActionListener (com.codename1.ui.events.ActionListener)2 Rectangle (com.codename1.ui.geom.Rectangle)2 Style (com.codename1.ui.plaf.Style)2 SpanLabel (com.codename1.components.SpanLabel)1 File (com.codename1.io.File)1 com.codename1.ui (com.codename1.ui)1 CN.getCurrentForm (com.codename1.ui.CN.getCurrentForm)1 Command (com.codename1.ui.Command)1 ComponentClosure (com.codename1.ui.ComponentSelector.ComponentClosure)1 Container (com.codename1.ui.Container)1 Sheet (com.codename1.ui.Sheet)1