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

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

Introduction

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

Prototype

public void setPackageName(CharSequence packageName) 

Source Link

Document

Sets the package this node comes from.

Usage

From source file:com.yyl.inputmethod.accessibility.AccessibilityEntityProvider.java

/**
 * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
 * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
 * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
 * <p>/* w  w w.  j  a  v a 2 s . c  o m*/
 * A virtual descendant is an imaginary View that is reported as a part of
 * the view hierarchy for accessibility purposes. This enables custom views
 * that draw complex content to report them selves as a tree of virtual
 * views, thus conveying their logical structure.
 * </p>
 * <p>
 * The implementer is responsible for obtaining an accessibility node info
 * from the pool of reusable instances and setting the desired properties of
 * the node info before returning it.
 * </p>
 *
 * @param virtualViewId A client defined virtual view id.
 * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host
 * View.
 * @see AccessibilityNodeInfoCompat
 */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) {
    if (virtualViewId == UNDEFINED) {
        return null;
    }
    if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo);

        // Add the virtual children of the root View.
        final Keyboard keyboard = mKeyboardView.getKeyboard();
        final Key[] keys = keyboard.mKeys;
        for (Key key : keys) {
            final int childVirtualViewId = generateVirtualViewIdForKey(key);
            rootInfo.addChild(mKeyboardView, childVirtualViewId);
        }
        return rootInfo;
    }

    // Find the view that corresponds to the given id.
    final Key key = mVirtualViewIdToKey.get(virtualViewId);
    if (key == null) {
        Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
        return null;
    }
    final String keyDescription = getKeyDescription(key);
    final Rect boundsInParent = key.mHitBox;

    // Calculate the key's in-screen bounds.
    mTempBoundsInScreen.set(boundsInParent);
    mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation));
    final Rect boundsInScreen = mTempBoundsInScreen;

    // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view.
    final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
    info.setPackageName(mKeyboardView.getContext().getPackageName());
    info.setClassName(key.getClass().getName());
    info.setContentDescription(keyDescription);
    info.setBoundsInParent(boundsInParent);
    info.setBoundsInScreen(boundsInScreen);
    info.setParent(mKeyboardView);
    info.setSource(mKeyboardView, virtualViewId);
    info.setBoundsInScreen(boundsInScreen);
    info.setEnabled(true);
    info.setVisibleToUser(true);

    if (mAccessibilityFocusedView == virtualViewId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }
    return info;
}

From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java

/**
 * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
 * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
 * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
 * <p>//from   w ww  .  j  a v a2s .  c o  m
 * A virtual descendant is an imaginary View that is reported as a part of
 * the view hierarchy for accessibility purposes. This enables custom views
 * that draw complex content to report them selves as a tree of virtual
 * views, thus conveying their logical structure.
 * </p>
 * <p>
 * The implementer is responsible for obtaining an accessibility node info
 * from the pool of reusable instances and setting the desired properties of
 * the node info before returning it.
 * </p>
 *
 * @param virtualViewId A client defined virtual view id.
 * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host
 * View.
 * @see AccessibilityNodeInfoCompat
 */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) {
    if (virtualViewId == UNDEFINED) {
        return null;
    }
    if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo);

        // Add the virtual children of the root View.
        final Keyboard keyboard = mKeyboardView.getKeyboard();
        final Key[] keys = keyboard.getKeys();
        for (Key key : keys) {
            final int childVirtualViewId = generateVirtualViewIdForKey(key);
            rootInfo.addChild(mKeyboardView, childVirtualViewId);
        }
        return rootInfo;
    }

    // Find the view that corresponds to the given id.
    final Key key = mVirtualViewIdToKey.get(virtualViewId);
    if (key == null) {
        Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
        return null;
    }
    final String keyDescription = getKeyDescription(key);
    final Rect boundsInParent = key.getHitBox();

    // Calculate the key's in-screen bounds.
    mTempBoundsInScreen.set(boundsInParent);
    mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation));
    final Rect boundsInScreen = mTempBoundsInScreen;

    // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view.
    final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
    info.setPackageName(mKeyboardView.getContext().getPackageName());
    info.setClassName(key.getClass().getName());
    info.setContentDescription(keyDescription);
    info.setBoundsInParent(boundsInParent);
    info.setBoundsInScreen(boundsInScreen);
    info.setParent(mKeyboardView);
    info.setSource(mKeyboardView, virtualViewId);
    info.setBoundsInScreen(boundsInScreen);
    info.setEnabled(true);
    info.setVisibleToUser(true);

    if (mAccessibilityFocusedView == virtualViewId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }
    return info;
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java

