Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isScrollable

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isScrollable

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat isScrollable.

Prototype

public boolean isScrollable() 

Source Link

Document

Gets if the node is scrollable.

Usage

From source file:Main.java

/**
 * Check whether a given node is scrollable.
 *
 * @param node The node to examine.// ww  w  .  j av a2 s.co  m
 * @return {@code true} if the node is scrollable.
 */
private static boolean isScrollable(AccessibilityNodeInfoCompat node) {
    if (node.isScrollable()) {
        return true;
    }

    return supportsAnyAction(node, AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD,
            AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
}

From source file:Main.java

/**
 * Determines whether the provided {@link View} and {@link AccessibilityNodeInfoCompat} is a
 * top-level item in a scrollable container.
 *
 * @param view The {@link View} to evaluate
 * @param node The {@link AccessibilityNodeInfoCompat} to evaluate
 * @return {@code true} if it is a top-level item in a scrollable container.
 *///w w w  .j  av  a 2  s  . com
public static boolean isTopLevelScrollItem(@Nullable AccessibilityNodeInfoCompat node, @Nullable View view) {
    if (node == null || view == null) {
        return false;
    }

    View parent = (View) ViewCompat.getParentForAccessibility(view);
    if (parent == null) {
        return false;
    }

    if (node.isScrollable()) {
        return true;
    }

    List actionList = node.getActionList();
    if (actionList.contains(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD)
            || actionList.contains(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD)) {
        return true;
    }

    // AdapterView, ScrollView, and HorizontalScrollView are focusable
    // containers, but Spinner is a special case.
    if (parent instanceof Spinner) {
        return false;
    }

    return parent instanceof AdapterView || parent instanceof ScrollView
            || parent instanceof HorizontalScrollView;
}

From source file:com.android.utils.AccessibilityNodeInfoUtils.java

/**
 * Check whether a given node is scrollable.
 *
 * @param node The node to examine.//from   www  . j a  va  2 s.co  m
 * @return {@code true} if the node is scrollable.
 */
private static boolean isScrollable(AccessibilityNodeInfoCompat node) {
    return node.isScrollable() || supportsAnyAction(node, AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD,
            AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);

}

From source file:com.example.accessibility.OverlayManager.java

private void findComponentScrollable(AccessibilityNodeInfoCompat root) {
    try {//from   w w w .j a va 2s.  com
        if (root.isScrollable()) {
            Log.w("prints", "isScrollable");
            scrollables.add(root);
        }

        for (int i = 0; i < root.getChildCount(); i++) {
            findComponentScrollable(root.getChild(i));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testAccessibility() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear);
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 1000);
    intent.putExtra(GridActivity.EXTRA_STAGGERED, false);
    initActivity(intent);/*from  w w  w  . j ava2 s . c om*/
    mOrientation = BaseGridView.VERTICAL;
    mNumRows = 1;

    assertTrue(0 == mGridView.getSelectedPosition());

    final RecyclerViewAccessibilityDelegate delegateCompat = mGridView.getCompatAccessibilityDelegate();
    final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            delegateCompat.onInitializeAccessibilityNodeInfo(mGridView, info);
        }
    });
    assertTrue("test sanity", info.isScrollable());
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            delegateCompat.performAccessibilityAction(mGridView,
                    AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD, null);
        }
    });
    waitForScrollIdle(mVerifyLayout);
    int selectedPosition1 = mGridView.getSelectedPosition();
    assertTrue(0 < selectedPosition1);

    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            delegateCompat.onInitializeAccessibilityNodeInfo(mGridView, info);
        }
    });
    assertTrue("test sanity", info.isScrollable());
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            delegateCompat.performAccessibilityAction(mGridView,
                    AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD, null);
        }
    });
    waitForScrollIdle(mVerifyLayout);
    int selectedPosition2 = mGridView.getSelectedPosition();
    assertTrue(selectedPosition2 < selectedPosition1);
}