Example usage for android.view View isScrollContainer

List of usage examples for android.view View isScrollContainer

Introduction

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

Prototype

public boolean isScrollContainer() 

Source Link

Document

Indicates whether this view is one of the set of scrollable containers in its window.

Usage

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  ww .  j a v  a  2s  . c  om*/
 */
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));
}

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

ViewHierarchyElement(int id, @Nullable ViewHierarchyElement parent, View fromView) {
    // Bookkeeping
    this.id = id;
    this.parentId = (parent != null) ? parent.getId() : null;

    // API 16+ properties
    this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

    // API 11+ properties
    this.backgroundDrawableColor = (AT_11 && (fromView != null)
            && (fromView.getBackground() instanceof ColorDrawable))
                    ? ((ColorDrawable) fromView.getBackground()).getColor()
                    : null;/* w  ww . j  a  v  a2  s.c om*/

    // Base properties
    this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
    this.className = fromView.getClass().getName();
    this.accessibilityClassName = null;
    this.packageName = fromView.getContext().getPackageName();
    this.resourceName = (fromView.getId() != View.NO_ID)
            ? ViewAccessibilityUtils.getResourceNameForView(fromView)
            : null;
    this.contentDescription = SpannableString.valueOf(fromView.getContentDescription());
    this.enabled = fromView.isEnabled();
    if (fromView instanceof TextView) {
        TextView textView = (TextView) fromView;
        // Hint text takes precedence if no text is present.
        CharSequence text = textView.getText();
        if (TextUtils.isEmpty(text)) {
            text = textView.getHint();
        }
        this.text = SpannableString.valueOf(text);
        this.textSize = textView.getTextSize();
        this.textColor = textView.getCurrentTextColor();
        this.typefaceStyle = (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
    } else {
        this.text = null;
        this.textSize = null;
        this.textColor = null;
        this.typefaceStyle = null;
    }

    this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
    this.clickable = fromView.isClickable();
    this.longClickable = fromView.isLongClickable();
    this.focusable = fromView.isFocusable();
    this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
    this.canScrollForward = (ViewCompat.canScrollVertically(fromView, 1)
            || ViewCompat.canScrollHorizontally(fromView, 1));
    this.canScrollBackward = (ViewCompat.canScrollVertically(fromView, -1)
            || ViewCompat.canScrollHorizontally(fromView, -1));
    this.checkable = (fromView instanceof Checkable);
    this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
    this.hasTouchDelegate = (fromView.getTouchDelegate() != null);

    // There may be subtle differences between the bounds from a View instance compared to that of
    // its AccessibilityNodeInfo. The latter uses a @hide getBoundsOnScreen method, which clips to
    // parent bounds.
    android.graphics.Rect tempRect = new android.graphics.Rect();
    if (fromView.getGlobalVisibleRect(tempRect)) {
        this.boundsInScreen = new Rect(tempRect);
    } else {
        this.boundsInScreen = null;
    }
    this.nonclippedHeight = fromView.getHeight();
    this.nonclippedWidth = fromView.getWidth();
}