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();
}
});
}
}
}
};
}
}
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;
}
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);
}
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);
}
}
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();
// }
}
Aggregations