Example usage for android.text.method TransformationMethod getTransformation

List of usage examples for android.text.method TransformationMethod getTransformation

Introduction

In this page you can find the example usage for android.text.method TransformationMethod getTransformation.

Prototype

public CharSequence getTransformation(CharSequence source, View view);

Source Link

Document

Returns a CharSequence that is a transformation of the source text -- for example, replacing each character with a dot in a password field.

Usage

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

private boolean suggestedSizeFitsInSpace(int suggestedSizeInPx, RectF availableSpace) {
    CharSequence text = mTextView.getText();
    TransformationMethod transformationMethod = mTextView.getTransformationMethod();
    if (transformationMethod != null) {
        CharSequence transformedText = transformationMethod.getTransformation(text, mTextView);
        if (transformedText != null) {
            text = transformedText;//from  w  w  w .  java2  s  . c o  m
        }
    }

    final int maxLines = Build.VERSION.SDK_INT >= 16 ? mTextView.getMaxLines() : -1;
    if (mTempTextPaint == null) {
        mTempTextPaint = new TextPaint();
    } else {
        mTempTextPaint.reset();
    }
    mTempTextPaint.set(mTextView.getPaint());
    mTempTextPaint.setTextSize(suggestedSizeInPx);

    // Needs reflection call due to being private.
    Layout.Alignment alignment = invokeAndReturnWithDefault(mTextView, "getLayoutAlignment",
            Layout.Alignment.ALIGN_NORMAL);
    final StaticLayout layout = Build.VERSION.SDK_INT >= 23
            ? createStaticLayoutForMeasuring(text, alignment, Math.round(availableSpace.right), maxLines)
            : createStaticLayoutForMeasuringPre23(text, alignment, Math.round(availableSpace.right));
    // Lines overflow.
    if (maxLines != -1 && (layout.getLineCount() > maxLines
            || (layout.getLineEnd(layout.getLineCount() - 1)) != text.length())) {
        return false;
    }

    // Height overflow.
    if (layout.getHeight() > availableSpace.bottom) {
        return false;
    }

    return true;
}