/**
 * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
 * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
 * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
 * <p>//  w w w.j  ava  2  s.  co m
 * A virtual descendant is an imaginary View that is reported as a part of
 * the view hierarchy for accessibility purposes. This enables custom views
 * that draw complex content to report them selves as a tree of virtual
 * views, thus conveying their logical structure.
 * </p>
 * <p>
 * The implementer is responsible for obtaining an accessibility node info
 * from the pool of reusable instances and setting the desired properties of
 * the node info before returning it.
 * </p>
 *
 * @param virtualViewId A client defined virtual view id.
 * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host
 * View.
 * @see AccessibilityNodeInfoCompat
 */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) {
    if (virtualViewId == UNDEFINED) {
        return null;
    }
    if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo);
        updateParentLocation();

        // Add the virtual children of the root View.
        final List<Key> sortedKeys = mKeyboard.getSortedKeys();
        final int size = sortedKeys.size();
        for (int index = 0; index < size; index++) {
            final Key key = sortedKeys.get(index);
            if (key.isSpacer()) {
                continue;
            }
            // Use an index of the sorted keys list as a virtual view id.
            rootInfo.addChild(mKeyboardView, index);
        }
        return rootInfo;
    }

    // Find the key that corresponds to the given virtual view id.
    final Key key = getKeyOf(virtualViewId);
    if (key == null) {
        Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
        return null;
    }
    final String keyDescription = getKeyDescription(key);
    final Rect boundsInParent = key.getHitBox();

    // Calculate the key's in-screen bounds.
    mTempBoundsInScreen.set(boundsInParent);
    mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation));
    final Rect boundsInScreen = mTempBoundsInScreen;

    // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view.
    final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
    info.setPackageName(mKeyboardView.getContext().getPackageName());
    info.setClassName(key.getClass().getName());
    info.setContentDescription(keyDescription);
    info.setBoundsInParent(boundsInParent);
    info.setBoundsInScreen(boundsInScreen);
    info.setParent(mKeyboardView);
    info.setSource(mKeyboardView, virtualViewId);
    info.setEnabled(key.isEnabled());
    info.setVisibleToUser(true);
    // Don't add ACTION_CLICK and ACTION_LONG_CLOCK actions while hovering on the key.
    // See {@link #onHoverEnterTo(Key)} and {@link #onHoverExitFrom(Key)}.
    if (virtualViewId != mHoveringNodeId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
        if (key.isLongPressEnabled()) {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK);
        }
    }

    if (mAccessibilityFocusedView == virtualViewId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }
    return info;
}

From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java

private AccessibilityNodeInfoCompat populateNodeForItemInternal(T item, AccessibilityNodeInfoCompat node) {
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    node.setEnabled(true);//from  w w  w . j ava2s .c o  m

    // Allow the client to populate the node.
    populateNodeForItem(item, node);

    if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateNodeForItem()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mParentView.getContext().getPackageName());
    node.setClassName(item.getClass().getName());
    node.setParent(mParentView);
    node.setSource(mParentView, virtualDescendantId);

    if (mFocusedItemId == virtualDescendantId) {
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

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

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

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

    return node;
}

From source file:com.deange.datetimepicker.TouchExplorationHelper.java

