Java Code Examples for com.codename1.ui.TextArea#PASSWORD

The following examples show how to use com.codename1.ui.TextArea#PASSWORD . 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: InstantUI.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The text field constraint for the property. notice that some constraints 
 * are implicit unless set manually e.g. numeric for numbers or password for fields with password 
 * in the name
 * @param p the property
 * @return the constraint matching this property
 */
public int getTextFieldConstraint(PropertyBase p) {
    Integer v = (Integer)p.getClientProperty("cn1$tconstraint");
    if(v != null) {
        return v;
    }
    
    Class t = p.getGenericType();
    if(t != null) {
        if(t == Integer.class || t == Long.class || t == Short.class || t == Byte.class) {
            return TextArea.NUMERIC;
        }
        if(t == Double.class || t == Float.class) {
            return TextArea.DECIMAL;
        }
    }
    String n = p.getName().toLowerCase();
    if(n.indexOf("password") > -1) {
        return TextArea.PASSWORD;
    }
    if(n.indexOf("url") > -1 || n.indexOf("website") > -1 || n.indexOf("blog") > -1) {
        return TextArea.URL;
    }
    if(n.indexOf("email") > -1) {
        return TextArea.EMAILADDR;
    }
    if(n.indexOf("phone") > -1 || n.indexOf("mobile") > -1) {
        return TextArea.PHONENUMBER;
    }
    return TextArea.ANY;
}
 
Example 2
Source File: DefaultLookAndFeel.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 3
Source File: CodenameOneView.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
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 4
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
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 5
Source File: DefaultLookAndFeel.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Spans calculateTextAreaSpan(TextSelection sel, TextArea ta) {
    Spans out = sel.newSpans();
    //setFG(g, ta);
    //Span out = sel.newSpan(ta);
    int line = ta.getLines();
    //int oX = g.getClipX();
    //int oY = g.getClipY();
    //int oWidth = g.getClipWidth();
    //int oHeight = g.getClipHeight();
    Font f = ta.getStyle().getFont();
    int fontHeight = f.getHeight();

    int align = reverseAlignForBidi(ta);

    int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
    int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
    int topPadding = ta.getStyle().getPaddingTop();
    switch (ta.getVerticalAlignment()) {
        case Component.CENTER :
            topPadding += Math.max(0, (ta.getInnerHeight() - (ta.getRowsGap() + fontHeight) * line)/2);
            break;
        case Component.BOTTOM :
            topPadding += Math.max(0, (ta.getInnerHeight() - (ta.getRowsGap() + fontHeight) * line));
    }
    //boolean shouldBreak = false;
    int posOffset = 0;
    int lastRowBottom = 0;
    for (int i = 0; i < line; i++) {
        Span rowSpan = sel.newSpan(ta);
        int x = ta.getX() + leftPadding;
        int y = ta.getY() +  topPadding +
                (ta.getRowsGap() + fontHeight) * i;
        int adjustedY = Math.max(y, lastRowBottom);
        int yDiff = adjustedY - y;
        y = adjustedY;
        
        //if(Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
            
            String rowText = (String) ta.getTextAt(i);
            //display ******** if it is a password field
            String displayText = "";
            if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
                int rlen = rowText.length();
                for (int j = 0; j < rlen; j++) {
                    displayText += passwordChar;
                }
            } else {
                displayText = rowText;
            }
            posOffset = ta.getText().indexOf(rowText, posOffset);
            switch(align) {
                case Component.RIGHT:
            		x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
                    break;
                case Component.CENTER:
                    x+= (ta.getWidth()-leftPadding-rightPadding-f.stringWidth(displayText))/2;
                    break;
            }
            //int nextY = ta.getY() +  topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
            //if this is the last line to display and there is more content and isEndsWith3Points() is true
            //add "..." at the last row
            if(ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line){
                if(displayText.length() > 3){
                    displayText = displayText.substring(0, displayText.length() - 3);
                }
                //g.drawString(displayText + "...", x, y ,ta.getStyle().getTextDecoration()); 
                append(sel, ta, rowSpan, displayText + "...", f, posOffset, x, y, getSelectionHeight(f) - yDiff);
                lastRowBottom = rowSpan.getBounds().getY() + rowSpan.getBounds().getHeight();
                rowSpan = rowSpan.translate(ta.getAbsoluteX() - sel.getSelectionRoot().getAbsoluteX() - ta.getX(), ta.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - ta.getY());
                out.add(rowSpan);
                return out;
            }else{            
                //g.drawString(displayText, x, y ,ta.getStyle().getTextDecoration());
                append(sel, ta, rowSpan, displayText, f, posOffset, x, y, getSelectionHeight(f) - yDiff);
                lastRowBottom = rowSpan.getBounds().getY() + rowSpan.getBounds().getHeight();
                rowSpan = rowSpan.translate(ta.getAbsoluteX() - sel.getSelectionRoot().getAbsoluteX() - ta.getX(), ta.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - ta.getY());
                out.add(rowSpan);
            }
            posOffset += displayText.length();
            //shouldBreak = true;
        //}else{
        //    if(shouldBreak){
        //        break;
        //    }
        //}
    }
    return out;
}
 
Example 6
Source File: DefaultLookAndFeel.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void drawTextArea(Graphics g, TextArea ta) {
    setFG(g, ta);
    int line = ta.getLines();
    int oX = g.getClipX();
    int oY = g.getClipY();
    int oWidth = g.getClipWidth();
    int oHeight = g.getClipHeight();
    Font f = ta.getStyle().getFont();
    int fontHeight = f.getHeight();

    int align = reverseAlignForBidi(ta);

    int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
    int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
    int topPadding = ta.getStyle().getPaddingTop();
    switch (ta.getVerticalAlignment()) {
        case Component.CENTER :
            topPadding += Math.max(0, (ta.getInnerHeight() - ta.getRowsGap()*(line-1) - fontHeight* line)/2);
            break;
        case Component.BOTTOM :
            topPadding += Math.max(0, (ta.getInnerHeight() - ta.getRowsGap()*(line-1) - fontHeight* line));
    }
    boolean shouldBreak = false;
    
    for (int i = 0; i < line; i++) {
        int x = ta.getX() + leftPadding;
        int y = ta.getY() +  topPadding +
                (ta.getRowsGap() + fontHeight) * i;
        if(Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
            
            String rowText = (String) ta.getTextAt(i);
            //display ******** if it is a password field
            String displayText = "";
            if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
                int rlen = rowText.length();
                for (int j = 0; j < rlen; j++) {
                    displayText += passwordChar;
                }
            } else {
                displayText = rowText;
            }

            switch(align) {
                case Component.RIGHT:
            		x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
                    break;
                case Component.CENTER:
                    x+= (ta.getWidth()-leftPadding-rightPadding-f.stringWidth(displayText))/2;
                    break;
            }
            int nextY = ta.getY() +  topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
            //if this is the last line to display and there is more content and isEndsWith3Points() is true
            //add "..." at the last row
            if(ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line){
                if(displayText.length() > 3){
                    displayText = displayText.substring(0, displayText.length() - 3);
                }
                g.drawString(displayText + "...", x, y ,ta.getStyle().getTextDecoration());                
                return;
            }else{            
                g.drawString(displayText, x, y ,ta.getStyle().getTextDecoration());
            }
            shouldBreak = true;
        }else{
            if(shouldBreak){
                break;
            }
        }
    }
}