Search in sources :

Example 1 with Font

use of net.rim.device.api.ui.Font in project google-authenticator by google.

the class PinListFieldCallback method drawListRow.

/**
 * {@inheritDoc}
 */
public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
    PinInfo item = mItems[index];
    int iconWidth = mIcon.getWidth();
    int iconHeight = mIcon.getHeight();
    int iconX = width - PADDING - iconWidth;
    int iconY = y + Math.max(0, (mRowHeight - iconHeight) / 2);
    graphics.drawBitmap(iconX, iconY, iconWidth, iconHeight, mIcon, 0, 0);
    int textWidth = Math.max(0, width - iconWidth - PADDING * 3);
    int textX = PADDING;
    int textY = y + PADDING;
    int flags = Graphics.ELLIPSIS;
    Font savedFont = graphics.getFont();
    graphics.setFont(mUserFont);
    graphics.drawText(item.mUser, textX, textY, flags, textWidth);
    textY += mUserFont.getHeight();
    graphics.setFont(mPinFont);
    graphics.drawText(item.mPin, textX, textY, flags, textWidth);
    graphics.setFont(savedFont);
}
Also used : Font(net.rim.device.api.ui.Font)

Example 2 with Font

use of net.rim.device.api.ui.Font in project CodenameOne by codenameone.

the class BlackBerryImplementation method getSize.

public int getSize(Object nativeFont) {
    Font nf = (Font) font(nativeFont);
    int bbSize = Font.getDefault().getHeight();
    int diff = Font.getDefault().getHeight() / 3;
    if (nf.getHeight() == bbSize - diff) {
        return com.codename1.ui.Font.SIZE_SMALL;
    }
    if (nf.getHeight() == bbSize + diff) {
        return com.codename1.ui.Font.SIZE_LARGE;
    }
    return com.codename1.ui.Font.SIZE_MEDIUM;
}
Also used : Font(net.rim.device.api.ui.Font)

Example 3 with Font

use of net.rim.device.api.ui.Font in project CodenameOne by codenameone.

the class BlackBerryImplementation method getFace.

public int getFace(Object nativeFont) {
    Font nf = (Font) font(nativeFont);
    int s = nf.getStyle();
    int result = 0;
    if ((s & Font.BOLD) == Font.BOLD) {
        result |= com.codename1.ui.Font.STYLE_BOLD;
    }
    if ((s & Font.ITALIC) == Font.ITALIC) {
        result |= com.codename1.ui.Font.STYLE_ITALIC;
    }
    if ((s & Font.UNDERLINED) == Font.UNDERLINED) {
        result |= com.codename1.ui.Font.STYLE_UNDERLINED;
    }
    return result;
}
Also used : Font(net.rim.device.api.ui.Font)

Example 4 with Font

use of net.rim.device.api.ui.Font in project CodenameOne by codenameone.

the class BlackBerryImplementation method createFont.

public Object createFont(int face, int style, int size) {
    Font font = Font.getDefault();
    int bbSize = Font.getDefault().getHeight();
    int diff = Font.getDefault().getHeight() / 3;
    switch(size) {
        case com.codename1.ui.Font.SIZE_SMALL:
            bbSize -= diff;
            break;
        case com.codename1.ui.Font.SIZE_LARGE:
            bbSize += diff;
            break;
    }
    int bbStyle = Font.PLAIN;
    switch(style) {
        case com.codename1.ui.Font.STYLE_BOLD:
            bbStyle = Font.BOLD;
            break;
        case com.codename1.ui.Font.STYLE_ITALIC:
            bbStyle = Font.ITALIC;
            break;
        case com.codename1.ui.Font.STYLE_PLAIN:
            bbStyle = Font.PLAIN;
            break;
        case com.codename1.ui.Font.STYLE_UNDERLINED:
            bbStyle = Font.UNDERLINED;
            break;
        default:
            // probably bold/italic
            bbStyle = Font.BOLD | Font.ITALIC;
            break;
    }
    switch(face) {
        case com.codename1.ui.Font.FACE_MONOSPACE:
            font = font.getFontFamily().getFont(bbStyle | FontFamily.MONO_BITMAP_FONT, bbSize);
            break;
        case com.codename1.ui.Font.FACE_PROPORTIONAL:
            font = font.getFontFamily().getFont(bbStyle | FontFamily.SCALABLE_FONT, bbSize);
            break;
        case com.codename1.ui.Font.FACE_SYSTEM:
            font = font.derive(bbStyle, bbSize, Ui.UNITS_px, Font.ANTIALIAS_SUBPIXEL, font.getEffects());
            break;
    }
    return font;
}
Also used : Font(net.rim.device.api.ui.Font)

