Search in sources :

Example 1 with WebBrowser

use of com.codename1.components.WebBrowser in project CodenameOne by codenameone.

the class PreviewInSimulator method main.

/**
 * Called back from simulateDeviceActionPerformed to show the simulator skin
 */
public static void main(String[] argv) {
    com.codename1.ui.Display.init(new Runnable() {

        public void run() {
            try {
                Preferences pref = Preferences.userNodeForPackage(PreviewInSimulator.class);
                String theme = pref.get("previewTheme", null);
                File resFile = new File(pref.get("previewResource", null));
                String baseResDir = pref.get("baseResourceDir", null);
                if (baseResDir != null) {
                    JavaSEPort.setBaseResourceDir(new File(baseResDir));
                }
                String selection = pref.get("previewSelection", null);
                Resources res = Resources.open(new FileInputStream(resFile));
                if (theme == null || theme.length() == 0) {
                    if (com.codename1.ui.Display.getInstance().hasNativeTheme()) {
                        com.codename1.ui.Display.getInstance().installNativeTheme();
                    }
                } else {
                    com.codename1.ui.plaf.UIManager.getInstance().setThemeProps(res.getTheme(theme));
                }
                com.codename1.ui.util.UIBuilder.registerCustomComponent("Table", com.codename1.ui.table.Table.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("MediaPlayer", com.codename1.components.MediaPlayer.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("ContainerList", com.codename1.ui.list.ContainerList.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("ComponentGroup", com.codename1.ui.ComponentGroup.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("Tree", com.codename1.ui.tree.Tree.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("HTMLComponent", com.codename1.ui.html.HTMLComponent.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("RSSReader", com.codename1.components.RSSReader.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("FileTree", com.codename1.components.FileTree.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("WebBrowser", com.codename1.components.WebBrowser.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("NumericSpinner", com.codename1.ui.spinner.NumericSpinner.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("DateSpinner", com.codename1.ui.spinner.DateSpinner.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("TimeSpinner", com.codename1.ui.spinner.TimeSpinner.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("DateTimeSpinner", com.codename1.ui.spinner.DateTimeSpinner.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("GenericSpinner", com.codename1.ui.spinner.GenericSpinner.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("LikeButton", com.codename1.facebook.ui.LikeButton.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("InfiniteProgress", com.codename1.components.InfiniteProgress.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiButton", com.codename1.components.MultiButton.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanButton", com.codename1.components.SpanButton.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanLabel", com.codename1.components.SpanLabel.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("Ads", com.codename1.components.Ads.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("MapComponent", com.codename1.maps.MapComponent.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiList", com.codename1.ui.list.MultiList.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("ShareButton", com.codename1.components.ShareButton.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("OnOffSwitch", com.codename1.components.OnOffSwitch.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("ImageViewer", com.codename1.components.ImageViewer.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("AutoCompleteTextField", com.codename1.ui.AutoCompleteTextField.class);
                com.codename1.ui.util.UIBuilder.registerCustomComponent("Picker", com.codename1.ui.spinner.Picker.class);
                com.codename1.ui.util.UIBuilder builder = new com.codename1.ui.util.UIBuilder();
                com.codename1.ui.Container c = builder.createContainer(res, selection);
                if (c instanceof com.codename1.ui.Form) {
                    ((com.codename1.ui.Form) c).refreshTheme();
                    if (c instanceof com.codename1.ui.Dialog) {
                        ((com.codename1.ui.Dialog) c).showModeless();
                    } else {
                        ((com.codename1.ui.Form) c).show();
                    }
                } else {
                    com.codename1.ui.Form f = new com.codename1.ui.Form();
                    f.setLayout(new com.codename1.ui.layouts.BorderLayout());
                    f.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, c);
                    f.refreshTheme();
                    f.show();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, "Error While Running In Simulator: " + ex, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
}
Also used : Preferences(java.util.prefs.Preferences) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BackingStoreException(java.util.prefs.BackingStoreException) Resources(com.codename1.ui.util.Resources) File(java.io.File)

Example 2 with WebBrowser

use of com.codename1.components.WebBrowser 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 3 with WebBrowser

use of com.codename1.components.WebBrowser in project CodenameOne by codenameone.

the class RSSReader method showRSSEntry.

/**
 * Shows a form containing the RSS entry
 *
 * @param h the parsed entry
 */
protected void showRSSEntry(Hashtable h) {
    Form newForm = null;
    if (targetContainer != null) {
        if (targetContainer instanceof Form) {
            newForm = (Form) targetContainer;
        } else {
            newForm = new Form((String) h.get("title"));
            newForm.setLayout(new BorderLayout());
            newForm.addComponent(BorderLayout.CENTER, targetContainer);
        }
        updateComponentValues(newForm, h);
    } else {
        newForm = new Form((String) h.get("title"));
        newForm.setScrollable(false);
        WebBrowser c = new WebBrowser();
        String s = (String) h.get("description");
        s = "<html><body>" + s + "</body></html>";
        c.setPage(s, null);
        newForm.setLayout(new BorderLayout());
        newForm.addComponent(BorderLayout.CENTER, c);
    }
    if (addBackToTaget) {
        final Form sourceForm = Display.getInstance().getCurrent();
        Command back = new BackCommand(sourceForm);
        newForm.addCommand(back);
        newForm.setBackCommand(back);
    }
    newForm.show();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command)

Example 4 with WebBrowser

use of com.codename1.components.WebBrowser in project CodenameOne by codenameone.

the class RSSReader method updateComponentValues.

void updateComponentValues(Container root, Hashtable h) {
    int c = root.getComponentCount();
    for (int iter = 0; iter < c; iter++) {
        Component current = root.getComponentAt(iter);
        // subclasses
        if (current.getClass() == com.codename1.ui.Container.class || current.getClass() == com.codename1.ui.Tabs.class) {
            updateComponentValues((Container) current, h);
            continue;
        }
        String n = current.getName();
        if (n != null) {
            String val = (String) h.get(n);
            if (val != null) {
                if (current instanceof Button) {
                    final String url = (String) val;
                    ((Button) current).addActionListener(new Listener(url));
                    continue;
                }
                if (current instanceof Label) {
                    ((Label) current).setText(val);
                    continue;
                }
                if (current instanceof TextArea) {
                    ((TextArea) current).setText(val);
                    continue;
                }
                if (current instanceof WebBrowser) {
                    ((WebBrowser) current).setPage(val, null);
                    continue;
                }
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 5 with WebBrowser

use of com.codename1.components.WebBrowser in project CodenameOne by codenameone.

the class VServAds method getPendingAd.

/**
 * {@inheritDoc}
 */
protected Component getPendingAd() {
    if (imageURL == null) {
        return null;
    }
    if (renderNotify != null && renderNotify.length() > 0) {
        ConnectionRequest c = new ConnectionRequest();
        c.setFailSilently(true);
        c.setUrl(renderNotify);
        c.setPost(false);
        NetworkManager.getInstance().addToQueue(c);
    }
    if ("image".equalsIgnoreCase(contentType)) {
        Button adComponent = new Button() {

            public void setIcon(Image icon) {
                if (icon != null && isScaleMode()) {
                    icon = icon.scaledWidth(Display.getInstance().getDisplayWidth());
                }
                super.setIcon(icon);
            }
        };
        adComponent.setUIID("Container");
        adComponent.getStyle().setBgColor(backgroundColor);
        adComponent.getStyle().setOpacity(0xff);
        ImageDownloadService imd = new ImageDownloadService(imageURL, adComponent);
        NetworkManager.getInstance().addToQueueAndWait(imd);
        /*adComponent.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    Display.getInstance().execute(getAdDestination());
                }
            });*/
        return adComponent;
    } else {
        WebBrowser wb = new WebBrowser();
        if (wb.getInternal() instanceof BrowserComponent) {
            BrowserComponent bc = (BrowserComponent) wb.getInternal();
            bc.setBrowserNavigationCallback(new BrowserNavigationCallback() {

                public boolean shouldNavigate(final String url) {
                    unlock(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            Display.getInstance().execute(url);
                        }
                    });
                    return false;
                }
            });
        }
        wb.setURL(imageURL);
        return wb;
    }
}
Also used : ImageDownloadService(com.codename1.io.services.ImageDownloadService) ConnectionRequest(com.codename1.io.ConnectionRequest) WebBrowser(com.codename1.components.WebBrowser) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) BrowserNavigationCallback(com.codename1.ui.events.BrowserNavigationCallback)

Aggregations

WebBrowser (com.codename1.components.WebBrowser)2 Form (com.codename1.ui.Form)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 IOException (java.io.IOException)2 Hashtable (java.util.Hashtable)2 ConnectionRequest (com.codename1.io.ConnectionRequest)1 ImageDownloadService (com.codename1.io.services.ImageDownloadService)1 Button (com.codename1.ui.Button)1 Command (com.codename1.ui.Command)1 Component (com.codename1.ui.Component)1 Container (com.codename1.ui.Container)1 Label (com.codename1.ui.Label)1 TextArea (com.codename1.ui.TextArea)1 BrowserNavigationCallback (com.codename1.ui.events.BrowserNavigationCallback)1 BorderLayout (com.codename1.ui.layouts.BorderLayout)1 Resources (com.codename1.ui.util.Resources)1 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)1 StringReader (com.codename1.util.regex.StringReader)1 File (java.io.File)1