Search in sources :

Example 6 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class Oauth2 method createLoginComponent.

private Component createLoginComponent(final ActionListener al, final Form frm, final Form backToForm, final Dialog progress) {
    String URL = oauth2URL + "?client_id=" + clientId + "&redirect_uri=" + Util.encodeUrl(redirectURI);
    if (scope != null) {
        URL += "&scope=" + scope;
    }
    if (clientSecret != null) {
        URL += "&response_type=code";
    } else {
        URL += "&response_type=token";
    }
    if (additionalParams != null) {
        Enumeration e = additionalParams.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String val = additionalParams.get(key).toString();
            URL += "&" + key + "=" + val;
        }
    }
    DocumentInfo.setDefaultEncoding(DocumentInfo.ENCODING_UTF8);
    final WebBrowser[] web = new WebBrowser[1];
    web[0] = new WebBrowser() {

        @Override
        public void onLoad(String url) {
            handleURL(url, this, al, frm, backToForm, progress);
        }

        public void onStart(String url) {
        }
    };
    web[0].setURL(URL);
    return web[0];
}
Also used : Enumeration(java.util.Enumeration) WebBrowser(com.codename1.components.WebBrowser)

Example 7 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class IntentIntegrator method showDownloadDialog.

private void showDownloadDialog() {
    Dialog d = new Dialog();
    d.setTitle(title);
    if (Dialog.show(title, message, "Yes", "No")) {
        Uri uri = Uri.parse("market://details?id=" + BS_PACKAGE);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        try {
            activity.startActivity(intent);
        } catch (ActivityNotFoundException anfe) {
            // Hmm, market is not installed
            Log.w(TAG, "Android Market is not installed; cannot install Barcode Scanner");
        }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Dialog(com.codename1.ui.Dialog) Intent(android.content.Intent) Uri(android.net.Uri)

Example 8 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class IOSImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    if (!nativeInstance.checkMicrophoneUsage()) {
        throw new RuntimeException("Please add the ios.NSMicrophoneUsageDescription build hint");
    }
    dropEvents = false;
    String p = FileSystemStorage.getInstance().getAppHomePath();
    if (!p.endsWith("/")) {
        p += "/";
    }
    try {
        final Media media = MediaManager.createMediaRecorder(p + "cn1TempAudioFile", MediaManager.getAvailableRecordingMimeTypes()[0]);
        media.play();
        boolean b = Dialog.show("Recording", "", "Save", "Cancel");
        final Dialog d = new Dialog("Recording");
        media.pause();
        media.cleanup();
        d.dispose();
        if (b) {
            response.actionPerformed(new ActionEvent(p + "cn1TempAudioFile"));
        } else {
            FileSystemStorage.getInstance().delete(p + "cn1TempAudioFile");
            response.actionPerformed(null);
        }
    } catch (IOException err) {
        err.printStackTrace();
        response.actionPerformed(null);
    }
}
Also used : Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent) Media(com.codename1.media.Media) IOException(java.io.IOException)

Example 9 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class FloatingActionButton method fireActionEvent.

@Override
protected void fireActionEvent(int x, int y) {
    Form current = Display.getInstance().getCurrent();
    if (current instanceof Dialog) {
        ((Dialog) current).dispose();
    }
    super.fireActionEvent(x, y);
}
Also used : Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog)

Example 10 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class InteractionDialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param rect the screen rectangle to which the popup should point
 */
public void showPopupDialog(Rectangle rect) {
    disposed = false;
    if (getUIID().equals("Dialog")) {
        setUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    Component contentPane = getContentPane();
    Label title = getTitleComponent();
    UIManager manager = getUIManager();
    String dialogTitle = title.getText();
    // preferred size logic of the dialog won't work with large title borders
    if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        titleArea.setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            titleArea.setPreferredSize(new Dimension(0, 0));
            if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
                getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
                int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
                int titlePT = getTitleComponent().getStyle().getPaddingTop();
                byte[] pu = getContentPane().getStyle().getPaddingUnit();
                if (pu == null) {
                    pu = new byte[4];
                }
                pu[0] = Style.UNIT_TYPE_PIXELS;
                getContentPane().getStyle().setPaddingUnit(pu);
                int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
                getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
            }
        }
    }
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    Style contentPaneStyle = getStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    calcPreferredSize();
    int prefHeight = getPreferredH();
    int prefWidth = getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    Form f = Display.getInstance().getCurrent();
    int availableHeight = getLayeredPane(f).getParent().getHeight();
    int availableWidth = getLayeredPane(f).getParent().getWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    boolean showPortrait = Display.getInstance().isPortrait();
    // if we don't have enough space then disregard device orientation
    if (showPortrait) {
        if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
            showPortrait = false;
        }
    } else {
        if (availableHeight / 2 > availableWidth - rect.getWidth()) {
            showPortrait = true;
        }
    }
    if (showPortrait) {
        if (width < availableWidth) {
            int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealX > 0) {
                // if the idealX is too far to the right just align to the right
                if (idealX + width > availableWidth) {
                    x = availableWidth - width;
                } else {
                    x = idealX;
                }
            }
        }
        if (rect.getY() < availableHeight / 2) {
            // popup downwards
            y = rect.getY();
            int height = Math.min(prefHeight, availableHeight - y);
            show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
        } else {
            // popup upwards
            int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
            y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
            show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
        }
    } else {
        int height = Math.min(prefHeight, availableHeight);
        if (height < availableHeight) {
            int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealY > 0) {
                // if the idealY is too far up just align to the top
                if (idealY + height > availableHeight) {
                    y = availableHeight - height;
                } else {
                    y = idealY;
                }
            }
        }
        if (prefWidth > rect.getX()) {
            // popup right
            x = rect.getX() + rect.getSize().getWidth();
            if (x + prefWidth > availableWidth) {
                x = availableWidth - prefWidth;
            }
            width = Math.min(prefWidth, availableWidth - x);
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        }
    }
/*if(restoreArrow) {
            contentPaneStyle.getBorder().clearImageBorderSpecialTile();
        }*/
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component) Image(com.codename1.ui.Image) Border(com.codename1.ui.plaf.Border)

Aggregations

Dialog (com.codename1.ui.Dialog)28 Form (com.codename1.ui.Form)23 BorderLayout (com.codename1.ui.layouts.BorderLayout)17 Component (com.codename1.ui.Component)16 ActionEvent (com.codename1.ui.events.ActionEvent)14 Container (com.codename1.ui.Container)13 Style (com.codename1.ui.plaf.Style)12 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)7 IOException (java.io.IOException)7 InfiniteProgress (com.codename1.components.InfiniteProgress)6 Command (com.codename1.ui.Command)6 Label (com.codename1.ui.Label)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ConnectionRequest (com.codename1.io.ConnectionRequest)4 Button (com.codename1.ui.Button)4 CheckBox (com.codename1.ui.CheckBox)4 Painter (com.codename1.ui.Painter)4 TextArea (com.codename1.ui.TextArea)4