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