Example usage for android.view.accessibility AccessibilityNodeInfo getContentDescription

List of usage examples for android.view.accessibility AccessibilityNodeInfo getContentDescription

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo getContentDescription.

Prototype

public CharSequence getContentDescription() 

Source Link

Document

Gets the content description of this node.

Usage

From source file:Main.java

public static void dumpNode(AccessibilityNodeInfo node) {
    Log.d(LOGTAG, String.format("class: %s; text: %s; content-desc: %s", node.getClassName(), node.getText(),
            node.getContentDescription()));
}

From source file:Main.java

public static void findTextAndClick(AccessibilityService accessibilityService, String text) {

    AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow();
    if (accessibilityNodeInfo == null) {
        return;/*from w w w. j a v a  2s  .  c o m*/
    }

    List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
    if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
        for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
            if (nodeInfo != null
                    && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) {
                performClick(nodeInfo);
                break;
            }
        }
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.RedundantContentDescInfoCheck.java

@Override
public List<AccessibilityInfoCheckResult> runCheckOnInfoHierarchy(AccessibilityNodeInfo root, Context context,
        Bundle metadata) {//  w  w w. j a  v  a 2s  .  co  m
    List<AccessibilityInfoCheckResult> results = new ArrayList<AccessibilityInfoCheckResult>();
    // TODO(sjrush): This check needs internationalization support
    if (!Locale.getDefault().getLanguage().equals(Locale.ENGLISH.getLanguage())) {
        results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                "This check only runs in English locales", root));
        return results;
    }

    List<AccessibilityNodeInfoCompat> compatInfos = getAllInfoCompatsInHierarchy(context, root);
    for (AccessibilityNodeInfoCompat compatInfo : compatInfos) {
        AccessibilityNodeInfo info = (AccessibilityNodeInfo) compatInfo.getInfo();
        CharSequence contentDescription = info.getContentDescription();
        if (TextUtils.isEmpty(contentDescription)) {
            results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                    "View has no content description", info));
            continue;
        }
        for (CharSequence redundantWord : redundantWords) {
            if (contentDescription.toString().toLowerCase().contains(redundantWord)) {
                results.add(
                        new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.WARNING,
                                "View's speakable text ends with view type", info));
                break;
            }
        }
    }
    return results;
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

private String fixContentDescription(AccessibilityNodeInfo node) {
    String content = node.getContentDescription().toString();

    // NOTE: Unfortunately, line breaks are missing from content description, thus
    // we are reformatting now:

    // TODO: get charset from header?

    // find "hQ", start of pgp message (0x80 byte) and remove everything before
    content = content.replaceFirst(".*hQ", "hQ");

    StringBuilder builder = new StringBuilder(content);

    // re-add -----BEGIN PGP MESSAGE-----
    String header = BEGIN_PGP_MESSAGE + "\n\n";
    builder.insert(0, header);/* w  w w . ja  v  a  2s.c om*/

    int indexOfEnd = builder.lastIndexOf(END_PGP_MESSAGE);
    // TODO: check if END pgp message is really inside string! if not -> gmail has cut it!
    builder.insert(indexOfEnd, "\n");
    int i = indexOfEnd - CHECKSUM_LENGTH;
    builder.insert(i, "\n");

    // split into 65 character chunks
    int currentIndex = header.length() + 64;
    while (currentIndex < indexOfEnd) {
        builder.insert(currentIndex, "\n");
        currentIndex += 65;

        // stop where checksum starts
        indexOfEnd = builder.lastIndexOf(END_PGP_MESSAGE) - CHECKSUM_LENGTH - 2;
    }

    content = builder.toString();

    if (Constants.DEBUG) {
        // split for long messages
        for (String line : content.split("\n")) {
            Log.d(Constants.TAG, line);
        }
    }

    return content;
}

From source file:com.android.switchaccess.test.ShadowAccessibilityNodeInfoCompat.java

@Implementation
public String getContentDescription() {
    final AccessibilityNodeInfo info = (AccessibilityNodeInfo) mRealObject.getInfo();
    return (String) info.getContentDescription();
}

From source file:com.google.android.apps.common.testing.accessibility.framework.EditableContentDescInfoCheck.java