private AccessibilityNodeInfoCompat populateNodeForItemInternal(T item, AccessibilityNodeInfoCompat node) {
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    node.setEnabled(true);/* w  ww.  j  a va2s.  c om*/

    // Allow the client to populate the node.
    populateNodeForItem(item, node);

    if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateNodeForItem()");
    }

    // Don&#39;t allow the client to override these properties.
    node.setPackageName(mParentView.getContext().getPackageName());
    node.setClassName(item.getClass().getName());
    node.setParent(mParentView);
    node.setSource(mParentView, virtualDescendantId);

    if (mFocusedItemId == virtualDescendantId) {
        node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

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

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

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

    return node;
}

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

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>//from  w ww  .ja va 2s. c  o m
 * 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(Rect)}
 * </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 getNodeForVirtualViewId(int virtualViewId) {
    final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();

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

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

    if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) {
        throw new RuntimeException(
                "You must add text or a content description in populateNodeForVirtualViewId()");
    }

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

    // 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);
    }

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

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

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

    return node;
}

From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * parent view populated with its virtual descendants.
 *
 * @return An {@link AccessibilityNodeInfoCompat} for the parent view.
 *//*from  w ww  . ja  va2 s.c  o m*/
private AccessibilityNodeInfoCompat getNodeForHost() {
    // Since we don't want the parent to be focusable, but we can't remove
    // actions from a node, copy over the necessary fields.
    final AccessibilityNodeInfoCompat result = AccessibilityNodeInfoCompat.obtain(mHost);
    final AccessibilityNodeInfoCompat source = AccessibilityNodeInfoCompat.obtain(mHost);
    ViewCompat.onInitializeAccessibilityNodeInfo(mHost, source);

    // Copy over parent and screen bounds.
    source.getBoundsInParent(mTempParentRect);
    source.getBoundsInScreen(mTempScreenRect);
    result.setBoundsInParent(mTempParentRect);
    result.setBoundsInScreen(mTempScreenRect);

    // Set up the parent view, if applicable.
    final ViewParent parent = mHost.getParent();
    if (parent instanceof View) {
        result.setParent((View) parent);
    }

    // Populate the minimum required fields.
    result.setVisibleToUser(source.isVisibleToUser());
    result.setPackageName(source.getPackageName());
    result.setClassName(source.getClassName());

    // Add the fake root node.
    result.addChild(mHost, ROOT_ID);

    return result;
}

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

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * parent view populated with its virtual descendants.
 *
 * @return An {@link AccessibilityNodeInfoCompat} for the parent view.
 *//*from ww w. ja  va 2s. c o m*/
private AccessibilityNodeInfoCompat getNodeForHost() {
    // Since we don't want the parent to be focusable, but we can't remove
    // actions from a node, copy over the necessary fields.
    final AccessibilityNodeInfoCompat result = AccessibilityNodeInfoCompat.obtain(mHost);
    final AccessibilityNodeInfoCompat source = AccessibilityNodeInfoCompat.obtain(mHost);
    ViewCompat.onInitializeAccessibilityNodeInfo(mHost, source);

    // Copy over parent and screen bounds.
    source.getBoundsInParent(mTempParentRect);
    source.getBoundsInScreen(mTempScreenRect);
    result.setBoundsInParent(mTempParentRect);
    result.setBoundsInScreen(mTempScreenRect);

    // Set up the parent view, if applicable.
    final ViewParent parent = ViewCompat.getParentForAccessibility(mHost);
    if (parent instanceof View) {
        result.setParent((View) parent);
    }

    // Populate the minimum required fields.
    result.setVisibleToUser(source.isVisibleToUser());
    result.setPackageName(source.getPackageName());
    result.setClassName(source.getClassName());

    // Add the fake root node.
    result.addChild(mHost, ROOT_ID);

    return result;
}

From source file:com.android.inputmethod.accessibility.AccessibilityEntityProvider.java

