android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#isAccessibilityFocused ( )源码实例Demo

下面列出了android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#isAccessibilityFocused ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: brailleback   文件: NodeBrailler.java
/**
 * Formats {@code node} and its descendants, appending the result
 * to {@code sb}.
 */
private void formatSubtree(AccessibilityNodeInfoCompat node,
        Editable result) {
    if (!node.isVisibleToUser()) {
        return;
    }

    BrailleRule rule = mRuleRepository.find(node);
    SpannableStringBuilder subtreeResult = new SpannableStringBuilder();
    rule.format(subtreeResult, mContext, node);
    if (rule.includeChildren(node, mContext)) {
        int childCount = node.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            AccessibilityNodeInfoCompat child = node.getChild(i);
            if (child == null) {
                continue;
            }
            formatSubtree(child, subtreeResult);
            child.recycle();
        }
    }
    if (!TextUtils.isEmpty(subtreeResult)) {
        // If the node is accessibility focused, add the focus span
        // here to cover the node and its formatted children.
        // This is a fallback in case the formatting rule hasn't set
        // focus by itself.
        if (node.isAccessibilityFocused()
                && subtreeResult.getSpans(0, subtreeResult.length(),
                        DisplaySpans.FocusSpan.class).length == 0) {
            DisplaySpans.addFocus(subtreeResult, 0,
                    subtreeResult.length());
        }
        addNodeSpanForUncovered(node, subtreeResult);
        StringUtils.appendWithSpaces(result, subtreeResult);
    }
}
 
源代码2 项目: brailleback   文件: SearchNavigationMode.java
/**
 * Searches for the next result matching the current search query in the
 * specified direction. Ordering of results taken from linear navigation.
 * Returns whether there is another result in that direction.
 */
private boolean nextResult(int direction) {
    AccessibilityNodeInfoRef next = new AccessibilityNodeInfoRef();
    next.reset(NodeFocusFinder.focusSearch(
            getCurrentNode(), direction));
    AccessibilityNodeInfoCompat focusableNext = null;
    try {
        while (next.get() != null) {
            if (nodeMatchesQuery(next.get())) {
                // Even if the text matches, we need to make sure the node
                // should be focused or has a parent that should be focused.
                focusableNext =
                        AccessibilityNodeInfoUtils.findFocusFromHover(
                            mAccessibilityService, next.get());

                // Only count this as a match if it doesn't lead to the same
                // parent.
                if (focusableNext != null &&
                    !focusableNext.isAccessibilityFocused()) {
                    break;
                }
            }
            next.reset(NodeFocusFinder.focusSearch(next.get(), direction));
        }

        if (focusableNext == null) {
            return false;
        }

        mMatchedNode.reset(next);
        return focusableNext.performAction(
                AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(focusableNext);
        next.recycle();
    }
}
 
源代码3 项目: brailleback   文件: DefaultNavigationMode.java
/**
 * Attempts to navigate to the top-most focusable node in the tree.
 */
private boolean attemptNavigateTop() {
    AccessibilityNodeInfoCompat root =
            AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
    AccessibilityNodeInfoCompat toFocus = null;
    if (AccessibilityNodeInfoUtils.shouldFocusNode(
                    mAccessibilityService, root)) {
        toFocus = root;
        root = null;
    } else {
        toFocus = mFocusFinder.linear(root, FocusFinder.SEARCH_FORWARD);
        if (toFocus == null) {
            // Fall back on root as a last resort.
            toFocus = root;
            root = null;
        }
    }

    try {
        if (toFocus.isAccessibilityFocused()) {
            brailleFocusedNode();
            return true;
        }

        return toFocus.performAction(
            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, toFocus);
    }
}
 
源代码4 项目: brailleback   文件: DefaultNavigationMode.java
/**
 * Attempts to navigate to the bottom-most focusable node in the tree.
 */
private boolean attemptNavigateBottom() {
    AccessibilityNodeInfoCompat root =
            AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
    AccessibilityNodeInfoCompat toFocus =
            FocusFinder.findLastFocusableDescendant(root,
                mAccessibilityService);

    try {
        if (toFocus == null) {
            if (AccessibilityNodeInfoUtils.shouldFocusNode(
                    mAccessibilityService, root)) {
                root = null;
                toFocus = root;
            } else {
                return false;
            }
        }

        if (toFocus.isAccessibilityFocused()) {
            brailleFocusedNode();
            return true;
        }

        return toFocus.performAction(
            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, toFocus);
    }
}
 
源代码5 项目: stetho   文件: AccessibilityNodeInfoWrapper.java
public static boolean getIsAccessibilityFocused(View view) {
  AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
  boolean isAccessibilityFocused = node.isAccessibilityFocused();
  node.recycle();

  return isAccessibilityFocused;
}
 
源代码6 项目: brailleback   文件: TreeDebug.java
/**
 * Gets a description of the properties of a node.
 */
public static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());

    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().toString().trim());
    }

    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription().toString().trim());
    }

    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfoCompat.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();
}