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

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

Introduction

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

Prototype

int ACTION_SELECT

To view the source code for android.support.v4.view.accessibility AccessibilityNodeInfoCompat ACTION_SELECT.

Click Source Link

Document

Action that selects the node.

Usage

From source file:com.android.talkback.speechrules.RuleNonTextViews.java

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    final CharSequence text = AccessibilityNodeInfoUtils.getNodeText(node);
    CharSequence labelText = null;
    if (!TextUtils.isEmpty(text)) {
        labelText = text;//ww w  . ja  v a 2s.c  om
    } else {
        if (mLabelManager != null) {
            // Check to see if a custom label exists for the unlabeled control.
            Label label = mLabelManager.getLabelForViewIdFromCache(node.getViewIdResourceName());
            if (label != null) {
                labelText = label.getText();
            }
        }
    }

    // If the node's role is ROLE_IMAGE and the node is selectable, there's a non-trivial chance
    // that the node acts like a button (but we can't be sure). In this case, it is safest to
    // not append any role text to avoid confusing the user.
    CharSequence roleText;
    if (Role.getRole(node) == Role.ROLE_IMAGE
            && AccessibilityNodeInfoUtils.supportsAction(node, AccessibilityNodeInfoCompat.ACTION_SELECT)) {
        roleText = node.getRoleDescription(); // But don't fall back to default text.
    } else {
        roleText = Role.getRoleDescriptionOrDefault(context, node);
    }

    CharSequence unlabelledState;
    if (labelText == null) {
        unlabelledState = context.getString(R.string.value_unlabelled);
    } else {
        unlabelledState = null;
    }

    SpannableStringBuilder output = new SpannableStringBuilder();
    StringBuilderUtils.append(output, labelText, roleText);
    StringBuilderUtils.append(output, unlabelledState);

    return output;
}

From source file:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java

@Nullable
public static String getActions(AccessibilityNodeInfoCompat node) {
    final StringBuilder actionLabels = new StringBuilder();
    final String separator = ", ";

    for (AccessibilityActionCompat action : node.getActionList()) {
        if (actionLabels.length() > 0) {
            actionLabels.append(separator);
        }// w  ww.  ja v a  2  s  .  c om
        switch (action.getId()) {
        case AccessibilityNodeInfoCompat.ACTION_FOCUS:
            actionLabels.append("focus");
            break;
        case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS:
            actionLabels.append("clear-focus");
            break;
        case AccessibilityNodeInfoCompat.ACTION_SELECT:
            actionLabels.append("select");
            break;
        case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
            actionLabels.append("clear-selection");
            break;
        case AccessibilityNodeInfoCompat.ACTION_CLICK:
            actionLabels.append("click");
            break;
        case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
            actionLabels.append("long-click");
            break;
        case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
            actionLabels.append("accessibility-focus");
            break;
        case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
            actionLabels.append("clear-accessibility-focus");
            break;
        case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
            actionLabels.append("next-at-movement-granularity");
            break;
        case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
            actionLabels.append("previous-at-movement-granularity");
            break;
        case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT:
            actionLabels.append("next-html-element");
            break;
        case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT:
            actionLabels.append("previous-html-element");
            break;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
            actionLabels.append("scroll-forward");
            break;
        case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
            actionLabels.append("scroll-backward");
            break;
        case AccessibilityNodeInfoCompat.ACTION_CUT:
            actionLabels.append("cut");
            break;
        case AccessibilityNodeInfoCompat.ACTION_COPY:
            actionLabels.append("copy");
            break;
        case AccessibilityNodeInfoCompat.ACTION_PASTE:
            actionLabels.append("paste");
            break;
        case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
            actionLabels.append("set-selection");
            break;
        default:
            CharSequence label = action.getLabel();
            if (label != null) {
                actionLabels.append(label);
            } else {
                actionLabels.append("unknown");
            }
            break;
        }
    }

    return actionLabels.length() > 0 ? actionLabels.toString() : null;
}