Search in sources :

Example 1 with Display

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

the class Border method getMinimumWidth.

/**
 * Returns the minimum size required to properly display this border, normally this
 * is 0 but a border might deem itself undisplayable with too small a size e.g. for
 * the case of an image border the minimum height would be top + bottom and the minimum
 * width would be left+right
 *
 * @return 0 if not applicable or a dimension if it is.
 */
public int getMinimumWidth() {
    if (images != null) {
        if (images.length < 4) {
            if (type == TYPE_IMAGE_HORIZONTAL) {
                return images[0].getWidth() + images[1].getWidth();
            } else {
                return images[0].getWidth();
            }
        }
        Image topLeft = images[4];
        Image topRight = images[5];
        return topLeft.getWidth() + topRight.getWidth();
    }
    return 0;
}
Also used : RGBImage(com.codename1.ui.RGBImage) Image(com.codename1.ui.Image)

Example 2 with Display

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

the class Border method getMinimumHeight.

/**
 * Returns the minimum size required to properly display this border, normally this
 * is 0 but a border might deem itself undisplayable with too small a size e.g. for
 * the case of an image border the minimum height would be top + bottom and the minimum
 * width would be left+right
 *
 * @return 0 if not applicable or a dimension if it is.
 */
public int getMinimumHeight() {
    if (images != null) {
        if (images.length < 4) {
            if (type == TYPE_IMAGE_HORIZONTAL) {
                return images[0].getHeight();
            } else {
                return images[0].getHeight() + images[1].getHeight();
            }
        }
        Image topLeft = images[4];
        Image bottomRight = images[7];
        return topLeft.getHeight() + bottomRight.getHeight();
    }
    return 0;
}
Also used : RGBImage(com.codename1.ui.RGBImage) Image(com.codename1.ui.Image)

Example 3 with Display

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

the class DefaultLookAndFeel method drawTextArea.

/**
 * {@inheritDoc}
 */
