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

Commit 727b06b4 authored by Selim Cinek's avatar Selim Cinek Committed by android-build-merger
Browse files

Merge "Using transformation method in the ImageFloatingTextView" into oc-dr1-dev

am: 997e4ac2

Change-Id: Ifffc5f1dfe2a5d606e5eae128cbe0a331d4aaf7c
parents 6dea3d77 997e4ac2
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);