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 package com.android.test.uibench; 17 18 import android.animation.ObjectAnimator; 19 import android.animation.ValueAnimator; 20 import android.graphics.Color; 21 import android.os.Bundle; 22 import android.support.v7.app.AppCompatActivity; 23 import android.view.ViewGroup; 24 import android.widget.LinearLayout; 25 26 import java.util.ArrayList; 27 28 /** 29 * Tests invalidation/record performance by invalidating a large number of easily rendered 30 * nested views. 31 */ 32 public class InvalidateTreeActivity extends AppCompatActivity { 33 private final ArrayList<LinearLayout> mLayouts = new ArrayList<>(); 34 35 private int mColorToggle = 0; 36 createQuadTree(LinearLayout parent, int remainingDepth)37 private void createQuadTree(LinearLayout parent, int remainingDepth) { 38 mLayouts.add(parent); 39 if (remainingDepth <= 0) { 40 mColorToggle = (mColorToggle + 1) % 4; 41 parent.setBackgroundColor((mColorToggle < 2) ? Color.RED : Color.BLUE); 42 return; 43 } 44 45 boolean vertical = remainingDepth % 2 == 0; 46 parent.setOrientation(vertical ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL); 47 48 for (int i = 0; i < 2; i++) { 49 LinearLayout child = new LinearLayout(this); 50 // vertical: match parent in x axis, horizontal: y axis. 51 parent.addView(child, new LinearLayout.LayoutParams( 52 (vertical ? ViewGroup.LayoutParams.MATCH_PARENT : 0), 53 (vertical ? 0 : ViewGroup.LayoutParams.MATCH_PARENT), 54 1.0f)); 55 56 createQuadTree(child, remainingDepth - 1); 57 } 58 } 59 60 @SuppressWarnings("unused") 61 public void setIgnoredValue(int ignoredValue) { 62 for (int i = 0; i < mLayouts.size(); i++) { 63 mLayouts.get(i).invalidate(); 64 } 65 } 66 67 @Override 68 protected void onCreate(Bundle savedInstanceState) { 69 super.onCreate(savedInstanceState); 70 LinearLayout root = new LinearLayout(this); 71 createQuadTree(root, 8); 72 setContentView(root); 73 74 ObjectAnimator animator = ObjectAnimator.ofInt(this, "ignoredValue", 0, 1000); 75 animator.setRepeatMode(ValueAnimator.REVERSE); 76 animator.setRepeatCount(ValueAnimator.INFINITE); 77 animator.start(); 78 } 79 } 80