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

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

Introduction

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

Prototype

public void setClassName(CharSequence className) 

Source Link

Document

Sets the class this node comes from.

Usage

From source file:com.facebook.react.uimanager.AccessibilityDelegateUtil.java

/**
 * Strings for setting the Role Description in english
 *//* w  w  w.j  a va2  s .  c o m*/

//TODO: Eventually support for other languages on talkback

public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role,
        final Context context) {
    nodeInfo.setClassName(role.getValue());
    if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
        if (role.equals(AccessibilityRole.LINK)) {
            nodeInfo.setRoleDescription(context.getString(R.string.link_description));
        }
        if (role.equals(AccessibilityRole.SEARCH)) {
            nodeInfo.setRoleDescription(context.getString(R.string.search_description));
        }
        if (role.equals(AccessibilityRole.IMAGE)) {
            nodeInfo.setRoleDescription(context.getString(R.string.image_description));
        }
        if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
            nodeInfo.setRoleDescription(context.getString(R.string.image_button_description));
        }
        if (role.equals(AccessibilityRole.ADJUSTABLE)) {
            nodeInfo.setRoleDescription(context.getString(R.string.adjustable_description));
        }
    }
    if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
        nodeInfo.setClickable(true);
    }
}

From source file:com.facebook.react.uimanager.AccessibilityRoleUtil.java

/**
 * Strings for setting the Role Description in english
 *//*ww  w.j  a  v  a 2s.c o m*/

//TODO: Eventually support fot other languages on talkback

public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role,
        final Context context) {
    nodeInfo.setClassName(role.getValue());
    if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
        if (role.equals(AccessibilityRole.LINK)) {
            nodeInfo.setRoleDescription(context.getString(R.string.link_description));
        }
        if (role.equals(AccessibilityRole.SEARCH)) {
            nodeInfo.setRoleDescription(context.getString(R.string.search_description));
        }
        if (role.equals(AccessibilityRole.IMAGE)) {
            nodeInfo.setRoleDescription(context.getString(R.string.image_description));
        }
        if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
            nodeInfo.setRoleDescription(context.getString(R.string.image_button_description));
        }
        if (role.equals(AccessibilityRole.ADJUSTABLE)) {
            nodeInfo.setRoleDescription(context.getString(R.string.adjustable_description));
        }
    }
    if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
        nodeInfo.setClickable(true);
    }
}

From source file:com.android.datetimepicker.AccessibleTextView.java

private void installAccessibilityDelegate() {
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override//from w  w w.  java2  s  .  c om
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setClassName(Button.class.getName());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setClassName(Button.class.getName());
        }
    });
}

From source file:android.support.v7.widget.RecyclerViewAccessibilityDelegateEx.java

@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    info.setClassName(RecyclerView.class.getName());
    if (mRecyclerView.getLayoutManager() != null) {
        mRecyclerView.getLayoutManager().onInitializeAccessibilityNodeInfo(info);
    }//from  www  .j a v  a 2 s  . c  o  m
}

From source file:android.support.v7.widget.RecyclerViewAccessibilityDelegate.java

@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    info.setClassName(RecyclerView.class.getName());
    if (!shouldIgnore() && mRecyclerView.getLayoutManager() != null) {
        mRecyclerView.getLayoutManager().onInitializeAccessibilityNodeInfo(info);
    }/*www.  j  a  v a 2  s  . com*/
}

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

@Override
protected final void populateNodeForVirtualViewId(int virtualViewId, AccessibilityNodeInfoCompat node) {
    final T item = getItemForVirtualViewId(virtualViewId);
    if (item == null) {
        return;//from w  w w  .j  a v a2s. c  o m
    }

    populateNodeForItem(item, node);
    node.setClassName(item.getClass().getName());
}

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  ww.java 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   www.  java 2s  .c om*/
 * 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>//from   w w  w. j a  va 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.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * specified item. Automatically manages accessibility focus actions.
 * <p>/* w  w  w.  ja  va 2 s  .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;
}