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);
}
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);
}
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;
}
}
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();
}
}
});
}
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("");
}
Aggregations