Search in sources :

Example 61 with TextArea

use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method onEditorAction.

/**
 * This method will be called by our EditText control when the action
 * key (Enter/Go/Send) on the soft keyboard will be pressed.
 * @param actionCode
 * @return task to run after call to super.onEditorAction. Returns null if action was consumed (tapped Next in async mode) and super.onEditorAction do not have to be called.
 */
Runnable onEditorAction(int actionCode) {
    actionCode = actionCode & 0xf;
    final int fActionCode = actionCode;
    boolean hasNext = false;
    Component next = null;
    if (EditorInfo.IME_ACTION_NEXT == actionCode && mEditText != null && mEditText.mTextArea != null) {
        next = mEditText.mTextArea.getComponentForm().getNextComponent(mEditText.mTextArea);
        if (next != null) {
            hasNext = true;
        }
        if (next != null && next instanceof TextArea) {
            nextTextArea = (TextArea) next;
        }
    }
    if (hasNext && nextTextArea != null && impl.isAsyncEditMode()) {
        // in async edit mode go right to next field edit to avoid hiding and showing again the native edit text
        final TextArea theNext = nextTextArea;
        nextTextArea = null;
        mLastEditText = mEditText;
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                edit(sInstance.impl, theNext, theNext.getConstraint());
            }
        });
        return null;
    } else {
        final Component fNext = next;
        final boolean fHasNext = hasNext;
        return new Runnable() {

            @Override
            public void run() {
                endEditing(REASON_IME_ACTION, false, fActionCode);
                if (fHasNext && fNext != null) {
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            final Form f = fNext.getComponentForm();
                            if (f == null) {
                                return;
                            }
                            f.addSizeChangedListener(new ActionListener() {

                                @Override
                                public void actionPerformed(ActionEvent evt) {
                                    f.removeSizeChangedListener(this);
                                    fNext.requestFocus();
                                    fNext.startEditingAsync();
                                }
                            });
                        }
                    });
                }
            }
        };
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) Component(com.codename1.ui.Component) Paint(android.graphics.Paint)

Example 62 with TextArea

use of com.vaadin.v7.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 63 with TextArea

use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method startEditing.

/**
 * Start editing the given text-area
 * This method is executed on the UI thread, so UI manipulation is safe here.
 * @param activity Current running activity
 * @param textArea The TextAreaData instance that wraps the CN1 TextArea that our internal EditText needs to overlap.  We use
 *                 a TextAreaData so that the text area properties can be accessed off the EDT safely.
 * @param codenameOneInputType One of the input type constants in com.codename1.ui.TextArea
 * @param initialText The text that appears in the Codename One text are before the call to startEditing
 * @param isEditedFieldSwitch if true, then special case for async edit mode - the native editing is already active, no need to show
 *                            native field, just change the connected field
 */
