FileDocCategorySizeDatePackage
LoginFilter.javaAPI DocAndroid 5.1 API6804Thu Mar 12 22:22:10 GMT 2015android.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.

        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
        SpannableStringBuilder modification = null;
        int modoff = 0;

        for (int i = start; i < end; i++) {
            char c = source.charAt(i);
            if (isAllowed(c)) {
                // Character allowed.
                modoff++;
            } else {
                if (mAppendInvalid) {
                    modoff++;
                } else {
                    if (modification == null) {
                        modification = new SpannableStringBuilder(source, start, end);
                        modoff = i - start;
                    }

                    modification.delete(modoff, modoff + 1);
                }

                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();

        // Either returns null if we made no changes,
        // or what we wanted to change it to if there were changes.
        return modification;
    
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