FileDocCategorySizeDatePackage
ViewLayerInvalidationActivity.javaAPI DocAndroid 5.1 API6174Thu Mar 12 22:22:44 GMT 2015com.android.test.hwui

ViewLayerInvalidationActivity

public class ViewLayerInvalidationActivity extends android.app.Activity

Fields Summary
int
currentColor
boolean
nestedLayersOn
ArrayList
linearLayouts
ArrayList
topLayouts
ArrayList
textViews
android.widget.LinearLayout
container
boolean
randomInvalidates
android.widget.TextView
nestedStatusTV
android.widget.TextView
invalidateStatusTV
static final String
NO_NESTING
static final String
NESTING
static final String
NO_INVALIDATING
static final String
INVALIDATING
static final int
TEXT_COLOR_INTERVAL
static final int
INVALIDATING_INTERVAL
static final int
NESTING_INTERVAL
private Runnable
textColorSetter
private Runnable
randomInvalidatesSetter
private Runnable
nestedLayerSetter
Constructors Summary
Methods Summary
private voidcollectLinearLayouts(android.view.View view)

        if (!(view instanceof LinearLayout)) {
            return;
        }
        LinearLayout parent = (LinearLayout) view;
        linearLayouts.add(parent);
        for (int i = 0; i < parent.getChildCount(); ++i) {
            collectLinearLayouts(parent.getChildAt(i));
        }
    
private voidcollectTextViews(android.view.View view)

        if (view instanceof TextView) {
            textViews.add((TextView) view);
            return;
        }
        if (!(view instanceof ViewGroup)) {
            return;
        }
        ViewGroup parent = (ViewGroup) view;
        for (int i = 0; i < parent.getChildCount(); ++i) {
            collectTextViews(parent.getChildAt(i));
        }
    
public voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_layer_invalidation);

        container = (LinearLayout) findViewById(R.id.container);
        final LinearLayout container1 = (LinearLayout) findViewById(R.id.container1);
        final LinearLayout container2 = (LinearLayout) findViewById(R.id.container2);
        final LinearLayout container3 = (LinearLayout) findViewById(R.id.container3);
        nestedStatusTV = (TextView) findViewById(R.id.nestedStatus);
        invalidateStatusTV = (TextView) findViewById(R.id.invalidateStatus);
        final TextView tva = (TextView) findViewById(R.id.textviewa);

        topLayouts.add(container1);
        topLayouts.add(container2);
        topLayouts.add(container3);

        collectLinearLayouts(container);
        collectTextViews(container);

        nestedStatusTV.setText(NO_NESTING);
        invalidateStatusTV.setText(NO_INVALIDATING);

        tva.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        container1.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        container2.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        container3.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        container.postDelayed(textColorSetter, TEXT_COLOR_INTERVAL);
        container.postDelayed(nestedLayerSetter, NESTING_INTERVAL);
        container.postDelayed(randomInvalidatesSetter, INVALIDATING_INTERVAL);
    
private voidrandomInvalidator(android.view.ViewGroup parent)
Invalidates views based on random chance (50%). This is meant to test invalidating several items in the hierarchy at the same time, which can cause artifacts if our invalidation-propagation logic is not sound.


                                          
        
        for (int i = 0; i < parent.getChildCount(); ++i) {
            View child = parent.getChildAt(i);
            if (Math.random() < .5) {
                child.invalidate();
            }
            if (child instanceof ViewGroup) {
                randomInvalidator((ViewGroup) child);
            }
        }