public void drawTextArea(Graphics g, TextArea ta) {
    setFG(g, ta);
    int line = ta.getLines();
    int oX = g.getClipX();
    int oY = g.getClipY();
    int oWidth = g.getClipWidth();
    int oHeight = g.getClipHeight();
    Font f = ta.getStyle().getFont();
    int fontHeight = f.getHeight();
    int align = reverseAlignForBidi(ta);
    int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
    int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
    int topPadding = ta.getStyle().getPaddingTop();
    boolean shouldBreak = false;
    for (int i = 0; i < line; i++) {
        int x = ta.getX() + leftPadding;
        int y = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * i;
        if (Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
            String rowText = (String) ta.getTextAt(i);
            // display ******** if it is a password field
            String displayText = "";
            if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
                int rlen = rowText.length();
                for (int j = 0; j < rlen; j++) {
                    displayText += passwordChar;
                }
            } else {
                displayText = rowText;
            }
            switch(align) {
                case Component.RIGHT:
                    x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
                    break;
                case Component.CENTER:
                    x += (ta.getWidth() - leftPadding - rightPadding - f.stringWidth(displayText)) / 2;
                    break;
            }
            int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
            // add "..." at the last row
            if (ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line) {
                if (displayText.length() > 3) {
                    displayText = displayText.substring(0, displayText.length() - 3);
                }
                g.drawString(displayText + "...", x, y, ta.getStyle().getTextDecoration());
                return;
            } else {
                g.drawString(displayText, x, y, ta.getStyle().getTextDecoration());
            }
            shouldBreak = true;
        } else {
            if (shouldBreak) {
                break;
            }
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 4 with Display

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

the class DefaultLookAndFeel method drawTextField.

/**
 * {@inheritDoc}
 */
public void drawTextField(Graphics g, TextArea ta) {
    setFG(g, ta);
    // display ******** if it is a password field
    String displayText = getTextFieldString(ta);
    Style style = ta.getStyle();
    int x = 0;
    // ta.getCursorX();
    int cursorCharPosition = ta.getCursorPosition();
    Font f = style.getFont();
    int cursorX = 0;
    int xPos = 0;
    int align = reverseAlignForBidi(ta);
    int displayX = 0;
    String inputMode = ta.getInputMode();
    int inputModeWidth = f.stringWidth(inputMode);
    // QWERTY devices don't quite have an input mode hide it also when we have a VK
    if (ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
        inputMode = "";
        inputModeWidth = 0;
    }
    if (ta.isSingleLineTextArea()) {
        // there is currently no support for CENTER aligned text fields
        if (align == Component.LEFT) {
            if (cursorCharPosition > 0) {
                cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
                xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
                cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
                // no point in showing the input mode when there is only one input mode...
                if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length == 1) {
                    inputModeWidth = 0;
                }
                if (ta.isEnableInputScroll()) {
                    if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
                        if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2) {
                            x = ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2 - xPos - 1;
                        }
                    }
                }
            }
            displayX = ta.getX() + x + style.getPaddingLeft(ta.isRTL());
        } else {
            x = 0;
            cursorX = getTextFieldCursorX(ta);
            int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
            int endX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL();
            if (cursorX < baseX) {
                x = baseX - cursorX;
            } else {
                if (cursorX > endX) {
                    x = endX - cursorX;
                }
            }
            displayX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL() - f.stringWidth(displayText) + x;
        }
        int cx = g.getClipX();
        int cy = g.getClipY();
        int cw = g.getClipWidth();
        int ch = g.getClipHeight();
        int clipx = ta.getX() + style.getPaddingLeft(ta.isRTL());
        int clipw = ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - style.getPaddingRight(ta.isRTL());
        // g.pushClip();
        g.clipRect(clipx, cy, clipw, ch);
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), style.getTextDecoration());
                break;
            case Component.CENTER:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2, style.getTextDecoration());
                break;
            default:
                g.drawString(displayText, displayX, ta.getY() + style.getPaddingTop(), style.getTextDecoration());
                break;
        }
        g.setClip(cx, cy, cw, ch);
    // g.popClip();
    } else {
        drawTextArea(g, ta);
    }
    // no point in showing the input mode when there is only one input mode...
    if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length > 1) {
        if (ta.handlesInput() && ta.getWidth() / 2 > inputModeWidth) {
            int drawXPos = ta.getX() + style.getPaddingLeft(ta.isRTL());
            if ((!ta.isRTL() && style.getAlignment() == Component.LEFT) || (ta.isRTL() && style.getAlignment() == Component.RIGHT)) {
                drawXPos = drawXPos + ta.getWidth() - inputModeWidth - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL();
            }
            g.setColor(style.getFgColor());
            int inputIndicatorY = ta.getY() + ta.getScrollY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight();
            g.fillRect(drawXPos, inputIndicatorY, inputModeWidth, f.getHeight(), (byte) 140);
            g.setColor(style.getBgColor());
            g.drawString(inputMode, drawXPos, inputIndicatorY);
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 5 with Display

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

the class Message method sendMessageViaCloudSync.

/**
 * <p>Send an email message using the Codename One cloud to send the message, notice that this API
 * will only work for pro accounts.</p>
 * <script src="https://gist.github.com/codenameone/8229c1d4627ab3a1f17e.js"></script>
 *
 * @param sender the name of the sender, notice all email will arrive from Codename One to avoid spam issues
 * @param recipient the email for the recipient
 * @param recipientName the display name for the recipient
 * @param subject e-mail subject
 * @param plainTextBody when sending an HTML message you should also attach a plain text fallback message,
 * this is redundant if the email is a plain text message to begin with
 * @return true if sending succeeded
 */
public boolean sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody) {
    ConnectionRequest r = createMessage(sender, recipient, recipientName, subject, plainTextBody);
    r.setFailSilently(true);
    NetworkManager.getInstance().addToQueueAndWait(r);
    return r.getResposeCode() == 200;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Aggregations

Display (com.codename1.ui.Display)10 Component (com.codename1.ui.Component)7 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Container (com.codename1.ui.Container)4 Dialog (com.codename1.ui.Dialog)4 Form (com.codename1.ui.Form)4 IOException (java.io.IOException)4 RGBImage (com.codename1.ui.RGBImage)3 InputStream (java.io.InputStream)3 ParseException (java.text.ParseException)3 Hashtable (java.util.Hashtable)3 Cursor (android.database.Cursor)2 Paint (android.graphics.Paint)2 Paint (com.codename1.charts.compat.Paint)2 Point (com.codename1.charts.models.Point)2 SpanButton (com.codename1.components.SpanButton)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 Button (com.codename1.ui.Button)2 Font (com.codename1.ui.Font)2