Merge "AutoSize TextView (part 2) - benchmark number of sizes"

This commit is contained in:
Andrei Stingaceanu
2016-11-30 11:02:50 +00:00
committed by Android (Google) Code Review
12 changed files with 416 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<!--
~ Copyright (C) 2016 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
-->
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 10 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="20px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 100 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="110px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 1000 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="1010px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 10000 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="10010px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 100000 sizes!!! to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="100010px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 300 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="310px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,42 @@
<!--
~ Copyright (C) 2016 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
-->
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 5 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="15px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 50 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="60px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2016 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
-->
<!-- Contains 500 sizes to choose from when auto-sizing -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="600dp"
android:text="@string/long_text"
android:textDirection="rtl"
android:autoSizeText="xy"
android:autoSizeMinTextSize="10px"
android:textSize="510px"
android:autoSizeStepGranularity="1px"/>

View File

@@ -0,0 +1,20 @@
<!--
~ Copyright (C) 2016 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
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp"
android:text="@string/long_text" />

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 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
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="long_text">text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text typo text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text </string>
</resources>

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2016 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
*/
package android.widget;
import android.app.Activity;
import android.os.Looper;
import android.os.Bundle;
import android.perftests.utils.PerfStatusReporter;
import android.util.Log;
import android.view.View;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.StubActivity;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.rule.ActivityTestRule;
import android.support.test.InstrumentationRegistry;
import com.android.perftests.core.R;
import java.util.Locale;
import java.util.Collection;
import java.util.Arrays;
import org.junit.Test;
import org.junit.Rule;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;
@LargeTest
@RunWith(Parameterized.class)
public class TextViewAutoSizeLayoutPerfTest {
@Parameters(name = "{0}")
public static Collection layouts() {
return Arrays.asList(new Object[][] {
{ "Basic TextView - no autosize", R.layout.test_basic_textview_layout},
{ "Autosize TextView 5 sizes", R.layout.test_autosize_textview_5},
{ "Autosize TextView 10 sizes", R.layout.test_autosize_textview_10},
{ "Autosize TextView 50 sizes", R.layout.test_autosize_textview_50},
{ "Autosize TextView 100 sizes", R.layout.test_autosize_textview_100},
{ "Autosize TextView 300 sizes", R.layout.test_autosize_textview_300},
{ "Autosize TextView 500 sizes", R.layout.test_autosize_textview_500},
{ "Autosize TextView 1000 sizes", R.layout.test_autosize_textview_1000},
{ "Autosize TextView 10000 sizes", R.layout.test_autosize_textview_10000},
{ "Autosize TextView 100000 sizes", R.layout.test_autosize_textview_100000}
});
}
private int mLayoutId;
public TextViewAutoSizeLayoutPerfTest(String key, int layoutId) {
mLayoutId = layoutId;
}
@Rule
public ActivityTestRule<StubActivity> mActivityRule =
new ActivityTestRule(StubActivity.class);
@Rule
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
@Test
public void testConstruction() throws Throwable {
mActivityRule.runOnUiThread(() -> {
assertTrue("We should be running on the main thread",
Looper.getMainLooper().getThread() == Thread.currentThread());
assertTrue("We should be running on the main thread",
Looper.myLooper() == Looper.getMainLooper());
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
Activity activity = mActivityRule.getActivity();
activity.setContentView(mLayoutId);
while (state.keepRunning()) {
TextView textView = new TextView(activity);
// TextView#onMeasure() gets called, which triggers TextView#autoSizeText()
// which is the method we want to benchmark.
textView.requestLayout();
}
});
}
}