Example 5 with Font

use of net.rim.device.api.ui.Font in project CodenameOne by codenameone.

the class BlackBerryImplementation method nativeEdit.

public void nativeEdit(final Component cmp, final int maxSize, final int constraint, String text, int keyCode) {
    if (nativeEdit != null) {
        finishEdit(true);
    }
    lightweightEdit = (TextArea) cmp;
    if (keyCode > 0 && getKeyboardType() == Display.KEYBOARD_TYPE_QWERTY) {
        // if this is a number
        if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL || (constraint & TextArea.NUMERIC) == TextArea.NUMERIC || (constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
            if (keyCode == 119) {
                text += "1";
            } else if (keyCode == 101) {
                text += "2";
            } else if (keyCode == 114) {
                text += "3";
            } else if (keyCode == 115) {
                text += "4";
            } else if (keyCode == 100) {
                text += "5";
            } else if (keyCode == 102) {
                text += "6";
            } else if (keyCode == 122) {
                text += "7";
            } else if (keyCode == 120) {
                text += "8";
            } else if (keyCode == 99) {
                text += "9";
            }
        } else {
            text += ((char) keyCode);
        }
        lightweightEdit.setText(text);
    }
    class LightweightEdit implements Runnable, Animation {

        public void run() {
            long type = 0;
            TextArea lightweightEditTmp = lightweightEdit;
            if (lightweightEditTmp == null) {
                return;
            }
            int constraint = lightweightEditTmp.getConstraint();
            if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL) {
                type = BasicEditField.FILTER_REAL_NUMERIC;
            } else if ((constraint & TextArea.EMAILADDR) == TextArea.EMAILADDR) {
                type = BasicEditField.FILTER_EMAIL;
            } else if ((constraint & TextArea.NUMERIC) == TextArea.NUMERIC) {
                type = BasicEditField.FILTER_NUMERIC;
            }
            if ((constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
                type = BasicEditField.FILTER_PHONE;
            }
            if ((constraint & TextArea.NON_PREDICTIVE) == TextArea.NON_PREDICTIVE) {
                type |= BasicEditField.NO_COMPLEX_INPUT;
            }
            if (lightweightEditTmp.isSingleLineTextArea()) {
                type |= BasicEditField.NO_NEWLINE;
            }
            if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
                nativeEdit = new BBPasswordEditField(lightweightEditTmp, type, maxSize);
            } else {
                nativeEdit = new BBEditField(lightweightEditTmp, type, maxSize);
            }
            nativeEdit.setEditable(true);
            Font f = nativeEdit.getFont();
            if (f.getHeight() > lightweightEditTmp.getStyle().getFont().getHeight()) {
                nativeEdit.setFont(f.derive(f.getStyle(), lightweightEditTmp.getStyle().getFont().getHeight()));
            }
            canvas.add(nativeEdit);
            nativeEdit.setCursorPosition(lightweightEditTmp.getText().length());
            try {
                nativeEdit.setFocus();
            } catch (Throwable t) {
            // no idea why this throws an exception sometimes
            // t.printStackTrace();
            }
        }

        public boolean animate() {
            BasicEditField ef = nativeEdit;
            Component lw = lightweightEdit;
            if (lw == null || lw.getComponentForm() != Display.getInstance().getCurrent()) {
                Display.getInstance().getCurrent().deregisterAnimated(this);
                finishEdit(false);
            } else {
                if (ef != null) {
                    if (ef.isDirty()) {
                        lw.repaint();
                    }
                }
            }
            return false;
        }

        public void paint(com.codename1.ui.Graphics g) {
        }
    }
    LightweightEdit lw = new LightweightEdit();
    Display.getInstance().getCurrent().registerAnimated(lw);
    Application.getApplication().invokeLater(lw);
}
Also used : TextArea(com.codename1.ui.TextArea) BasicEditField(net.rim.device.api.ui.component.BasicEditField) Font(net.rim.device.api.ui.Font) Graphics(net.rim.device.api.ui.Graphics) Animation(com.codename1.ui.animations.Animation) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Aggregations

Font (net.rim.device.api.ui.Font)6 Component (com.codename1.ui.Component)1 PeerComponent (com.codename1.ui.PeerComponent)1 TextArea (com.codename1.ui.TextArea)1 Animation (com.codename1.ui.animations.Animation)1 Graphics (net.rim.device.api.ui.Graphics)1 BasicEditField (net.rim.device.api.ui.component.BasicEditField)1