| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 androidx.appcompat.app.AppCompatActivity; |
| 23 |
import android.view.ViewGroup; |
| 24 |
import android.widget.LinearLayout; |
| 25 |
|
| 26 |
import java.util.ArrayList; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class InvalidateTreeActivity extends AppCompatActivity { |
| 33 |
private final ArrayList<LinearLayout> mLayouts = new ArrayList<>(); |
| 34 |
|
| 35 |
private int mColorToggle = 0; |
| 36 |
|
| 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 |
|
| 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 |
} |