FileDocCategorySizeDatePackage
LoginFilter.javaAPI DocAndroid 1.5 API6919Wed May 06 22:41:56 BST 2009android.text

LoginFilter

public abstract class LoginFilter extends Object implements InputFilter
Abstract class for filtering login-related text (user names and passwords)

Fields Summary
private boolean
mAppendInvalid
Constructors Summary
LoginFilter(boolean appendInvalid)
Base constructor for LoginFilter

param
appendInvalid whether or not to append invalid characters.

        mAppendInvalid = appendInvalid;
    
LoginFilter()
Default constructor for LoginFilter doesn't append invalid characters.

        mAppendInvalid = false;
    
Methods Summary
public java.lang.CharSequencefilter(java.lang.CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
This method is called when the buffer is going to replace the range dstart … dend of dest with the new text from the range start … end of source. Returns the CharSequence that we want placed there instead, including an empty string if appropriate, or null to accept the original replacement. Be careful to not to reject 0-length replacements, as this is what happens when you delete text.

        char[] out = new char[end - start]; // reserve enough space for whole string
        int outidx = 0;
        boolean changed = false;
        
        onStart();
        
        // Scan through beginning characters in dest, calling onInvalidCharacter() 
        // for each invalid character.
        for (int i = 0; i < dstart; i++) {
            char c = dest.charAt(i);
            if (!isAllowed(c)) onInvalidCharacter(c);
        }

        // Scan through changed characters rejecting disallowed chars
        for (int i = start; i < end; i++) {
            char c = source.charAt(i);
            if (isAllowed(c)) {
                // Character allowed. Add it to the sequence.
                out[outidx++] = c;
            } else {
                if (mAppendInvalid) out[outidx++] = c;
                else changed = true; // we changed the original string
                onInvalidCharacter(c);
            }
        }
        
        // Scan through remaining characters in dest, calling onInvalidCharacter() 
        // for each invalid character.
        for (int i = dend; i < dest.length(); i++) {
            char c = dest.charAt(i);
            if (!isAllowed(c)) onInvalidCharacter(c);
        }
        
        onStop();

        if (!changed) {
            return null;
        }
        
        String s = new String(out, 0, outidx);
        
        if (source instanceof Spanned) {
            SpannableString sp = new SpannableString(s);
            TextUtils.copySpansFrom((Spanned) source,
                                    start, end, null, sp, 0);
            return sp;
        } else {
            return s;
        }
    
public abstract booleanisAllowed(char c)
Returns whether or not we allow character c. Subclasses must override this method.

public voidonInvalidCharacter(char c)
Called whenever we encounter an invalid character.

param
c the invalid character

        
    
public voidonStart()
Called when we start processing filter.

        
    
public voidonStop()
Called when we're done processing filter