Example usage for android.view View getParentForAccessibility

List of usage examples for android.view View getParentForAccessibility

Introduction

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

Prototype

public ViewParent getParentForAccessibility() 

Source Link

Document

Gets the parent for accessibility purposes.

Usage

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

/**
 * Determines if the supplied {@link View} has an ancestor which meets the criteria for gaining
 * accessibility focus./*from www  .  j a v  a  2s.  c om*/
 * <p>
 * NOTE: This method only evaluates ancestors which may be considered important for accessibility
 * and explicitly does not evaluate the supplied {@code view}.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if an ancestor of {@code view} may gain accessibility focus, {@code false}
 *         otherwise
 */
private static boolean hasFocusableAncestor(View view) {
    if (view == null) {
        return false;
    }

    ViewParent parent = view.getParentForAccessibility();
    if (!(parent instanceof View)) {
        return false;
    }

    if (isAccessibilityFocusable((View) parent)) {
        return true;
    }

    return hasFocusableAncestor((View) parent);
}

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

/**
 * Determines if the supplied {@link View} is a top-level item within a scrollable container.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is a top-level view within a scrollable container,
 *         {@code false} otherwise//w w w  .j av  a  2  s  .  c  o m
 */
private static boolean isChildOfScrollableContainer(View view) {
    if (view == null) {
        return false;
    }

    ViewParent viewParent = view.getParentForAccessibility();
    if ((viewParent == null) || !(viewParent instanceof View)) {
        return false;
    }

    View parent = (View) viewParent;
    if (parent.isScrollContainer()) {
        return true;
    }

    // Specifically check for parents that are AdapterView, ScrollView, or HorizontalScrollView, but
    // exclude Spinners, which are a special case of AdapterView.
    return (((parent instanceof AdapterView) || (parent instanceof ScrollView)
            || (parent instanceof HorizontalScrollView)) && !(parent instanceof Spinner));
}