Java Code Examples for com.codename1.ui.TextArea#isSingleLineTextArea()
The following examples show how to use
com.codename1.ui.TextArea#isSingleLineTextArea() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Similar to getText() but works properly with password fields */ protected String getTextFieldString(TextArea ta) { String txt = ta.getText(); String text; if(ta.isSingleLineTextArea()){ text = txt; }else{ text = (String) ta.getTextAt(ta.getCursorY()); if(ta.getCursorPosition() + text.length() < txt.length()){ char c = txt.charAt(ta.getCursorPosition() + text.length()); if(c == '\n'){ text += "\n"; }else if(c == ' '){ text += " "; } } } String displayText = ""; if ((ta.getConstraint() & TextArea.PASSWORD) != 0) { // show the last character in a password field if (ta.isPendingCommit()) { if (text.length() > 0) { int tlen = text.length(); for (int j = 0; j < tlen - 1; j++) { displayText += passwordChar; } displayText += text.charAt(text.length() - 1); } } else { for (int j = 0; j < text.length(); j++) { displayText += passwordChar; } } } else { displayText = text; } return displayText; }
Example 2
Source File: CodenameOneView.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
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; } }
Example 3
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
protected EditPopup(TextArea lightweightEdit, int maxSize) { super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL), Field.FOCUSABLE | Field.EDITABLE | Screen.DEFAULT_MENU); UIManager m = UIManager.getInstance(); okString = m.localize("ok", "OK"); cancelString = m.localize("cancel", "Cancel"); this.lightweightEdit = lightweightEdit; long type = 0; int constraint = lightweightEdit.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; } else if ((constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) { type = BasicEditField.FILTER_PHONE; } else if ((constraint & TextArea.NON_PREDICTIVE) == TextArea.NON_PREDICTIVE) { type = BasicEditField.NO_COMPLEX_INPUT; } if (lightweightEdit.isSingleLineTextArea()) { type |= BasicEditField.NO_NEWLINE; } if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) { nativeEdit = new BBPasswordEditField(lightweightEdit, type, maxSize, 0, 0xffffff); } else { nativeEdit = new BBEditField(lightweightEdit, type, maxSize, 0, 0xffffff); } // using Field.EDITABLE flag now because of bug with DevTrack ID 354265 at // https://www.blackberry.com/jira/browse/JAVAAPI-101 //nativeEdit.setEditable(true); net.rim.device.api.ui.Font f = nativeEdit.getFont(); if (f.getHeight() > lightweightEdit.getStyle().getFont().getHeight()) { nativeEdit.setFont(f.derive(f.getStyle(), lightweightEdit.getStyle().getFont().getHeight())); } add(nativeEdit); nativeEdit.setFocus(); nativeEdit.setFocusListener(this); }
Example 4
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * Calculates the position of the text field cursor within the string */ private int getTextFieldCursorX(TextArea ta) { Style style = ta.getStyle(); Font f = style.getFont(); // display ******** if it is a password field String displayText = getTextFieldString(ta); String inputMode = ta.getInputMode(); int inputModeWidth = f.stringWidth(inputMode); // QWERTY devices don't quite have an input mode hide it also when we have a VK if(ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) { inputMode = ""; inputModeWidth = 0; } int xPos = 0; int cursorCharPosition = ta.getCursorX(); int cursorX=0; int x = 0; if (reverseAlignForBidi(ta) == Component.RIGHT) { if (Display.getInstance().isBidiAlgorithm()) { //char[] dest = displayText.toCharArray(); cursorCharPosition = Display.getInstance().getCharLocation(displayText, cursorCharPosition-1); if (cursorCharPosition==-1) { xPos = f.stringWidth(displayText); } else { displayText = Display.getInstance().convertBidiLogicalToVisual(displayText); if (!isRTLOrWhitespace((displayText.charAt(cursorCharPosition)))) { cursorCharPosition++; } xPos = f.stringWidth(displayText.substring(0, cursorCharPosition)); } } int displayX = ta.getX() + ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - f.stringWidth(displayText); cursorX = displayX + xPos; x=0; } else { if (cursorCharPosition > 0) { cursorCharPosition = Math.min(displayText.length(), cursorCharPosition); xPos = f.stringWidth(displayText.substring(0, cursorCharPosition)); } cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos; if (ta.isSingleLineTextArea() && ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth -style.getPaddingLeft(ta.isRTL())) { if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL()) { x = ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL() - xPos -1; } } } return cursorX+x; }
Example 5
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public void drawTextFieldCursor(Graphics g, TextArea ta) { Style style = ta.getStyle(); Font f = style.getFont(); int cursorY; if(ta.isSingleLineTextArea()) { switch(ta.getVerticalAlignment()) { case Component.BOTTOM: cursorY = ta.getY() + ta.getHeight() - f.getHeight(); break; case Component.CENTER: cursorY = ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2; break; default: cursorY = ta.getY() + style.getPaddingTop(); break; } } else { cursorY = ta.getY() + style.getPaddingTop() + ta.getCursorY() * (ta.getRowsGap() + f.getHeight()); } int cursorX = getTextFieldCursorX(ta); int align = reverseAlignForBidi(ta); int x=0; if (align==Component.RIGHT) { String inputMode = ta.getInputMode(); int inputModeWidth = f.stringWidth(inputMode); int baseX=ta.getX()+style.getPaddingLeftNoRTL()+inputModeWidth; if (cursorX<baseX) { x=baseX-cursorX; } } int oldColor = g.getColor(); if(getTextFieldCursorColor() == 0) { g.setColor(style.getFgColor()); } else { g.setColor(getTextFieldCursorColor()); } g.drawLine(cursorX + x, cursorY, cursorX + x, cursorY + f.getHeight()); g.setColor(oldColor); }