Search in sources :

Example 16 with TextField

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

the class BooleanContainer method editNextTextArea.

/**
 * Opens onscreenkeyboard for the next textfield. The method works in EDT if
 * needed.
 */
public static void editNextTextArea() {
    Runnable task = new Runnable() {

        public void run() {
            Component next = getNextEditComponent();
            if (next != null) {
                if (next instanceof TextArea) {
                    TextArea text = (TextArea) next;
                    text.requestFocus();
                    Display.getInstance().editString(next, text.getMaxSize(), text.getConstraint(), text.getText(), 0);
                }
            }
        }
    };
    Display.getInstance().callSerially(task);
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component)

Example 17 with TextField

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

the class HTMLComponent method setInputFormat.

/**
 * Sets input format validation for a TextArea or TextField
 * This is called from the CSSEngine, and since it is done after the TextArea has been added it is a bit more complicated
 *
 * @param inputField The TextArea to place the input format validation on
 * @param inputFormat The string representing the input format
 * @return The same TextArea or a new instance representing the element
 */
TextArea setInputFormat(final TextArea inputField, String inputFormat) {
    TextArea returnInputField = inputField;
    if (SUPPORT_INPUT_FORMAT) {
        HTMLForm form = (HTMLForm) textfieldsToForms.get(inputField);
        if (form != null) {
            HTMLInputFormat format = HTMLInputFormat.getInputFormat(inputFormat);
            if (format != null) {
                form.setInputFormat(inputField, format);
                final TextArea newInputField = format.applyConstraints(inputField);
                returnInputField = newInputField;
                // Replace operation must be done on the EDT if the form is visible
                if (Display.getInstance().getCurrent() != inputField.getComponentForm()) {
                    // ((inputField.getComponentForm()==null) ||
                    // Applying the constraints may return a new instance that has to be replaced in the form
                    inputField.getParent().replace(inputField, newInputField, null);
                } else {
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            // Applying the constraints may return a new instance that has to be replaced in the form
                            inputField.getParent().replace(inputField, newInputField, null);
                        }
                    });
                }
                if (firstFocusable == inputField) {
                    firstFocusable = newInputField;
                }
            }
        }
    }
    return returnInputField;
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 18 with TextField

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

the class CodenameOneInputConnection method setComposingText.

@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            TextField t = (TextField) txtCmp;
            String textFieldText = t.getText();
            StringBuilder sb = new StringBuilder(textFieldText);
            sb.replace(sb.length() - composingText.length(), sb.length(), text.toString());
            int cursorPosition = t.getCursorPosition();
            composingText = text.toString();
            t.setText(sb.toString());
            t.setCursorPosition(cursorPosition + text.length());
            updateExtractedText();
            return true;
        }
    }
    return false;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Example 19 with TextField

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

the class CodenameOneInputConnection method getEditable.

public Editable getEditable() {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            TextField t = (TextField) txtCmp;
            String textFieldText = t.getText();
            edit.clear();
            edit.append(textFieldText);
            return edit;
        }
    }
    return super.getEditable();
}
Also used : TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Example 20 with TextField

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

the class CodenameOneInputConnection method getTextBeforeCursor.

@Override
public CharSequence getTextBeforeCursor(int length, int flags) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            String txt = ((TextField) txtCmp).getText();
            int position = ((TextField) txtCmp).getCursorPosition();
            int start;
            if (position > 0) {
                start = txt.subSequence(0, position).toString().lastIndexOf(" ");
                if (start > 0) {
                    return txt.subSequence(start, position);
                } else {
                    return txt.subSequence(0, position);
                }
            }
        }
    }
    return "";
}
Also used : TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Aggregations

TextField (com.codename1.ui.TextField)19 Component (com.codename1.ui.Component)16 TextArea (com.codename1.ui.TextArea)10 Button (com.codename1.ui.Button)8 Container (com.codename1.ui.Container)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)6 Form (com.codename1.ui.Form)5 ActionListener (com.codename1.ui.events.ActionListener)5 BorderLayout (com.codename1.ui.layouts.BorderLayout)5 CheckBox (com.codename1.ui.CheckBox)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 BoxLayout (com.codename1.ui.layouts.BoxLayout)4 FlowLayout (com.codename1.ui.layouts.FlowLayout)3 Paint (android.graphics.Paint)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 List (com.codename1.ui.List)2 Slider (com.codename1.ui.Slider)2 SelectionListener (com.codename1.ui.events.SelectionListener)2 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)2