private synchronized void startEditing(Activity activity, TextAreaData textArea, String initialText, int codenameOneInputType, final boolean isEditedFieldSwitch) {
    int txty = lastTextAreaY = textArea.getAbsoluteY() + textArea.getScrollY();
    int txtx = lastTextAreaX = textArea.getAbsoluteX() + textArea.getScrollX();
    lastTextAreaWidth = textArea.getWidth();
    lastTextAreaHeight = textArea.getHeight();
    int paddingTop = 0;
    int paddingLeft = textArea.paddingLeft;
    int paddingRight = textArea.paddingRight;
    int paddingBottom = textArea.paddingBottom;
    // An ugly hack to smooth over an apparent race condition where
    // the lightweight textarea is not repainted after the native text field
    // becomes visible - resulting in the hint still appearing while typing.
    // https://github.com/codenameone/CodenameOne/issues/2629
    // We just blindly repaint the textfield every 50ms for half a second
    // to make sure it gets a repaint properly.
    final TextArea fTextArea = textArea.textArea;
    new Thread(new Runnable() {

        public void run() {
            for (int i = 0; i < 10; i++) {
                com.codename1.io.Util.sleep(50);
                com.codename1.ui.CN.callSerially(new Runnable() {

                    public void run() {
                        fTextArea.repaint();
                    }
                });
            }
        }
    }).start();
    if (textArea.isTextField) {
        switch(textArea.getVerticalAlignment()) {
            case Component.BOTTOM:
                paddingTop = textArea.getHeight() - textArea.paddingBottom - textArea.fontHeight;
                break;
            case Component.CENTER:
                paddingTop = textArea.getHeight() / 2 - textArea.fontHeight / 2;
                break;
            default:
                paddingTop = textArea.paddingTop;
                break;
        }
    } else {
        paddingTop = textArea.paddingTop;
    }
    int id = activity.getResources().getIdentifier("cn1Style", "attr", activity.getApplicationInfo().packageName);
    if (!isEditedFieldSwitch) {
        mEditText = new EditView(activity, textArea.textArea, this, id);
        defaultInputType = mEditText.getInputType();
        defaultIMEOptions = mEditText.getImeOptions();
    } else {
        mEditText.switchToTextArea(textArea.textArea);
    }
    if (textArea.getClientProperty("blockCopyPaste") != null || Display.getInstance().getProperty("blockCopyPaste", "false").equals("true")) {
        // The code below is taken from this stackoverflow answer: http://stackoverflow.com/a/22756538/756809
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

                @Override
                public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                    menu.clear();
                }
            });
        } else {
            mEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
        }
    } else if (isEditedFieldSwitch) {
        // reset copy-paste protection
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(null);
        } else {
            mEditText.setCustomSelectionActionModeCallback(null);
        }
    }
    if (!isEditedFieldSwitch) {
        mEditText.addTextChangedListener(mEditText.mTextWatcher);
    }
    mEditText.setBackgroundDrawable(null);
    mEditText.setFocusableInTouchMode(true);
    mEditLayoutParams = new FrameLayout.LayoutParams(0, 0);
    // Set the appropriate gravity so that the left and top margins will be
    // taken into account
    mEditLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    mEditLayoutParams.setMargins(txtx, txty, 0, 0);
    mEditLayoutParams.width = textArea.getWidth();
    mEditLayoutParams.height = textArea.getHeight();
    mEditText.setLayoutParams(mEditLayoutParams);
    if (textArea.isRTL()) {
        mEditText.setGravity(Gravity.RIGHT | Gravity.TOP);
    } else {
        mEditText.setGravity(Gravity.LEFT | Gravity.TOP);
    }
    mEditText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    Component nextDown = textArea.nextDown;
    boolean imeOptionTaken = true;
    int ime = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    if (textArea.isSingleLineTextArea() || textArea.getDoneListener() != null) {
        if (textArea.getClientProperty("searchField") != null) {
            mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEARCH);
        } else {
            if (textArea.getClientProperty("sendButton") != null) {
                mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEND);
            } else {
                if (textArea.getClientProperty("goButton") != null) {
                    mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_GO);
                } else {
                    if (textArea.getDoneListener() != null) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                    } else if (nextDown != null) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_NEXT);
                    } else {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                        imeOptionTaken = false;
                    }
                }
            }
        }
    }
    mEditText.setSingleLine(textArea.isSingleLineTextArea());
    mEditText.setAdapter((ArrayAdapter<String>) null);
    mEditText.setText(initialText);
    if (!textArea.isSingleLineTextArea() && textArea.textArea.isGrowByContent() && textArea.textArea.getGrowLimit() > -1) {
        defaultMaxLines = mEditText.getMaxLines();
        mEditText.setMaxLines(textArea.textArea.getGrowLimit());
    }
    if (textArea.nativeHintBool && textArea.getHint() != null) {
        mEditText.setHint(textArea.getHint());
    }
    if (!isEditedFieldSwitch) {
        addView(mEditText, mEditLayoutParams);
    }
    invalidate();
    setVisibility(VISIBLE);
    bringToFront();
    mEditText.requestFocus();
    Object nativeFont = textArea.nativeFont;
    if (nativeFont == null) {
        nativeFont = impl.getDefaultFont();
    }
    Paint p = (Paint) ((AndroidImplementation.NativeFont) nativeFont).font;
    mEditText.setTypeface(p.getTypeface());
    mEditText.setTextScaleX(p.getTextScaleX());
    mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, p.getTextSize());
    int fgColor = textArea.fgColor;
    mEditText.setTextColor(Color.rgb(fgColor >> 16, (fgColor & 0x00ff00) >> 8, (fgColor & 0x0000ff)));
    boolean password = false;
    if ((codenameOneInputType & TextArea.PASSWORD) == TextArea.PASSWORD) {
        codenameOneInputType = codenameOneInputType ^ TextArea.PASSWORD;
        password = true;
    }
    if (textArea.isSingleLineTextArea()) {
        mEditText.setInputType(getAndroidInputType(codenameOneInputType));
        // if not ime was explicity requested and this is a single line textfield of type ANY add the emoji keyboard.
        if (!imeOptionTaken && codenameOneInputType == TextArea.ANY) {
            mEditText.setInputType(getAndroidInputType(codenameOneInputType) | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
        }
        if (Display.getInstance().getProperty("andAddComma", "false").equals("true") && (codenameOneInputType & TextArea.DECIMAL) == TextArea.DECIMAL) {
            defaultKeyListener = mEditText.getKeyListener();
            mEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));
        }
    } else {
        if (textArea.getDoneListener() != null) {
            mEditText.setHorizontallyScrolling(false);
            mEditText.setMaxLines(Integer.MAX_VALUE);
            mEditText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            mEditText.setMaxWidth(textArea.getWidth());
            mEditText.setMaxHeight(textArea.getHeight());
            mEditText.setHorizontalScrollBarEnabled(false);
            mEditText.getLayoutParams().width = textArea.getWidth();
            mEditText.getLayoutParams().height = textArea.getHeight();
        } else {
            mEditText.setInputType(getAndroidInputType(codenameOneInputType, true));
        }
    }
    if (password) {
        int type = mInputTypeMap.get(codenameOneInputType, InputType.TYPE_CLASS_TEXT);
        if ((type & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) == InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) {
            type = type ^ InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        }
        // turn off suggestions for passwords
        mEditText.setInputType(type | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        mEditText.setTransformationMethod(new MyPasswordTransformationMethod());
    }
    int maxLength = textArea.maxSize;
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
    mEditText.setFilters(FilterArray);
    mEditText.setSelection(mEditText.getText().length());
    showVirtualKeyboard(true);
    if (Boolean.FALSE.equals(textArea.getClientProperty("android.cursorVisible"))) {
        // This provides an imperfect workaround for this issue:
        // https://github.com/codenameone/CodenameOne/issues/2317
        // Blinking cursor causes text to disappear on some versions of android
        // Can't seem to find how to detect whether device is affected, so
        // just providing a client property to disable the blinking cursor
        // on a particular text field.
        mEditText.setCursorVisible(false);
    }
/*
        // Leaving this hack here for posterity.  It seems that this manually
        // blinking cursor causes the paste menu to disappear
        // https://github.com/codenameone/CodenameOne/issues/2147
        // Removing the hack below, fixes this issue.  And in the test device
        // I'm using the blinking of text doesn't seem to occur, so perhaps
        // it was fixed via other means.  Test device:
        // Name: Samsung Galaxy S3 (T-Mobile)
        //    OS: 4.3
        //    Manufacturer: Samsung
        //    Model: 4.3
        //    Chipset: armeabi-v7a 1512MHz
        //    Memory: 16000000000
        //    Heap: 256000000
        //    Display: 720 x 1280
        //
        // UPDATE Feb. 13, 2018:
        // This issue seems to be still present in some devices, but it isn't clear even
        // how to detect it.
        // Issue reported and reproduced here https://github.com/codenameone/CodenameOne/issues/2317
        // Issue has been observed in a Virtual Box installation with 5.1.1, but
        // cannot be reproduced in a Nexus 5 running 5.1.1.
        // 
        if (Build.VERSION.SDK_INT < 21) {
            // HACK!!!  On Android 4.4, it seems that the natural blinking cursor
            // causes text to disappear when it blinks.  Manually blinking the
            // cursor seems to work around this issue, so that's what we do here.
            // This issue is described here: http://stackoverflow.com/questions/41305052/textfields-content-disappears-during-typing?noredirect=1#comment69977316_41305052
            mEditText.setCursorVisible(false);
            final boolean[] cursorVisible = new boolean[]{false};
            if (cursorTimer != null) {
                cursorTimer.cancel();
            }
            cursorTimer = new Timer();
            cursorTimerTask = new TimerTask() {
                public void run() {
                    AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            EditView v = mEditText;
                            if (v != null) {
                                cursorVisible[0] = !cursorVisible[0];
                                v.setCursorVisible(cursorVisible[0]);
                            }
                        }
                    });

                }
            };
            cursorTimer.schedule(cursorTimerTask, 100, 500);
        }
        */
}
Also used : TextArea(com.codename1.ui.TextArea) ContextMenu(android.view.ContextMenu) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu) Component(com.codename1.ui.Component) InputFilter(android.text.InputFilter) MenuItem(android.view.MenuItem) Paint(android.graphics.Paint) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Paint(android.graphics.Paint) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo)

