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

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

Introduction

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

Prototype

public void setClickable(boolean clickable) 

Source Link

Document

Sets whether this node is clickable.

Usage

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

/**
 * Strings for setting the Role Description in english
 *//*from  w  w  w .  j a v  a2  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  av a2s . 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.launcher3.accessibility.DragAndDropAccessibilityDelegate.java

@Override
protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) {
    if (id == INVALID_ID) {
        throw new IllegalArgumentException("Invalid virtual view id");
    }//from   w  ww  .j av  a  2 s.  c  om

    node.setContentDescription(getLocationDescriptionForIconDrop(id));
    node.setBoundsInParent(getItemBounds(id));

    node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
    node.setClickable(true);
    node.setFocusable(true);
}

From source file:com.facebook.litho.widget.TextSpec.java

@OnPopulateExtraAccessibilityNode
static void onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat node, int extraNodeIndex,
        int componentBoundsLeft, int componentBoundsTop, @Prop(resType = STRING) CharSequence text,
        @FromBoundsDefined Layout textLayout, @FromBoundsDefined ClickableSpan[] clickableSpans) {
    final Spanned spanned = (Spanned) text;

    final ClickableSpan span = clickableSpans[extraNodeIndex];
    final int start = spanned.getSpanStart(span);
    final int end = spanned.getSpanEnd(span);
    final int startLine = textLayout.getLineForOffset(start);
    final int endLine = textLayout.getLineForOffset(end);

    // The bounds for multi-line strings should *only* include the first line.  This is because
    // Talkback triggers its click at the center point of these bounds, and if that center point
    // is outside the spannable, it will click on something else.  There is no harm in not outlining
    // the wrapped part of the string, as the text for the whole string will be read regardless of
    // the bounding box.
    final int selectionPathEnd = startLine == endLine ? end : textLayout.getLineVisibleEnd(startLine);

    textLayout.getSelectionPath(start, selectionPathEnd, sTempPath);
    sTempPath.computeBounds(sTempRectF, /* unused */true);

    sTempRect.set(componentBoundsLeft + (int) sTempRectF.left, componentBoundsTop + (int) sTempRectF.top,
            componentBoundsLeft + (int) sTempRectF.right, componentBoundsTop + (int) sTempRectF.bottom);

    if (sTempRect.isEmpty()) {
        // Text is not actually visible.
        // Override bounds so it doesn't crash ExploreByTouchHelper.java
        sTempRect.set(0, 0, 1, 1);/*from   w ww . ja  va2 s  .  c  o m*/
        node.setBoundsInParent(sTempRect);
        node.setContentDescription(""); // make node non-focusable
        return;
    }

    node.setBoundsInParent(sTempRect);

    node.setClickable(true);
    node.setFocusable(true);
    node.setEnabled(true);
    node.setVisibleToUser(true);
    if (span instanceof AccessibleClickableSpan) {
        node.setText(((AccessibleClickableSpan) span).getAccessibilityDescription());
    } else {
        node.setText(spanned.subSequence(start, end));
    }
}

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  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(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;
}