Search in sources :

Example 1 with BasicEditField

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

the class BlackBerryImplementation method finishEdit.

void finishEdit(final boolean canceled) {
    // assigning the field here prevents a null pointer exception in the layout
    BasicEditField be = nativeEdit;
    if (be != null) {
        if (!Application.isEventDispatchThread()) {
            InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_LATER_finishEdit);
            Application.getApplication().invokeLater(i);
            return;
        }
        if (!canceled && lightweightEdit != null) {
            Display.getInstance().onEditingComplete(lightweightEdit, be.getText());
        }
        lightweightEdit = null;
        nativeEdit = null;
        canvas.delete(be);
        flushGraphics();
        disableBlockFolding();
        Display.getInstance().setShowVirtualKeyboard(false);
    }
}
Also used : BasicEditField(net.rim.device.api.ui.component.BasicEditField)

Example 2 with BasicEditField

use of net.rim.device.api.ui.component.BasicEditField 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

BasicEditField (net.rim.device.api.ui.component.BasicEditField)2 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 Font (net.rim.device.api.ui.Font)1 Graphics (net.rim.device.api.ui.Graphics)1