@Override
public List<AccessibilityInfoCheckResult> runCheckOnInfo(AccessibilityNodeInfo info, Context context,
        Bundle metadata) {/*from w  w  w  .j a v  a2 s .c om*/
    List<AccessibilityInfoCheckResult> results = new ArrayList<AccessibilityInfoCheckResult>(1);
    AccessibilityNodeInfoCompat compatInfo = new AccessibilityNodeInfoCompat(info);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (info.isEditable()) {
            if (!TextUtils.isEmpty(info.getContentDescription())) {
                results.add(
                        new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR,
                                "Editable view should not have a contentDescription", info));
            }
        } else {
            results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                    "Associated view must be editable", info));
        }
    } else {
        // Earlier API versions don't allow us to filter based on editable state, so we'll fall back
        // to using EditTexts instead.

        // TODO(caseyburkhardt): The missing context below will cause us to fail to resolve classes
        // defined within other packages.
        if (AccessibilityNodeInfoUtils.nodeMatchesAnyClassByType(null, compatInfo, EditText.class)) {
            if (!TextUtils.isEmpty(compatInfo.getContentDescription())) {
                results.add(
                        new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR,
                                "EditText should not have a contentDescription", info));
            }
        } else {
            results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                    "Associated view must be an EditText", info));
        }
    }
    return results;
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

private void findPgpNodeInfo(AccessibilityNodeInfo parent, ArrayList<AccessibilityNodeInfo> pgpNodes) {

    for (int i = 0; i < parent.getChildCount(); i++) {
        AccessibilityNodeInfo currentChild = parent.getChild(i);

        /*// w w  w.j a v a2  s  .  c om
         WebView
         |- WebView
        |- View
        |- View
        |- View
         */
        if (WEB_VIEW_CLASS_NAME.equals(parent.getClassName())
                && VIEW_CLASS_NAME.equals(currentChild.getClassName())
                && !TextUtils.isEmpty(currentChild.getContentDescription())
                && currentChild.getContentDescription().toString().startsWith(BEGIN_PGP_MESSAGE)) {

            pgpNodes.add(currentChild);
        } else {
            // recursive traversal
            findPgpNodeInfo(currentChild, pgpNodes);

            currentChild.recycle();
        }
    }
}

From source file:com.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java

private CharSequence formatNode(AccessibilityNodeInfo node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());/* w  ww . j  a  v  a 2 s  .com*/
    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }
    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }
    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText());
    }
    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription());
    }
    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfo.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
    }
    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }
    if (node.isFocusable()) {
        sb.append(":focusable");
    }
    if (node.isFocused()) {
        sb.append(":focused");
    }
    if (node.isSelected()) {
        sb.append(":selected");
    }
    if (node.isClickable()) {
        sb.append(":clickable");
    }
    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }
    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }
    if (!node.isEnabled()) {
        sb.append(":disabled");
    }
    return sb.toString();
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 *
 *///from w  w w . j  av a2  s  .com
public void recycle(AccessibilityNodeInfo info, String target, boolean isClickSelft) {
    int temp = 0;
    if (info != null && info.getChildCount() == 0) {
        if (info.getContentDescription() != null && info.getContentDescription().toString().equals(target)
                && isClickSelft) {

            String content = info.getContentDescription().toString();
            info.performAction(AccessibilityNodeInfo.ACTION_CLICK);
            if (content.equals(AFTER_WORK))
                handleIt(info);
            else if (content.equals(GO_TO_WORK))
                handleGoToWork(info);
            return;
        }
        if (info.getText() != null) {
            if (target.equals(info.getText().toString())) {
                if (isClickSelft) {
                    info.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                    return;
                }
                AccessibilityNodeInfo parent = info.getParent();
                while (parent != null) {
                    if (parent.isClickable()) {
                        parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                        break;
                    }
                    parent = parent.getParent();
                }
            }

        }
    } else {

        for (int i = 0; info != null && i < info.getChildCount(); i++) {
            if (info.getChild(i) != null) {
                temp = i;
                recycle(info.getChild(i), target, isClickSelft);
            }
        }
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * AccessibilityNodeInfo  ?webView // w  w  w .  j a va  2s .  co  m
 *  
 *
 * @param target
 * @param accessibilityNodeInfo
 * @return
 */
private AccessibilityNodeInfo recurseFindByText(String target, AccessibilityNodeInfo accessibilityNodeInfo) {

    if (accessibilityNodeInfo != null && accessibilityNodeInfo.getChildCount() == 0) {
        if ((target.equals(accessibilityNodeInfo.getText())
                || target.equals(accessibilityNodeInfo.getContentDescription())))
            return accessibilityNodeInfo;
        else
            return null;
    } else {
        if (accessibilityNodeInfo == null)
            return null;

        for (int i = 0; i < accessibilityNodeInfo.getChildCount(); i++) {
            AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i);
            AccessibilityNodeInfo isTaget = recurseFindByText(target, child);
            if (isTaget == null)
                continue;
            else
                return isTaget;
        }
        return null;
    }
}