/**
 * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
 * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
 * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
 * <p>//from w  ww.  j av  a2s  .  co  m
 * A virtual descendant is an imaginary View that is reported as a part of
 * the view hierarchy for accessibility purposes. This enables custom views
 * that draw complex content to report them selves as a tree of virtual
 * views, thus conveying their logical structure.
 * </p>
 * <p>
 * The implementer is responsible for obtaining an accessibility node info
 * from the pool of reusable instances and setting the desired properties of
 * the node info before returning it.
 * </p>
 *
 * @param virtualViewId A client defined virtual view id.
 * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual
 *         descendant or the host View.
 * @see AccessibilityNodeInfoCompat
 */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) {
    AccessibilityNodeInfoCompat info = null;

    if (virtualViewId == UNDEFINED) {
        return null;
    } else if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        info = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info);

        // Add the virtual children of the root View.
        final Keyboard keyboard = mKeyboardView.getKeyboard();
        final Key[] keys = keyboard.mKeys;
        for (Key key : keys) {
            final int childVirtualViewId = generateVirtualViewIdForKey(key);
            info.addChild(mKeyboardView, childVirtualViewId);
        }
    } else {
        // Find the view that corresponds to the given id.
        final Key key = mVirtualViewIdToKey.get(virtualViewId);
        if (key == null) {
            Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
            return null;
        }

        final String keyDescription = getKeyDescription(key);
        final Rect boundsInParent = key.mHitBox;

        // Calculate the key's in-screen bounds.
        mTempBoundsInScreen.set(boundsInParent);
        mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]);

        final Rect boundsInScreen = mTempBoundsInScreen;

        // Obtain and initialize an AccessibilityNodeInfo with
        // information about the virtual view.
        info = AccessibilityNodeInfoCompat.obtain();
        info.setPackageName(mKeyboardView.getContext().getPackageName());
        info.setClassName(key.getClass().getName());
        info.setContentDescription(keyDescription);
        info.setBoundsInParent(boundsInParent);
        info.setBoundsInScreen(boundsInScreen);
        info.setParent(mKeyboardView);
        info.setSource(mKeyboardView, virtualViewId);
        info.setBoundsInScreen(boundsInScreen);
        info.setEnabled(true);
        info.setVisibleToUser(true);

        if (mAccessibilityFocusedView == virtualViewId) {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
        } else {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
        }
    }

    return info;
}

From source file:com.android.hareime.accessibility.AccessibilityEntityProvider.java

/**
 * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
 * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
 * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
 * <p>/*from   w  w  w.  j av a2s.c  o m*/
 * A virtual descendant is an imaginary View that is reported as a part of
 * the view hierarchy for accessibility purposes. This enables custom views
 * that draw complex content to report them selves as a tree of virtual
 * views, thus conveying their logical structure.
 * </p>
 * <p>
 * The implementer is responsible for obtaining an accessibility node info
 * from the pool of reusable instances and setting the desired properties of
 * the node info before returning it.
 * </p>
 *
 * @param virtualViewId A client defined virtual view id.
 * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual
 *         descendant or the host View.
 * @see AccessibilityNodeInfoCompat
 */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) {
    AccessibilityNodeInfoCompat info = null;

    if (virtualViewId == UNDEFINED) {
        return null;
    } else if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        info = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info);

        // Add the virtual children of the root View.
        final Keyboard keyboard = mKeyboardView.getKeyboard();
        final Key[] keys = keyboard.mKeys;
        for (Key key : keys) {
            final int childVirtualViewId = generateVirtualViewIdForKey(key);
            info.addChild(mKeyboardView, childVirtualViewId);
        }
    } else {
        // Find the view that corresponds to the given id.
        final Key key = mVirtualViewIdToKey.get(virtualViewId);
        if (key == null) {
            Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
            return null;
        }

        final String keyDescription = getKeyDescription(key);
        final Rect boundsInParent = key.mHitBox;

        // Calculate the key's in-screen bounds.
        mTempBoundsInScreen.set(boundsInParent);
        mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]);

        final Rect boundsInScreen = mTempBoundsInScreen;

        // Obtain and initialize an AccessibilityNodeInfo with
        // information about the virtual view.
        info = AccessibilityNodeInfoCompat.obtain();
        info.setPackageName(mKeyboardView.getContext().getPackageName());
        info.setClassName(key.getClass().getName());
        info.setContentDescription(keyDescription);
        info.setBoundsInParent(boundsInParent);
        info.setBoundsInScreen(boundsInScreen);
        info.setParent(mKeyboardView);
        info.setSource(mKeyboardView, virtualViewId);
        info.setBoundsInScreen(boundsInScreen);
        info.setEnabled(true);
        info.setClickable(true);
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);

        if (mAccessibilityFocusedView == virtualViewId) {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
        } else {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
        }
    }

    return info;
}