Search in sources :

Example 71 with Image

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

the class Image method createIndexed.

/**
 * Creates an indexed image with byte data this method may return a native indexed image rather than
 * an instance of the IndexedImage class
 *
 * @param width image width
 * @param height image height
 * @param palette the color palette to use with the byte data
 * @param data byte data containing palette offsets to map to ARGB colors
 * @deprecated try to avoid using indexed images explicitly
 */
public static Image createIndexed(int width, int height, int[] palette, byte[] data) {
    IndexedImage i = new IndexedImage(width, height, palette, data);
    CodenameOneImplementation impl = Display.impl;
    if (impl.isNativeIndexed()) {
        return new Image(impl.createNativeIndexed(i));
    }
    return i;
}
Also used : CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 72 with Image

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

the class Label method getAvaliableSpaceForText.

int getAvaliableSpaceForText() {
    Style style = getStyle();
    int textSpaceW = getWidth() - style.getHorizontalPadding();
    Image icon = getIconFromState();
    if (icon != null && (getTextPosition() == Label.RIGHT || getTextPosition() == Label.LEFT)) {
        textSpaceW = textSpaceW - icon.getWidth();
    }
    return textSpaceW;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 73 with Image

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

the class Label method paintImpl.

void paintImpl(Graphics g) {
    initAutoResize();
    Object icn = null;
    Image i = getIconFromState();
    if (i != null) {
        icn = i.getImage();
    } else {
        // optimize away a common usage pattern for drawing the background only
        if (text == null || text.equals("") || text.equals(" ")) {
            return;
        }
    }
    // getUIManager().getLookAndFeel().drawLabel(g, this);
    int cmpX = getX() + g.getTranslateX();
    int cmpY = getY() + g.getTranslateY();
    int cmpHeight = getHeight();
    int cmpWidth = getWidth();
    Style s = getStyle();
    Font f = s.getFont();
    String t = text;
    if (text == null) {
        t = "";
    }
    Display.impl.drawLabelComponent(g.getGraphics(), cmpX, cmpY, cmpHeight, cmpWidth, s, t, icn, null, 0, gap, isRTL(), false, textPosition, getStringWidth(f), tickerRunning, shiftText, endsWith3Points, valign);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 74 with Image

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

the class EmailShare method share.

/**
 * {@inheritDoc}
 */
public void share(final String toShare, final String image, final String mimeType) {
    final Form currentForm = Display.getInstance().getCurrent();
    final Form contactsForm = new Form("Contacts");
    contactsForm.setLayout(new BorderLayout());
    contactsForm.setScrollable(false);
    contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
    contactsForm.show();
    Display.getInstance().startThread(new Runnable() {

        public void run() {
            String[] ids = ContactsManager.getAllContacts();
            if (ids == null || ids.length == 0) {
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
                        currentForm.showBack();
                    }
                });
                return;
            }
            ContactsModel model = new ContactsModel(ids);
            final List contacts = new List(model);
            contacts.setRenderer(createListRenderer());
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    contacts.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            final ShareForm[] f = new ShareForm[1];
                            Hashtable contact = (Hashtable) contacts.getSelectedItem();
                            if (image == null) {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            } else {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, image, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        msg.setAttachment(image);
                                        msg.setMimeType(mimeType);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            }
                        }
                    });
                    contactsForm.addComponent(BorderLayout.CENTER, contacts);
                    Command back = new Command("Back") {

                        public void actionPerformed(ActionEvent evt) {
                            currentForm.showBack();
                        }
                    };
                    contactsForm.addCommand(back);
                    contactsForm.setBackCommand(back);
                    contactsForm.revalidate();
                }
            });
        }
    }, "Email Thread").start();
}
Also used : Message(com.codename1.messaging.Message) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ContactsModel(com.codename1.contacts.ContactsModel)

Example 75 with Image

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

the class TestUtils method screenshotTest.

/**
 * The screenshot test takes a screenshot of the screen and compares it to
 * a prior screenshot, if both are 100% identical the test passes. If not
 * the test fails.<br>
 * If this is the first time the test is run then the screenshot is taken
 * and saved under the given name in the devices storage. The test passes
 * for this case but a warning is printed to the console. The name will have
 * .png appended to it so it will be identified.<br>
 * This test will only work on devices that support the ImageIO API with PNG
 * file format.
 *
 * @param screenshotName the name to use for the storage, must be unique!
 * @return true if the screenshots are identical or no prior screenshot exists
 * or if the test can't be run on this device. False if a screenshot exists and
 * it isn't 100% identical.
 */
public static boolean screenshotTest(String screenshotName) {
    if (verbose) {
        log("screenshotTest(" + screenshotName + ")");
    }
    try {
        ImageIO io = ImageIO.getImageIO();
        if (io == null || !io.isFormatSupported(ImageIO.FORMAT_PNG)) {
            log("screenshot test skipped due to no image IO support for PNG format");
            return true;
        }
        Image mute = Image.createImage(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
        Display.getInstance().getCurrent().paint(mute.getGraphics());
        screenshotName = screenshotName + ".png";
        if (Storage.getInstance().exists(screenshotName)) {
            int[] rgba = mute.getRGBCached();
            Image orig = Image.createImage(Storage.getInstance().createInputStream(screenshotName));
            int[] origRgba = orig.getRGBCached();
            orig = null;
            for (int iter = 0; iter < rgba.length; iter++) {
                if (rgba[iter] != origRgba[iter]) {
                    log("screenshots do not match at offset " + iter + " saving additional image under " + screenshotName + ".fail");
                    io.save(mute, Storage.getInstance().createOutputStream(screenshotName + ".fail"), ImageIO.FORMAT_PNG, 1);
                    return false;
                }
            }
        } else {
            io.save(mute, Storage.getInstance().createOutputStream(screenshotName), ImageIO.FORMAT_PNG, 1);
        }
        return true;
    } catch (IOException err) {
        log(err);
        return false;
    }
}
Also used : IOException(java.io.IOException) Image(com.codename1.ui.Image) ImageIO(com.codename1.ui.util.ImageIO)

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