Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47ec3391 authored by Selim Cinek's avatar Selim Cinek
Browse files

Using transformation method in the ImageFloatingTextView

Otherwise things like singleline and password don't work.

Test: runtest -x core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java
Change-Id: I9d7d13c038be38319e6516715137789f612a43f7
Fixes: 36713596
parent b02cbdee
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.text.BoringLayout;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.widget.RemoteViews;
@@ -68,7 +69,12 @@ public class ImageFloatingTextView extends TextView {
    protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
            Layout.Alignment alignment, boolean shouldEllipsize,
            TextUtils.TruncateAt effectiveEllipsize, boolean useSaved) {
        CharSequence text = getText() == null ? "" : getText();
        TransformationMethod transformationMethod = getTransformationMethod();
        CharSequence text = getText();
        if (transformationMethod != null) {
            text = transformationMethod.getTransformation(text, this);
        }
        text = text == null ? "" : text;
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(text, 0, text.length(),
                getPaint(), wantWidth)
                .setAlignment(alignment)
+12 −0
Original line number Diff line number Diff line
@@ -21,9 +21,11 @@ import static org.junit.Assert.assertTrue;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.text.Layout;
import android.view.View.MeasureSpec;
import android.widget.TextView;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

@@ -102,6 +104,16 @@ public class ImageFloatingTextViewTest {
                + "Yada yada, yada yada. Lorem ipsum dolor sit amet.");
    }

    @Test
    public void usesTransformationMethod() {
        mView.setSingleLine();
        String text = "Test \n Test";
        parametrizedTest(text);
        Layout layout = mView.getLayout();
        Assert.assertFalse("The transformation method wasn't used, string is still the same",
                text.equals(layout.getText()));
    }

    private void parametrizedTest(CharSequence text) {
        int heightMeasureSpec = MeasureSpec.makeMeasureSpec(500, MeasureSpec.AT_MOST);
        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY);