Java Code Examples for android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#setSource()

The following examples show how to use android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#setSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KlyphDrawerLayout.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child)) {
            info.addChild(child);
        }
    }
}
 
Example 2
Source File: DrawerLayout.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    if (DrawerLayout.CAN_HIDE_DESCENDANTS) {
        super.onInitializeAccessibilityNodeInfo(host, info);
    } else {
        AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
        super.onInitializeAccessibilityNodeInfo(host, superNode);
        info.setSource(host);
        ViewParent parent = ViewCompat.getParentForAccessibility(host);
        if (parent instanceof View) {
            info.setParent((View) parent);
        }
        copyNodeInfoNoChildren(info, superNode);
        superNode.recycle();
        addChildrenForAccessibility(info, (ViewGroup) host);
    }
    info.setClassName(DrawerLayout.class.getName());
    info.setFocusable(false);
    info.setFocused(false);
    info.removeAction(AccessibilityActionCompat.ACTION_FOCUS);
    info.removeAction(AccessibilityActionCompat.ACTION_CLEAR_FOCUS);
}
 
Example 3
Source File: ExploreByTouchHelper.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * parent view populated with its virtual descendants.
 *
 * @return An {@link AccessibilityNodeInfoCompat} for the parent view.
 */
private AccessibilityNodeInfoCompat getNodeForRoot() {
    // The root node is identical to the parent node, except that it is a
    // child of the parent view and is populated with virtual descendants.
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mHost);
    ViewCompat.onInitializeAccessibilityNodeInfo(mHost, node);

    // Add the virtual descendants.
    final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>();
    getVisibleVirtualViewIds(virtualViewIds);

    for (Integer virtualViewId : virtualViewIds) {
        node.addChild(mHost, virtualViewId);
    }

    // Set up the node as a child of the parent.
    node.setParent(mHost);
    node.setSource(mHost, ROOT_ID);

    return node;
}
 
Example 4
Source File: DrawerLayout.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setClassName(DrawerLayout.class.getName());
    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
}
 
Example 5
Source File: DrawerLayout.java    From guideshow with MIT License 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);

    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
}
 
Example 6
Source File: f.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfoCompat accessibilitynodeinfocompat)
{
    AccessibilityNodeInfoCompat accessibilitynodeinfocompat1 = AccessibilityNodeInfoCompat.obtain(accessibilitynodeinfocompat);
    super.onInitializeAccessibilityNodeInfo(view, accessibilitynodeinfocompat1);
    accessibilitynodeinfocompat.setSource(view);
    android.view.ViewParent viewparent = ViewCompat.getParentForAccessibility(view);
    if (viewparent instanceof View)
    {
        accessibilitynodeinfocompat.setParent((View)viewparent);
    }
    a(accessibilitynodeinfocompat, accessibilitynodeinfocompat1);
    accessibilitynodeinfocompat1.recycle();
    int i = b.getChildCount();
    for (int j = 0; j < i; j++)
    {
        View view1 = b.getChildAt(j);
        if (!a(view1))
        {
            accessibilitynodeinfocompat.addChild(view1);
        }
    }

}
 
Example 7
Source File: H.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfoCompat accessibilitynodeinfocompat)
{
    AccessibilityNodeInfoCompat accessibilitynodeinfocompat1 = AccessibilityNodeInfoCompat.obtain(accessibilitynodeinfocompat);
    super.onInitializeAccessibilityNodeInfo(view, accessibilitynodeinfocompat1);
    a(accessibilitynodeinfocompat, accessibilitynodeinfocompat1);
    accessibilitynodeinfocompat1.recycle();
    accessibilitynodeinfocompat.setClassName(android/support/v4/widget/SlidingPaneLayout.getName());
    accessibilitynodeinfocompat.setSource(view);
    android.view.ViewParent viewparent = ViewCompat.getParentForAccessibility(view);
    if (viewparent instanceof View)
    {
        accessibilitynodeinfocompat.setParent((View)viewparent);
    }
    int i = b.getChildCount();
    for (int j = 0; j < i; j++)
    {
        View view1 = b.getChildAt(j);
        if (!a(view1) && view1.getVisibility() == 0)
        {
            ViewCompat.setImportantForAccessibility(view1, 1);
            accessibilitynodeinfocompat.addChild(view1);
        }
    }

}
 
Example 8
Source File: SlidingPaneLayout.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlidingPaneLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 9
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
  if (CAN_HIDE_DESCENDANTS) {
    super.onInitializeAccessibilityNodeInfo(host, info);
  } else {
    // Obtain a node for the host, then manually generate the list
    // of children to only include non-obscured views.
    final AccessibilityNodeInfoCompat superNode =
        AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);

    info.setSource(host);
    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
      info.setParent((View) parent);
    }
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    addChildrenForAccessibility(info, (ViewGroup) host);
  }

  info.setClassName(DebugDrawerLayout.class.getName());

  // This view reports itself as focusable so that it can intercept
  // the back button, but we should prevent this view from reporting
  // itself as focusable to accessibility services.
  info.setFocusable(false);
  info.setFocused(false);
}
 
Example 10
Source File: SlidingPaneLayout.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlidingPaneLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 11
Source File: SlidingPaneLayout.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlidingPaneLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == View.VISIBLE) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 12
Source File: SlideLayout.java    From SlideActivity with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlideLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 13
Source File: SlidingPaneLayout.java    From guideshow with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlidingPaneLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 14
Source File: SlideFrameLayout.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
    super.onInitializeAccessibilityNodeInfo(host, superNode);
    copyNodeInfoNoChildren(info, superNode);
    superNode.recycle();

    info.setClassName(SlideFrameLayout.class.getName());
    info.setSource(host);

    final ViewParent parent = ViewCompat.getParentForAccessibility(host);
    if (parent instanceof View) {
        info.setParent((View) parent);
    }

    // This is a best-approximation of addChildrenForAccessibility()
    // that accounts for filtering.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (!filter(child) && (child.getVisibility() == View.VISIBLE)) {
            // Force importance to "yes" since we can't read the value.
            ViewCompat.setImportantForAccessibility(
                child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            info.addChild(child);
        }
    }
}
 
Example 15
Source File: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
private AccessibilityNodeInfoCompat d(int l)
{
    AccessibilityNodeInfoCompat accessibilitynodeinfocompat = AccessibilityNodeInfoCompat.obtain();
    accessibilitynodeinfocompat.setEnabled(true);
    accessibilitynodeinfocompat.setClassName(b);
    onPopulateNodeForVirtualView(l, accessibilitynodeinfocompat);
    if (accessibilitynodeinfocompat.getText() == null && accessibilitynodeinfocompat.getContentDescription() == null)
    {
        throw new RuntimeException("Callbacks must add text or a content description in populateNodeForVirtualViewId()");
    }
    accessibilitynodeinfocompat.getBoundsInParent(d);
    if (d.isEmpty())
    {
        throw new RuntimeException("Callbacks must set parent bounds in populateNodeForVirtualViewId()");
    }
    int i1 = accessibilitynodeinfocompat.getActions();
    if ((i1 & 0x40) != 0)
    {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
    }
    if ((i1 & 0x80) != 0)
    {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
    }
    accessibilitynodeinfocompat.setPackageName(h.getContext().getPackageName());
    accessibilitynodeinfocompat.setSource(h, l);
    accessibilitynodeinfocompat.setParent(h);
    int j1;
    int k1;
    if (j == l)
    {
        accessibilitynodeinfocompat.setAccessibilityFocused(true);
        accessibilitynodeinfocompat.addAction(128);
    } else
    {
        accessibilitynodeinfocompat.setAccessibilityFocused(false);
        accessibilitynodeinfocompat.addAction(64);
    }
    if (a(d))
    {
        accessibilitynodeinfocompat.setVisibleToUser(true);
        accessibilitynodeinfocompat.setBoundsInParent(d);
    }
    h.getLocationOnScreen(f);
    j1 = f[0];
    k1 = f[1];
    c.set(d);
    c.offset(j1, k1);
    accessibilitynodeinfocompat.setBoundsInScreen(c);
    return accessibilitynodeinfocompat;
}
 
Example 16
Source File: ExploreByTouchHelper.java    From guideshow with MIT License 4 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>
 * Allows the implementing class to specify most node properties, but
 * overrides the following:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setPackageName}
 * <li>{@link AccessibilityNodeInfoCompat#setClassName}
 * <li>{@link AccessibilityNodeInfoCompat#setParent(View)}
 * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)}
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)}
 * </ul>
 * <p>
 * Uses the bounds of the parent view and the parent-relative bounding
 * rectangle specified by
 * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically
 * update the following properties:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent}
 * </ul>
 *
 * @param virtualViewId The virtual view id for item for which to construct
 *            a node.
 * @return An {@link AccessibilityNodeInfoCompat} for the specified item.
 */
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) {
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();

    // Ensure the client has good defaults.
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the node.
    onPopulateNodeForVirtualView(virtualViewId, node);

    // Make sure the developer is following the rules.
    if ((node.getText() == null) && (node.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateNodeForVirtualViewId()");
    }

    node.getBoundsInParent(mTempParentRect);
    if (mTempParentRect.isEmpty()) {
        throw new RuntimeException("Callbacks must set parent bounds in "
                + "populateNodeForVirtualViewId()");
    }

    final int actions = node.getActions();
    if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }
    if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mView.getContext().getPackageName());
    node.setSource(mView, virtualViewId);
    node.setParent(mView);

    // Manage internal accessibility focus state.
    if (mFocusedVirtualViewId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(mTempParentRect)) {
        node.setVisibleToUser(true);
        node.setBoundsInParent(mTempParentRect);
    }

    // Calculate screen-relative bound.
    mView.getLocationOnScreen(mTempGlobalRect);
    final int offsetX = mTempGlobalRect[0];
    final int offsetY = mTempGlobalRect[1];
    mTempScreenRect.set(mTempParentRect);
    mTempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(mTempScreenRect);

    return node;
}
 
Example 17
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>
 * Allows the implementing class to specify most node properties, but
 * overrides the following:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setPackageName}
 * <li>{@link AccessibilityNodeInfoCompat#setClassName}
 * <li>{@link AccessibilityNodeInfoCompat#setParent(View)}
 * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)}
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)}
 * </ul>
 * <p>
 * Uses the bounds of the parent view and the parent-relative bounding
 * rectangle specified by
 * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically
 * update the following properties:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent}
 * </ul>
 *
 * @param virtualViewId The virtual view id for item for which to construct
 *            a node.
 * @return An {@link AccessibilityNodeInfoCompat} for the specified item.
 */
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) {
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();

    // Ensure the client has good defaults.
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the node.
    onPopulateNodeForVirtualView(virtualViewId, node);

    // Make sure the developer is following the rules.
    if ((node.getText() == null) && (node.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateNodeForVirtualViewId()");
    }

    node.getBoundsInParent(mTempParentRect);
    if (mTempParentRect.isEmpty()) {
        throw new RuntimeException("Callbacks must set parent bounds in "
                + "populateNodeForVirtualViewId()");
    }

    final int actions = node.getActions();
    if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }
    if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mView.getContext().getPackageName());
    node.setSource(mView, virtualViewId);
    node.setParent(mView);

    // Manage internal accessibility focus state.
    if (mFocusedVirtualViewId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(mTempParentRect)) {
        node.setVisibleToUser(true);
        node.setBoundsInParent(mTempParentRect);
    }

    // Calculate screen-relative bound.
    mView.getLocationOnScreen(mTempGlobalRect);
    final int offsetX = mTempGlobalRect[0];
    final int offsetY = mTempGlobalRect[1];
    mTempScreenRect.set(mTempParentRect);
    mTempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(mTempScreenRect);

    return node;
}
 
Example 18
Source File: ExploreByTouchHelper.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>
 * Allows the implementing class to specify most node properties, but
 * overrides the following:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setPackageName}
 * <li>{@link AccessibilityNodeInfoCompat#setClassName}
 * <li>{@link AccessibilityNodeInfoCompat#setParent(View)}
 * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)}
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)}
 * </ul>
 * <p>
 * Uses the bounds of the parent view and the parent-relative bounding
 * rectangle specified by
 * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically
 * update the following properties:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent}
 * </ul>
 *
 * @param virtualViewId The virtual view id for item for which to construct
 *            a node.
 * @return An {@link AccessibilityNodeInfoCompat} for the specified item.
 */
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) {
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();

    // Ensure the client has good defaults.
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the node.
    onPopulateNodeForVirtualView(virtualViewId, node);

    // Make sure the developer is following the rules.
    if ((node.getText() == null) && (node.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateNodeForVirtualViewId()");
    }

    node.getBoundsInParent(mTempParentRect);
    if (mTempParentRect.isEmpty()) {
        throw new RuntimeException("Callbacks must set parent bounds in "
                + "populateNodeForVirtualViewId()");
    }

    final int actions = node.getActions();
    if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }
    if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mView.getContext().getPackageName());
    node.setSource(mView, virtualViewId);
    node.setParent(mView);

    // Manage internal accessibility focus state.
    if (mFocusedVirtualViewId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(mTempParentRect)) {
        node.setVisibleToUser(true);
        node.setBoundsInParent(mTempParentRect);
    }

    // Calculate screen-relative bound.
    mView.getLocationOnScreen(mTempGlobalRect);
    final int offsetX = mTempGlobalRect[0];
    final int offsetY = mTempGlobalRect[1];
    mTempScreenRect.set(mTempParentRect);
    mTempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(mTempScreenRect);

    return node;
}
 