Example 64 with TextArea

use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method endEditing.

/**
 * Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call
 * to 'edit' to return.
 */
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
    // if (cursorTimer != null) {
    // cursorTimer.cancel();
    // }
    System.out.println("-------In endEditing");
    if (!mIsEditing || mEditText == null) {
        return;
    }
    // SJH: Setting visibility GONE causes a size change event to be fired even when the
    // input mode is adjustPan.  This causes problems and glitches with the layout because we
    // have to guess if a resize even is accurate or not.
    // setVisibility(GONE);
    mLastEndEditReason = reason;
    // If the IME action is set to NEXT, do not hide the virtual keyboard
    boolean isNextActionFlagSet = ((mEditText.getImeOptions() & 0xf) == EditorInfo.IME_ACTION_NEXT);
    boolean leaveKeyboardShowing = impl.isAsyncEditMode();
    System.out.println("Next flag: " + isNextActionFlagSet);
    System.out.println("Next cmp: " + getNextComponent(mEditText.mTextArea));
    System.out.println("Reason : " + reason + " IME Action: " + REASON_IME_ACTION);
    if (reason == REASON_IME_ACTION && isNextActionFlagSet) {
        if (getNextComponent(mEditText.mTextArea) instanceof TextArea) {
            leaveKeyboardShowing = true;
        } else {
            leaveKeyboardShowing = false;
        }
    }
    if (forceVKBOpen) {
        leaveKeyboardShowing = true;
    }
    if (forceVKBClose) {
        leaveKeyboardShowing = false;
    }
    System.out.println("-----LEAVE KEYBOARD SHOWING: " + leaveKeyboardShowing);
    if (!leaveKeyboardShowing || actionCode == EditorInfo.IME_ACTION_DONE || actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        System.out.println("Hiding virtual keyboard");
        showVirtualKeyboard(false);
    }
    // Get rid of flags
    int imo = mEditText.getImeOptions() & 0xf;
    if (reason == REASON_IME_ACTION && ((TextArea) mEditText.mTextArea).getDoneListener() != null && (actionCode == EditorInfo.IME_ACTION_DONE) || actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        ((TextArea) mEditText.mTextArea).fireDoneEvent();
    }
    // Call this in onComplete instead
    // mIsEditing = false;
    mLastEditText = mEditText;
    removeView(mEditText);
    Component editingComponent = mEditText.mTextArea;
    mEditText.removeTextChangedListener(mEditText.mTextWatcher);
    mEditText = null;
    if (impl.isAsyncEditMode()) {
        Runnable onComplete = (Runnable) editingComponent.getClientProperty("android.onAsyncEditingComplete");
        editingComponent.putClientProperty("android.onAsyncEditingComplete", null);
        if (onComplete != null) {
            Display.getInstance().callSerially(onComplete);
        }
    }
    waitingForSynchronousEditingCompletion = false;
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) Paint(android.graphics.Paint)

Example 65 with TextArea

use of com.vaadin.v7.ui.TextArea 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

TextArea (com.codename1.ui.TextArea)60 Form (com.codename1.ui.Form)23 Component (com.codename1.ui.Component)21 Button (com.codename1.ui.Button)16 Label (com.codename1.ui.Label)16 TextArea (com.vaadin.v7.ui.TextArea)15 Container (com.codename1.ui.Container)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)12 Label (com.vaadin.ui.Label)11 ComboBox (com.vaadin.v7.ui.ComboBox)10 TextField (com.codename1.ui.TextField)9 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)9 DateField (com.vaadin.v7.ui.DateField)8 TextField (com.vaadin.v7.ui.TextField)8 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)7 RadioButton (com.codename1.ui.RadioButton)6 Field (com.vaadin.v7.ui.Field)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Paint (android.graphics.Paint)4 CheckBox (com.codename1.ui.CheckBox)4