Search in sources :

Example 46 with TextArea

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

the class ResetableTextWatcher method showTextEditorAgain.

/**
 * Shows the native text field again after it has been hidden in async edit mode.
 */
private void showTextEditorAgain() {
    if (!mIsEditing || !isTextEditorHidden()) {
        return;
    }
    textEditorHidden = false;
    final TextArea ta = mEditText.mTextArea;
    // changed since the native aread was hidden.
    synchronized (this) {
        inputBuffer = new ArrayList<TextChange>();
    }
    // We are probably not on the EDT.  We need to be on the EDT to
    // safely get text from the textarea for synchronization.
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            // and the editing text area hasn't changed since we issued this call.
            if (mIsEditing && mEditText != null && mEditText.mTextArea == ta) {
                final String text = ta.getText();
                final int cursorPos = ta.getCursorPosition();
                // Now that we have our text from the CN1 text area, we need to be on the
                // Android UI thread in order to set the text of the native text editor.
                impl.getActivity().runOnUiThread(new Runnable() {

                    public void run() {
                        // and the editing text area hasn't changed since we issued this call.
                        if (mIsEditing && mEditText != null && mEditText.mTextArea == ta) {
                            // so that we don't find it in an inconsistent state.
                            synchronized (InPlaceEditView.this) {
                                // Let's record the cursor positions of the native
                                // text editor in case we need to use them after synchronizing
                                // with the CN1 textarea.
                                int start = cursorPos;
                                int end = cursorPos;
                                /*
                                    if (!inputBuffer.isEmpty()) {
                                        // If the input buffer isn't empty, then our start
                                        // and end positions will be "wonky"
                                        start = end = inputBuffer.get(0).atPos;

                                        // If the first change was a delete, then the atPos
                                        // will point to the beginning of the deleted section
                                        // so we need to adjust the end point to be *after*
                                        // the deleted section to begin.
                                        if (inputBuffer.get(0).deleteLength > 0) {
                                            end = start = end + inputBuffer.get(0).deleteLength;
                                        }
                                    }
                                    */
                                StringBuilder buf = new StringBuilder();
                                buf.append(text);
                                // Loop through any pending changes in the input buffer
                                // (I.e. key strokes that have occurred since we initiated
                                // this async callback hell!!)
                                List<TextChange> tinput = inputBuffer;
                                if (tinput != null) {
                                    for (TextChange change : tinput) {
                                        // end.
                                        if (change.textToAppend != null) {
                                            if (end >= 0 && end <= buf.length()) {
                                                buf.insert(end, change.textToAppend);
                                                end += change.textToAppend.length();
                                                start = end;
                                            } else {
                                                buf.append(change.textToAppend);
                                                end = buf.length();
                                                start = end;
                                            }
                                        } else // The change is "deleted" text.
                                        if (change.deleteLength > 0) {
                                            if (end >= change.deleteLength && end <= buf.length()) {
                                                buf.delete(end - change.deleteLength, end);
                                                end -= change.deleteLength;
                                                start = end;
                                            } else if (end > 0 && end < change.deleteLength) {
                                                buf.delete(0, end);
                                                end = 0;
                                                start = end;
                                            }
                                        }
                                    }
                                }
                                // Important:  Clear the input buffer so that the TextWatcher
                                // knows to stop filling it up.  We only need the inputBuffer
                                // to keep input between the original showTextEditorAgain() call
                                // and here.
                                inputBuffer = null;
                                mEditText.setText(buf.toString());
                                if (start < 0 || start > mEditText.getText().length()) {
                                    start = mEditText.getText().length();
                                }
                                if (end < 0 || end > mEditText.getText().length()) {
                                    end = mEditText.getText().length();
                                }
                                // Update the caret in the edit text field so we can continue.
                                mEditText.setSelection(start, end);
                            }
                        }
                    }
                });
            }
        }
    });
    reLayoutEdit(true);
    repaintTextEditor(true);
}
Also used : TextArea(com.codename1.ui.TextArea) Paint(android.graphics.Paint)

Example 47 with TextArea

use of com.codename1.ui.TextArea 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 48 with TextArea

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

the class TestUtils method setText.

/**
 * Sets the text for the given component
 * @param path the path to the component
 * @param text the text to set
 */
public static void setText(int[] path, String text) {
    if (verbose) {
        log("setText(" + toString(path) + ", " + text + ")");
    }
    Component c = getComponentByPath(path);
    if (c instanceof Label) {
        ((Label) c).setText(text);
        return;
    }
    ((TextArea) c).setText(text);
}
Also used : TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 49 with TextArea

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

the class TestUtils method assertTextAreaEndingWith.

/**
 * Asserts that we have a TextArea with the a text ending with the given text and with the given name
 * @param name the name of the TextArea
 * @param text the suffix to search for in the TextArea
 */
public static void assertTextAreaEndingWith(String name, String text) {
    if (verbose) {
        log("assertTextAreaEndingWith(" + name + ", " + text + ")");
    }
    TextArea l = (TextArea) findByName(name);
    assertBool(l != null, "Null area " + text);
    assertBool(l.getText().endsWith(text), "assertTextArea: \"" + l.getText() + "\" is not ending with: \"" + text + "\"");
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 50 with TextArea

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

the class TestUtils method assertTextAreaStartingWith.

/**
 * Asserts that we have a TextArea with the a text starting with the given text and with the given name
 * @param name the name of the TextArea
 * @param text the prefix to search for in the TextArea
 */
public static void assertTextAreaStartingWith(String name, String text) {
    if (verbose) {
        log("assertTextAreaStartingWith(" + name + ", " + text + ")");
    }
    TextArea l = (TextArea) findByName(name);
    assertBool(l != null, "Null area " + text);
    assertBool(l.getText().startsWith(text), "assertTextArea: \"" + l.getText() + "\" is not starting with: \"" + text + "\"");
}
Also used : TextArea(com.codename1.ui.TextArea)

Aggregations

TextArea (com.codename1.ui.TextArea)46 Component (com.codename1.ui.Component)22 Label (com.codename1.ui.Label)11 Button (com.codename1.ui.Button)10 Container (com.codename1.ui.Container)10 Form (com.codename1.ui.Form)10 RadioButton (com.codename1.ui.RadioButton)8 PeerComponent (com.codename1.ui.PeerComponent)6 TextField (com.codename1.ui.TextField)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Font (com.codename1.ui.Font)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 CheckBox (com.codename1.ui.CheckBox)4 Dialog (com.codename1.ui.Dialog)4 List (com.codename1.ui.List)4 Hashtable (java.util.Hashtable)4 Paint (android.graphics.Paint)3 Command (com.codename1.ui.Command)3 Slider (com.codename1.ui.Slider)3 ActionEvent (com.codename1.ui.events.ActionEvent)3