![JAR search and dependency download from the Maven repository](/logo.png)
src.android.view.ViewShowHidePerfTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android-all Show documentation
Show all versions of android-all Show documentation
A library jar that provides APIs for Applications written for the Google Android Platform.
/*
* 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.view;
import static org.junit.Assert.assertTrue;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.perftests.utils.PerfTestActivity;
import android.view.View.MeasureSpec;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.List;
@RunWith(Parameterized.class)
@LargeTest
public class ViewShowHidePerfTest {
@Rule
public ActivityTestRule mActivityRule =
new ActivityTestRule<>(PerfTestActivity.class);
@Rule
public final BenchmarkRule mBenchmarkRule = new BenchmarkRule();
public Context getContext() {
return InstrumentationRegistry.getInstrumentation().getTargetContext();
}
static abstract class SubTreeFactory {
String mName;
SubTreeFactory(String name) { mName = name; }
abstract View create(Context context, int depth);
@Override
public String toString() {
return mName;
}
}
private static SubTreeFactory[] sSubTreeFactories = new SubTreeFactory[] {
new SubTreeFactory("NestedLinearLayoutTree") {
private int mColorToggle = 0;
private void createNestedLinearLayoutTree(Context context, LinearLayout parent,
int remainingDepth) {
if (remainingDepth <= 0) {
mColorToggle = (mColorToggle + 1) % 4;
parent.setBackgroundColor((mColorToggle < 2) ? Color.RED : Color.BLUE);
return;
}
boolean vertical = remainingDepth % 2 == 0;
parent.setOrientation(vertical ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
for (int i = 0; i < 2; i++) {
LinearLayout child = new LinearLayout(context);
// vertical: match parent in x axis, horizontal: y axis.
parent.addView(child, new LinearLayout.LayoutParams(
(vertical ? ViewGroup.LayoutParams.MATCH_PARENT : 0),
(vertical ? 0 : ViewGroup.LayoutParams.MATCH_PARENT),
1.0f));
createNestedLinearLayoutTree(context, child, remainingDepth - 1);
}
}
@Override
public View create(Context context, int depth) {
LinearLayout root = new LinearLayout(context);
createNestedLinearLayoutTree(context, root, depth - 1);
return root;
}
},
new SubTreeFactory("ImageViewList") {
@Override
public View create(Context context, int depth) {
LinearLayout root = new LinearLayout(context);
root.setOrientation(LinearLayout.HORIZONTAL);
int childCount = (int) Math.pow(2, depth);
for (int i = 0; i < childCount; i++) {
ImageView imageView = new ImageView(context);
root.addView(imageView, new LinearLayout.LayoutParams(
0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
imageView.setImageDrawable(new ColorDrawable(Color.RED));
}
return root;
}
},
};
@Parameterized.Parameters(name = "Factory:{0},depth:{1}")
public static Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy