1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.contentcapture; 18 19 import android.app.Activity; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.widget.LinearLayout; 23 import android.widget.TextView; 24 25 import com.android.perftests.contentcapture.R; 26 27 /** 28 * A simple activity used for testing, e.g. performance of activity switching, or as a base 29 * container of testing view. 30 */ 31 public class CustomTestActivity extends Activity { 32 public static final String INTENT_EXTRA_LAYOUT_ID = "layout_id"; 33 public static final String INTENT_EXTRA_CUSTOM_VIEWS = "custom_view_number"; 34 public static final int MAX_VIEWS = 500; 35 private static final int CUSTOM_CONTAINER_LAYOUT_ID = R.layout.test_container_activity; 36 37 @Override onCreate(Bundle savedInstanceState)38 protected void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 41 if (getIntent().hasExtra(INTENT_EXTRA_LAYOUT_ID)) { 42 final int layoutId = getIntent().getIntExtra(INTENT_EXTRA_LAYOUT_ID, 43 /* defaultValue= */0); 44 setContentView(layoutId); 45 if (layoutId == CUSTOM_CONTAINER_LAYOUT_ID) { 46 createCustomViews(findViewById(R.id.root_view), 47 getIntent().getIntExtra(INTENT_EXTRA_CUSTOM_VIEWS, MAX_VIEWS)); 48 } 49 } 50 } 51 createCustomViews(LinearLayout root, int number)52 private void createCustomViews(LinearLayout root, int number) { 53 LinearLayout horizontalLayout = null; 54 for (int i = 0; i < number; i++) { 55 final int j = i % 8; 56 if (horizontalLayout != null && j == 0) { 57 root.addView(horizontalLayout); 58 horizontalLayout = null; 59 } 60 if (horizontalLayout == null) { 61 horizontalLayout = createHorizontalLayout(); 62 } 63 horizontalLayout.addView(createItem(null, i)); 64 } 65 if (horizontalLayout != null) { 66 root.addView(horizontalLayout); 67 } 68 } 69 createHorizontalLayout()70 private LinearLayout createHorizontalLayout() { 71 final LinearLayout layout = new LinearLayout(getApplicationContext()); 72 layout.setOrientation(LinearLayout.HORIZONTAL); 73 return layout; 74 } 75 createItem(Drawable drawable, int index)76 private LinearLayout createItem(Drawable drawable, int index) { 77 final LinearLayout group = new LinearLayout(getApplicationContext()); 78 group.setOrientation(LinearLayout.VERTICAL); 79 group.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 80 LinearLayout.LayoutParams.WRAP_CONTENT, /* weight= */ 1.0f)); 81 82 final TextView text = new TextView(this); 83 text.setText("i = " + index); 84 group.addView(text); 85 86 return group; 87 } 88 } 89