Search in sources :

Example 11 with TextArea

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

the class ResetableTextWatcher method scrollActiveTextfieldToVisible.

static void scrollActiveTextfieldToVisible() {
    if (isEditing() && sInstance != null) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                if (sInstance != null && sInstance.mEditText != null && sInstance.mEditText.mTextArea != null) {
                    TextArea ta = sInstance.mEditText.mTextArea;
                    if (isScrollableParent(ta)) {
                        ta.scrollRectToVisible(0, 0, ta.getWidth(), ta.getHeight(), ta);
                        ta.getComponentForm().getAnimationManager().flushAnimation(new Runnable() {

                            @Override
                            public void run() {
                                reLayoutEdit();
                            }
                        });
                    }
                }
            }
        };
    }
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 12 with TextArea

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

the class ResetableTextWatcher method onTouchEvent.

/*
    static void handleActiveTouchEventIfHidden(MotionEvent event) {
        if (sInstance != null && mIsEditing && isActiveTextEditorHidden()) {
            sInstance.onTouchEvent(event);
        }
    }
    */
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!impl.isAsyncEditMode()) {
        boolean leaveVKBOpen = false;
        if (mEditText != null && mEditText.mTextArea != null && mEditText.mTextArea.getComponentForm() != null) {
            Component c = mEditText.mTextArea.getComponentForm().getResponderAt((int) event.getX(), (int) event.getY());
            if (mEditText.mTextArea.getClientProperty("leaveVKBOpen") != null || (c != null && c instanceof TextArea && ((TextArea) c).isEditable() && ((TextArea) c).isEnabled())) {
                leaveVKBOpen = true;
            }
        }
        // When the user touches the screen outside the text-area, finish editing
        endEditing(REASON_TOUCH_OUTSIDE, leaveVKBOpen, 0);
    } else {
        final int evtX = (int) event.getX();
        final int evtY = (int) event.getY();
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                if (mEditText != null && mEditText.mTextArea != null) {
                    TextArea tx = mEditText.mTextArea;
                    int x = tx.getAbsoluteX() + tx.getScrollX();
                    int y = tx.getAbsoluteY() + tx.getScrollY();
                    int w = tx.getWidth();
                    int h = tx.getHeight();
                    if (!(x <= evtX && y <= evtY && x + w >= evtX && y + h >= evtY)) {
                        hideTextEditor();
                    } else {
                        showTextEditorAgain();
                    }
                }
            }
        });
    }
    // We don't want to consume this event
    return false;
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) Paint(android.graphics.Paint)

Example 13 with TextArea

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

the class ResetableTextWatcher method hideTextEditor.

/**
 * Hides the native text editor while keeping the active async edit session going.
 * This will effectively hide the native text editor, and show the light-weight text area
 * with cursor still in the correct position.
 */
private void hideTextEditor() {
    if (!mIsEditing || textEditorHidden || mEditText == null) {
        return;
    }
    textEditorHidden = true;
    final TextArea ta = mEditText.mTextArea;
    // Since this may be called off the UI thread, we need to issue async request on UI thread
    // to hide the text area.
    impl.getActivity().runOnUiThread(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea == ta) {
                // Note:  Setting visibility to GONE doesn't work here because the TextWatcher
                // will stop receiving input from the keyboard, so we don't have a way to
                // reactivate the text editor when the user starts typing again.  Using the margin
                // to move it off screen keeps the text editor active.
                mEditLayoutParams.setMargins(-Display.getInstance().getDisplayWidth(), 0, 0, 0);
                InPlaceEditView.this.requestLayout();
                final int cursorPos = mEditText.getSelectionStart();
                // Since we are going to be displaying the CN1 text area now, we need to update
                // the cursor.  That needs to happen on the EDT.
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        if (mEditText != null && mEditText.mTextArea == ta && mIsEditing && textEditorHidden) {
                            if (ta instanceof TextField) {
                                ((TextField) ta).setCursorPosition(cursorPos);
                            }
                        }
                    }
                });
            }
        }
    });
    // Repaint the CN1 text area on the EDT.  This is necessary because while the native editor
    // was shown, the cn1 text area paints only its background.  Now that the editor is hidden
    // it should paint its foreground also.
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea != null) {
                mEditText.mTextArea.repaint();
            }
        }
    });
// repaintTextEditor(true);
}
Also used : TextArea(com.codename1.ui.TextArea) TextField(com.codename1.ui.TextField)

Example 14 with TextArea

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

the class BlackBerryImplementation method editString.

public void editString(final Component cmp, final int maxSize, final int constraint, final String text, int keyCode) {
    TextArea txtCmp = (TextArea) cmp;
    String edit = (String) txtCmp.getClientProperty("RIM.nativePopup");
    if (edit != null) {
        EditPopup editpop = new EditPopup(txtCmp, maxSize);
        editpop.startEdit();
    } else {
        nativeEdit(txtCmp, txtCmp.getMaxSize(), txtCmp.getConstraint(), txtCmp.getText(), keyCode);
    }
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 15 with TextArea

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

the class AndroidKeyboard method showKeyboard.

public void showKeyboard(boolean show) {
    // manager.restartInput(myView);
    // if (keyboardShowing != show) {
    // manager.toggleSoftInputFromWindow(myView.getWindowToken(), 0, 0);
    // this.keyboardShowing = show;
    // }
    System.out.println("showKeyboard " + show);
    Form current = Display.getInstance().getCurrent();
    if (current != null) {
        Component cmp = current.getFocused();
        if (cmp != null && cmp instanceof TextArea) {
            TextArea txt = (TextArea) cmp;
            if (show) {
                Display.getInstance().editString(txt, txt.getMaxSize(), txt.getConstraint(), txt.getText(), 0);
            }
        }
    } else {
        InPlaceEditView.endEdit();
    }
// if(!show){
// impl.saveTextEditingState();
// }
}
Also used : Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component)

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