Merge "Test TextView autosize and maxline" into oc-dev
diff --git a/tests/tests/widget/res/layout/textview_autosize_maxlines.xml b/tests/tests/widget/res/layout/textview_autosize_maxlines.xml
new file mode 100644
index 0000000..fc0d265
--- /dev/null
+++ b/tests/tests/widget/res/layout/textview_autosize_maxlines.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<view
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ class="android.widget.cts.TextViewTest$CustomTextViewWithTransformationMethod"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:autoSizeTextType="uniform"/>
\ No newline at end of file
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 7b54c11..1198229 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -45,6 +45,7 @@
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.IntDef;
+import android.annotation.Nullable;
import android.app.Activity;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
@@ -112,6 +113,7 @@
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.text.util.Linkify;
+import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.util.TypedValue;
@@ -6612,6 +6614,46 @@
}
@Test
+ public void testAutosizeWithMaxLines_shouldNotThrowException() throws Throwable {
+ // the layout contains an instance of CustomTextViewWithTransformationMethod
+ final TextView textView = (TextView) mActivity.getLayoutInflater()
+ .inflate(R.layout.textview_autosize_maxlines, null);
+ assertTrue(textView instanceof CustomTextViewWithTransformationMethod);
+ assertEquals(1, textView.getMaxLines());
+ assertEquals(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM, textView.getAutoSizeTextType());
+ assertTrue(textView.getTransformationMethod() instanceof SingleLineTransformationMethod);
+ }
+
+ public static class CustomTextViewWithTransformationMethod extends TextView {
+ public CustomTextViewWithTransformationMethod(Context context) {
+ super(context);
+ init();
+ }
+
+ public CustomTextViewWithTransformationMethod(Context context,
+ @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ public CustomTextViewWithTransformationMethod(Context context,
+ @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init();
+ }
+
+ public CustomTextViewWithTransformationMethod(Context context,
+ @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ init();
+ }
+
+ private void init() {
+ setTransformationMethod(new SingleLineTransformationMethod());
+ }
+ }
+
+ @Test
public void testAutoSize_setEllipsize() throws Throwable {
final TextView textView = (TextView) mActivity.findViewById(
R.id.textview_autosize_uniform_predef_sizes);