FileDocCategorySizeDatePackage
ReplacementTransformationMethod.javaAPI DocAndroid 1.5 API6714Wed May 06 22:41:56 BST 2009android.text.method

ReplacementTransformationMethod

public abstract class ReplacementTransformationMethod extends Object implements TransformationMethod
This transformation method causes the characters in the {@link #getOriginal} array to be replaced by the corresponding characters in the {@link #getReplacement} array.

Fields Summary
Constructors Summary
Methods Summary
protected abstract char[]getOriginal()
Returns the list of characters that are to be replaced by other characters when displayed.

protected abstract char[]getReplacement()
Returns a parallel array of replacement characters for the ones that are to be replaced.

public java.lang.CharSequencegetTransformation(java.lang.CharSequence source, android.view.View v)
Returns a CharSequence that will mirror the contents of the source CharSequence but with the characters in {@link #getOriginal} replaced by ones from {@link #getReplacement}.

        char[] original = getOriginal();
        char[] replacement = getReplacement();

        /*
         * Short circuit for faster display if the text will never change.
         */
        if (!(source instanceof Editable)) {
            /*
             * Check whether the text does not contain any of the
             * source characters so can be used unchanged.
             */
            boolean doNothing = true;
            int n = original.length;
            for (int i = 0; i < n; i++) {
                if (TextUtils.indexOf(source, original[i]) >= 0) {
                    doNothing = false;
                    break;
                }
            }
            if (doNothing) {
                return source;
            }

            if (!(source instanceof Spannable)) {
                /*
                 * The text contains some of the source characters,
                 * but they can be flattened out now instead of
                 * at display time.
                 */
                if (source instanceof Spanned) {
                    return new SpannedString(new SpannedReplacementCharSequence(
                                                        (Spanned) source,
                                                        original, replacement));
                } else {
                    return new ReplacementCharSequence(source,
                                                       original,
                                                       replacement).toString();
                }
            }
        }

        if (source instanceof Spanned) {
            return new SpannedReplacementCharSequence((Spanned) source,
                                                      original, replacement);
        } else {
            return new ReplacementCharSequence(source, original, replacement);
        }
    
public voidonFocusChanged(android.view.View view, java.lang.CharSequence sourceText, boolean focused, int direction, android.graphics.Rect previouslyFocusedRect)

        // This callback isn't used.