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

This commit is contained in:
TreeHugger Robot
2017-07-12 19:23:16 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 1 deletions

View File

@@ -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)

View File

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