use of com.codename1.components.ReplaceableImage in project CodenameOne by codenameone.
the class CloudImageProperty method propertyValue.
/**
* {@inheritDoc}
*/
public Object propertyValue(CloudObject obj, String propertyName) {
final String key = (String) obj.getObject(idProperty);
if (key == null) {
return placeholderImage;
}
Image image = (Image) getCache().get(key);
if (image == null) {
ReplaceableImage r = inProgress.get(key);
if (r != null) {
return r;
}
final ReplaceableImage rp = ReplaceableImage.create(placeholderImage);
inProgress.put(key, rp);
ConnectionRequest cr = new ConnectionRequest() {
private EncodedImage e;
protected void readResponse(InputStream input) throws IOException {
e = EncodedImage.create(input);
;
if (e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) {
ImageIO io = ImageIO.getImageIO();
if (io != null) {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
io.save(new ByteArrayInputStream(e.getImageData()), bo, ImageIO.FORMAT_JPEG, placeholderImage.getWidth(), placeholderImage.getHeight(), 0.9f);
e = EncodedImage.create(bo.toByteArray());
}
}
}
protected void postResponse() {
rp.replace(e);
getCache().put(key, e);
inProgress.remove(key);
}
};
cr.setPost(false);
cr.setUrl(CloudStorage.getInstance().getUrlForCloudFileId(key));
NetworkManager.getInstance().addToQueue(cr);
return rp;
}
return image;
}
Aggregations