Search in sources :

Example 21 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class CodenameOneView method setInputType.

public void setInputType(EditorInfo editorInfo) {
    /**
     * do not use the enter key to fire some kind of action!
     */
    // editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
    Component txtCmp = Display.getInstance().getCurrent().getFocused();
    if (txtCmp != null && txtCmp instanceof TextArea) {
        TextArea txt = (TextArea) txtCmp;
        if (txt.isSingleLineTextArea()) {
            editorInfo.imeOptions |= EditorInfo.IME_ACTION_DONE;
        } else {
            editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
        }
        int inputType = 0;
        int constraint = txt.getConstraint();
        if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
            constraint = constraint ^ TextArea.PASSWORD;
        }
        switch(constraint) {
            case TextArea.NUMERIC:
                inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_SIGNED;
                break;
            case TextArea.DECIMAL:
                inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_DECIMAL;
                break;
            case TextArea.PHONENUMBER:
                inputType = EditorInfo.TYPE_CLASS_PHONE;
                break;
            case TextArea.EMAILADDR:
                inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
                break;
            case TextArea.URL:
                inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_URI;
                break;
            default:
                inputType = EditorInfo.TYPE_CLASS_TEXT;
                break;
        }
        editorInfo.inputType = inputType;
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 22 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class Validator method addConstraint.

/**
 * Places a constraint on the validator, returns this object so constraint additions can be chained.
 * Notice that only one constraint
 * @param cmp the component to validate
 * @param c the constraint or constraints
 * @return this object so we can write code like v.addConstraint(cmp1, cons).addConstraint(cmp2, otherConstraint);
 */
public Validator addConstraint(Component cmp, Constraint... c) {
    if (c.length == 1) {
        constraintList.put(cmp, c[0]);
    } else {
        constraintList.put(cmp, new GroupConstraint(c));
    }
    bindDataListener(cmp);
    boolean isV = isValid();
    for (Component btn : submitButtons) {
        btn.setEnabled(isV);
    }
    return this;
}
Also used : TextComponent(com.codename1.ui.TextComponent) Component(com.codename1.ui.Component) InputComponent(com.codename1.ui.InputComponent)

Example 23 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class GameCanvasImplementation method editString.

/**
 * @inheritDoc
 */
public void editString(Component cmp, int maxSize, int constraint, String text, int keyCode) {
    UIManager m = UIManager.getInstance();
    CONFIRM_COMMAND = new Command(m.localize("ok", "OK"), Command.OK, 1);
    CANCEL_COMMAND = new Command(m.localize("cancel", "Cancel"), Command.CANCEL, 2);
    if (mid.getAppProperty("forceBackCommand") != null) {
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    currentTextBox = new TextBox("", "", maxSize, TextArea.ANY);
    currentTextBox.setCommandListener((CommandListener) canvas);
    currentTextBox.addCommand(CONFIRM_COMMAND);
    currentTextBox.addCommand(CANCEL_COMMAND);
    currentTextComponent = cmp;
    currentTextBox.setMaxSize(maxSize);
    currentTextBox.setString(text);
    currentTextBox.setConstraints(constraint);
    display.setCurrent(currentTextBox);
    ((C) canvas).setDone(false);
    Display.getInstance().invokeAndBlock(((C) canvas));
}
Also used : Command(javax.microedition.lcdui.Command) UIManager(com.codename1.ui.plaf.UIManager) TextBox(javax.microedition.lcdui.TextBox)

Example 24 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint 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

Component (com.codename1.ui.Component)8 TextArea (com.codename1.ui.TextArea)6 Style (com.codename1.ui.plaf.Style)5 Container (com.codename1.ui.Container)4 PeerComponent (com.codename1.ui.PeerComponent)4 Point (java.awt.Point)3 BrowserComponent (com.codename1.ui.BrowserComponent)2 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)2 Dimension (com.codename1.ui.geom.Dimension)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 Inset (com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)2 UITimer (com.codename1.ui.util.UITimer)2 java.awt (java.awt)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 AdjustmentListener (java.awt.event.AdjustmentListener)2 FocusEvent (java.awt.event.FocusEvent)2 FocusListener (java.awt.event.FocusListener)2 HierarchyBoundsListener (java.awt.event.HierarchyBoundsListener)2