use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToFileSystem.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param destFile local file to store the data into the given path
*/
public static void createImageToFileSystem(String url, ActionListener callback, String destFile) {
Image im = cacheImage(null, false, destFile, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.destinationFile = destFile;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ImageDownloadService method readResponse.
/**
* {@inheritDoc}
*/
protected void readResponse(InputStream input) throws IOException {
int imageScaleWidth = -1, imageScaleHeight = -1;
if (fastScale) {
if (toScale != null) {
imageScaleWidth = toScale.getWidth();
imageScaleHeight = toScale.getHeight();
} else {
if (placeholder != null) {
imageScaleWidth = placeholder.getWidth();
imageScaleHeight = placeholder.getHeight();
}
}
}
if (cacheImages) {
if (destinationFile != null) {
result = FileEncodedImage.create(destinationFile, input, imageScaleWidth, imageScaleHeight);
} else {
EncodedImage e = EncodedImage.create(input);
if (maintainAspectRatio) {
float actualW = e.getWidth();
float actualH = e.getHeight();
float r2 = Math.min(((float) imageScaleWidth) / actualW, ((float) imageScaleHeight) / actualH);
imageScaleWidth = (int) (actualW * r2);
imageScaleHeight = (int) (actualH * r2);
}
// workaround for http://stackoverflow.com/questions/35347353/label-image-scale-issue-in-codename-one-library-3-3/35354605
if (imageScaleWidth > -1 || imageScaleHeight > -1) {
e = e.scaledEncoded(imageScaleWidth, imageScaleHeight);
}
result = StorageImage.create(cacheId, e.getImageData(), imageScaleWidth, imageScaleHeight, keep);
// if the storage has failed create the image from the stream
if (result == null) {
result = e;
}
}
} else {
result = EncodedImage.create(input);
}
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToStorage.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param cacheId a unique identifier to be used to store the image into storage
* @param keep if set to true keeps the file in RAM once loaded
*/
public static void createImageToStorage(String url, ActionListener callback, String cacheId, boolean keep) {
Image im = cacheImage(cacheId, keep, null, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.cacheId = cacheId;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToStorage.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally to the Storage
*
* @param url the image URL
* @param l the Label that should be updated when the data arrives
* to just use storage and the url as the key
* @param cacheId a unique identifier to be used to store the image into storage
* @param toScale the scale dimension or null
* @param priority the priority for the task
*/
private static void createImageToStorage(final String url, final Label l, final String cacheId, final boolean keep, final Dimension toScale, final byte priority, final Image placeholder, final boolean maintainAspectRatio) {
if (Display.getInstance().isEdt()) {
Display.getInstance().scheduleBackgroundTask(new Runnable() {
public void run() {
createImageToStorage(url, l, cacheId, keep, toScale, priority, placeholder, maintainAspectRatio);
}
});
return;
}
Image im = cacheImage(cacheId, keep, null, toScale, placeholder, maintainAspectRatio);
if (im != null) {
if (!fastScale && toScale != null) {
im = scaleImage(im, toScale, defaultMaintainAspectRatio);
}
final Image i = im;
Display.getInstance().callSerially(new Runnable() {
public void run() {
l.setIcon(i);
Form f = l.getComponentForm();
if (f != null) {
f.revalidate();
}
}
});
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, l);
i.maintainAspectRatio = maintainAspectRatio;
i.setDuplicateSupported(true);
i.cacheImages = true;
i.toScale = toScale;
i.cacheId = cacheId;
i.placeholder = placeholder;
i.setPriority(priority);
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class Dialog method initImpl.
private void initImpl(String dialogUIID, String dialogTitleUIID, Layout lm) {
super.getContentPane().setUIID(dialogUIID);
super.getTitleComponent().setText("");
super.getTitleComponent().setVisible(false);
super.getTitleArea().setVisible(false);
super.getTitleArea().setUIID("Container");
lockStyleImages(getUnselectedStyle());
titleArea.setVisible(false);
if (lm != null) {
dialogContentPane = new Container(lm);
} else {
dialogContentPane = new Container();
}
dialogContentPane.setUIID("DialogContentPane");
dialogTitle = new Label("", dialogTitleUIID);
super.getContentPane().setLayout(new BorderLayout());
super.getContentPane().addComponent(BorderLayout.NORTH, dialogTitle);
super.getContentPane().addComponent(BorderLayout.CENTER, dialogContentPane);
super.getContentPane().setScrollable(false);
super.getContentPane().setAlwaysTensile(false);
super.getStyle().setBgTransparency(0);
super.getStyle().setBgImage(null);
super.getStyle().setBorder(null);
setSmoothScrolling(false);
deregisterAnimated(this);
}
Aggregations