Search in sources :

Example 91 with Image

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

the class CodenameOneImplementation method downloadImageToFileSystem.

/**
 * Downloads an image to file system. This will *not* first check to see if the file exists already.
 * It will download and overwrite any existing image at the provided location.
 *
 * <p>Some platforms may override this method to use platform-level caching.  E.g. Javascript will use
 * the browser cache for downloading the image.</p>
 *
 * @param url The URL of the image to download.
 * @param fileName The storage key to be used to store the image.
 * @param onSuccess Callback on success.  Will be executed on EDT.
 * @param onFail Callback on failure.  Will be executed on EDT.
 */
public void downloadImageToFileSystem(String url, String fileName, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail) {
    ConnectionRequest cr = new ConnectionRequest();
    cr.setPost(false);
    cr.setFailSilently(true);
    cr.setReadResponseForErrors(false);
    cr.setDuplicateSupported(true);
    cr.setUrl(url);
    cr.downloadImageToFileSystem(fileName, onSuccess, onFail);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 92 with Image

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

the class CodenameOneImplementation method downloadImageToStorage.

/**
 * Downloads an image to storage. This will *not* first check to see if the image is located in storage
 * already.  It will download and overwrite any existing image at the provided location.
 *
 * <p>Some platforms may override this method to use platform-level caching.  E.g. Javascript will use
 * the browser cache for downloading the image.</p>
 *
 * @param url The URL of the image to download.
 * @param fileName The storage key to be used to store the image.
 * @param onSuccess Callback on success.  Will be executed on EDT.
 * @param onFail Callback on failure.  Will be executed on EDT.
 */
public void downloadImageToStorage(String url, String fileName, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail) {
    ConnectionRequest cr = new ConnectionRequest();
    cr.setPost(false);
    cr.setFailSilently(true);
    cr.setReadResponseForErrors(false);
    cr.setDuplicateSupported(true);
    cr.setUrl(url);
    cr.downloadImageToStorage(fileName, onSuccess, onFail);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 93 with Image

use of com.codename1.ui.Image 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)

Example 94 with Image

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

the class MasterDetail method bindTabletLandscapeMaster.

/**
 * @deprecated this was a half baked idea that made it into the public API
 */
public static void bindTabletLandscapeMaster(final Form rootForm, Container parentContainer, Component landscapeUI, final Component portraitUI, final String commandTitle, Image commandIcon) {
    landscapeUI.setHideInPortrait(true);
    parentContainer.addComponent(BorderLayout.WEST, landscapeUI);
    final Command masterCommand = new Command(commandTitle, commandIcon) {

        public void actionPerformed(ActionEvent ev) {
            Dialog dlg = new Dialog();
            dlg.setLayout(new BorderLayout());
            dlg.setDialogUIID("Container");
            dlg.getContentPane().setUIID("Container");
            Container titleArea = new Container(new BorderLayout());
            dlg.addComponent(BorderLayout.NORTH, titleArea);
            titleArea.setUIID("TitleArea");
            Label title = new Label(commandTitle);
            titleArea.addComponent(BorderLayout.CENTER, title);
            title.setUIID("Title");
            Container body = new Container(new BorderLayout());
            body.setUIID("Form");
            body.addComponent(BorderLayout.CENTER, portraitUI);
            dlg.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 250));
            dlg.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 250));
            dlg.addComponent(BorderLayout.CENTER, body);
            dlg.setDisposeWhenPointerOutOfBounds(true);
            dlg.showStetched(BorderLayout.WEST, true);
            dlg.removeComponent(portraitUI);
        }
    };
    if (Display.getInstance().isPortrait()) {
        if (rootForm.getCommandCount() > 0) {
            rootForm.addCommand(masterCommand, 1);
        } else {
            rootForm.addCommand(masterCommand);
        }
    }
    rootForm.addOrientationListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (portraitUI.getParent() != null) {
                Form f = Display.getInstance().getCurrent();
                if (f instanceof Dialog) {
                    ((Dialog) f).dispose();
                }
            }
            if (Display.getInstance().isPortrait()) {
                rootForm.addCommand(masterCommand, 1);
            } else {
                rootForm.removeCommand(masterCommand);
                rootForm.revalidate();
            }
        }
    });
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) Dialog(com.codename1.ui.Dialog) Label(com.codename1.ui.Label)

Example 95 with Image

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

the class MultiButton method setCommand.

/**
 * Sets the command for the component, it doesn't affe
 *
 * @param c the command
 */
public void setCommand(Command c) {
    Image img = emblem.getIcon();
    emblem.setCommand(c);
    emblem.setIcon(img);
    emblem.setText("");
}
Also used : Image(com.codename1.ui.Image)

Aggregations

Image (com.codename1.ui.Image)82 EncodedImage (com.codename1.ui.EncodedImage)46 IOException (java.io.IOException)29 Hashtable (java.util.Hashtable)19 AnimationObject (com.codename1.ui.animations.AnimationObject)18 BufferedImage (java.awt.image.BufferedImage)18 Style (com.codename1.ui.plaf.Style)16 Form (com.codename1.ui.Form)15 ActionEvent (com.codename1.ui.events.ActionEvent)14 Dimension (com.codename1.ui.geom.Dimension)14 FontImage (com.codename1.ui.FontImage)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)13 Timeline (com.codename1.ui.animations.Timeline)12 ActionListener (com.codename1.ui.events.ActionListener)12 Border (com.codename1.ui.plaf.Border)12 Container (com.codename1.ui.Container)11 InputStream (java.io.InputStream)11 Graphics (com.codename1.ui.Graphics)10 Label (com.codename1.ui.Label)10 Button (com.codename1.ui.Button)9