Search in sources :

Example 1 with AsyncImage

use of com.codename1.rad.ui.image.AsyncImage in project CodeRAD by shannah.

the class ProfileAvatarView method update.

@Override
public void update() {
    if (iconLoaded) {
        return;
    }
    iconLoaded = true;
    if (getEntity() != null) {
        if (iconProp != null && !getEntity().isEmpty(iconProp)) {
            int sizePx = CN.convertToPixels(sizeMM);
            Image img = getEntity().getEntity().createImageToStorage(iconProp, EncodedImage.createFromImage(label.getIcon().fill(sizePx, sizePx), false), "@avatar" + label.getIcon().getWidth() + "x" + label.getIcon().getHeight(), URLImage.createMaskAdapter(getCircleMask()));
            if (img != null) {
                label.setIcon(img);
                return;
            }
        }
        if (fallbackSettings == FallbackSettings.FirstChar && nameProp != null && !getEntity().isEmpty(nameProp)) {
            FirstCharEntityImageRenderer renderer = new FirstCharEntityImageRenderer(sizeMM);
            AsyncImage img = renderer.createImage(this, nameProp, 0, false, false);
            if (img != null) {
                img.ready(im -> {
                    label.setIcon(im);
                    Form f = label.getComponentForm();
                    if (f != null) {
                        label.repaint();
                    }
                });
                return;
            }
        }
        FontImage.setMaterialIcon(label, defaultMaterialIcon, sizeMM);
    } else {
        FontImage.setMaterialIcon(label, defaultMaterialIcon, sizeMM);
    }
}
Also used : FirstCharEntityImageRenderer(com.codename1.rad.ui.image.FirstCharEntityImageRenderer) Form(com.codename1.ui.Form) AsyncImage(com.codename1.rad.ui.image.AsyncImage) WrappedImage(com.codename1.rad.ui.image.WrappedImage) FontImage(com.codename1.ui.FontImage) EncodedImage(com.codename1.ui.EncodedImage) AsyncImage(com.codename1.rad.ui.image.AsyncImage) Image(com.codename1.ui.Image) ComponentImage(ca.weblite.shared.components.ComponentImage) URLImage(com.codename1.ui.URLImage)

Aggregations

ComponentImage (ca.weblite.shared.components.ComponentImage)1 AsyncImage (com.codename1.rad.ui.image.AsyncImage)1 FirstCharEntityImageRenderer (com.codename1.rad.ui.image.FirstCharEntityImageRenderer)1 WrappedImage (com.codename1.rad.ui.image.WrappedImage)1 EncodedImage (com.codename1.ui.EncodedImage)1 FontImage (com.codename1.ui.FontImage)1 Form (com.codename1.ui.Form)1 Image (com.codename1.ui.Image)1 URLImage (com.codename1.ui.URLImage)1