Example usage for android.view View getAccessibilityNodeProvider

List of usage examples for android.view View getAccessibilityNodeProvider

Introduction

In this page you can find the example usage for android.view View getAccessibilityNodeProvider.

Prototype

public AccessibilityNodeProvider getAccessibilityNodeProvider() 

Source Link

Document

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to android.accessibilityservice.AccessibilityService s that explore the window content.

Usage

From source file:com.google.android.apps.common.testing.accessibility.framework.ViewAccessibilityUtils.java

/**
 * @see View#isImportantForAccessibility()
 *///w  w w . j a  v a 2s  .  c  o  m
public static boolean isImportantForAccessibility(View view) {
    if (view == null) {
        return false;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return view.isImportantForAccessibility();
    } else {
        // On earlier APIs, we must piece together accessibility importance from the available
        // properties. We return false incorrectly for some cases where unretrievable listeners
        // prevent us from determining importance.

        // If the developer marked the view as explicitly not important, it isn't.
        int mode = view.getImportantForAccessibility();
        if ((mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO)
                || (mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)) {
            return false;
        }

        // No parent view can be hiding us. (APIs 19 to 21)
        ViewParent parent = view.getParent();
        while (parent instanceof View) {
            if (((View) parent)
                    .getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
                return false;
            }
            parent = parent.getParent();
        }

        // Interrogate the view's other properties to determine importance.
        return (mode == View.IMPORTANT_FOR_ACCESSIBILITY_YES) || isActionableForAccessibility(view)
                || hasListenersForAccessibility(view) || (view.getAccessibilityNodeProvider() != null)
                || (ViewCompat.getAccessibilityLiveRegion(view) != ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE);
    }
}