Example 19
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 4 votes vote down vote up
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) {
    AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);
    onPopulateNodeForVirtualView(virtualViewId, node);
    if (node.getText() == null && node.getContentDescription() == null) {
        throw new RuntimeException("Callbacks must add text or a content description in populateNodeForVirtualViewId()");
    }
    node.getBoundsInParent(this.mTempParentRect);
    if (this.mTempParentRect.isEmpty()) {
        throw new RuntimeException("Callbacks must set parent bounds in populateNodeForVirtualViewId()");
    }
    int actions = node.getActions();
    if ((actions & 64) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
    } else if ((actions & 128) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
    } else {
        node.setPackageName(this.mView.getContext().getPackageName());
        node.setSource(this.mView, virtualViewId);
        node.setParent(this.mView);
        if (this.mFocusedVirtualViewId == virtualViewId) {
            node.setAccessibilityFocused(true);
            node.addAction(128);
        } else {
            node.setAccessibilityFocused(false);
            node.addAction(64);
        }
        if (intersectVisibleToUser(this.mTempParentRect)) {
            node.setVisibleToUser(true);
            node.setBoundsInParent(this.mTempParentRect);
        }
        this.mView.getLocationOnScreen(this.mTempGlobalRect);
        int offsetX = this.mTempGlobalRect[0];
        int offsetY = this.mTempGlobalRect[1];
        this.mTempScreenRect.set(this.mTempParentRect);
        this.mTempScreenRect.offset(offsetX, offsetY);
        node.setBoundsInScreen(this.mTempScreenRect);
        return node;
    }
}
 
Example 20
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>
 * Allows the implementing class to specify most node properties, but
 * overrides the following:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setPackageName}
 * <li>{@link AccessibilityNodeInfoCompat#setClassName}
 * <li>{@link AccessibilityNodeInfoCompat#setParent(View)}
 * <li>{@link AccessibilityNodeInfoCompat#setSource(View, int)}
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)}
 * </ul>
 * <p>
 * Uses the bounds of the parent view and the parent-relative bounding
 * rectangle specified by
 * {@link AccessibilityNodeInfoCompat#getBoundsInParent} to automatically
 * update the following properties:
 * <ul>
 * <li>{@link AccessibilityNodeInfoCompat#setVisibleToUser}
 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent}
 * </ul>
 *
 * @param virtualViewId The virtual view id for item for which to construct
 *            a node.
 * @return An {@link AccessibilityNodeInfoCompat} for the specified item.
 */
private AccessibilityNodeInfoCompat createNodeForChild(int virtualViewId) {
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();

    // Ensure the client has good defaults.
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the node.
    onPopulateNodeForVirtualView(virtualViewId, node);

    // Make sure the developer is following the rules.
    if ((node.getText() == null) && (node.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateNodeForVirtualViewId()");
    }

    node.getBoundsInParent(mTempParentRect);
    if (mTempParentRect.isEmpty()) {
        throw new RuntimeException("Callbacks must set parent bounds in "
                + "populateNodeForVirtualViewId()");
    }

    final int actions = node.getActions();
    if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }
    if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in "
                + "populateNodeForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mView.getContext().getPackageName());
    node.setSource(mView, virtualViewId);
    node.setParent(mView);

    // Manage internal accessibility focus state.
    if (mFocusedVirtualViewId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(mTempParentRect)) {
        node.setVisibleToUser(true);
        node.setBoundsInParent(mTempParentRect);
    }

    // Calculate screen-relative bound.
    mView.getLocationOnScreen(mTempGlobalRect);
    final int offsetX = mTempGlobalRect[0];
    final int offsetY = mTempGlobalRect[1];
    mTempScreenRect.set(mTempParentRect);
    mTempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(mTempScreenRect);

    return node;
}