Example usage for android.view ViewGroup setOnHierarchyChangeListener

List of usage examples for android.view ViewGroup setOnHierarchyChangeListener

Introduction

In this page you can find the example usage for android.view ViewGroup setOnHierarchyChangeListener.

Prototype

public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener) 

Source Link

Document

Register a callback to be invoked when a child is added to or removed from this view.

Usage

From source file:com.android.launcher2.HideFromAccessibilityHelper.java

private void setImportantForAccessibilityToNoHelper(View v) {
    mPreviousValues.put(v, ViewCompat.getImportantForAccessibility(v));
    ViewCompat.setImportantForAccessibility(v, View.IMPORTANT_FOR_ACCESSIBILITY_NO);

    // Call method on children recursively
    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;
        vg.setOnHierarchyChangeListener(this);
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);

            if (includeView(child)) {
                setImportantForAccessibilityToNoHelper(child);
            }/* ww  w  . ja v a2  s.  c o  m*/
        }
    }
}

From source file:com.android.launcher2.HideFromAccessibilityHelper.java

private void restoreImportantForAccessibilityHelper(View v) {
    ViewCompat.setImportantForAccessibility(v, mPreviousValues.get(v));
    mPreviousValues.remove(v);/*  w ww.ja v a  2 s.  co m*/

    // Call method on children recursively
    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;

        // We assume if a class implements OnHierarchyChangeListener, it listens
        // to changes to any of its children (happens to be the case in Launcher)
        if (vg instanceof OnHierarchyChangeListener) {
            vg.setOnHierarchyChangeListener((OnHierarchyChangeListener) vg);
        } else {
            vg.setOnHierarchyChangeListener(null);
        }
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            if (includeView(child)) {
                restoreImportantForAccessibilityHelper(child);
            }
        }
    }
}