List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getChild
public AccessibilityNodeInfoCompat getChild(int index)
From source file:Main.java
private static AccessibilityNodeInfoCompat refreshFromChild(AccessibilityNodeInfoCompat node) { if (node.getChildCount() > 0) { AccessibilityNodeInfoCompat firstChild = node.getChild(0); if (firstChild != null) { AccessibilityNodeInfoCompat parent = firstChild.getParent(); firstChild.recycle();//from ww w . ja v a 2 s. co m if (node.equals(parent)) { return parent; } else { recycleNodes(parent); } } } return null; }
From source file:Main.java
private static AccessibilityNodeInfoCompat refreshFromParent(AccessibilityNodeInfoCompat node) { AccessibilityNodeInfoCompat parent = node.getParent(); if (parent != null) { try {/*from www . jav a2 s . co m*/ int childCount = parent.getChildCount(); for (int i = 0; i < childCount; ++i) { AccessibilityNodeInfoCompat child = parent.getChild(i); if (node.equals(child)) { return child; } recycleNodes(child); } } finally { parent.recycle(); } } return null; }
From source file:com.googlecode.eyesfree.brailleback.FocusFinder.java
private static AccessibilityNodeInfoCompat findFirstFocusableDescendantInternal( AccessibilityNodeInfoCompat root, Context context, HashSet<AccessibilityNodeInfoCompat> seenNodes) { for (int i = 0, end = root.getChildCount(); i < end; ++i) { AccessibilityNodeInfoCompat child = root.getChild(i); if (child == null) { continue; }//from w w w.j a va 2s.c o m if (AccessibilityNodeInfoUtils.shouldFocusNode(context, child)) { return child; } if (!seenNodes.add(child)) { LogUtils.log(FocusFinder.class, Log.ERROR, "Cycle in node tree"); child.recycle(); return null; } AccessibilityNodeInfoCompat n = findFirstFocusableDescendantInternal(child, context, seenNodes); if (n != null) { return n; } } return null; }
From source file:com.googlecode.eyesfree.brailleback.FocusFinder.java
private static AccessibilityNodeInfoCompat findLastFocusableDescendantInternal(AccessibilityNodeInfoCompat root, Context context, HashSet<AccessibilityNodeInfoCompat> seenNodes) { for (int end = root.getChildCount(), i = end - 1; i >= 0; --i) { AccessibilityNodeInfoCompat child = root.getChild(i); if (child == null) { continue; }/*from w ww. j ava2 s. c o m*/ AccessibilityNodeInfoCompat n = findLastFocusableDescendantInternal(child, context, seenNodes); if (n != null) { return n; } if (AccessibilityNodeInfoUtils.shouldFocusNode(context, child)) { return child; } if (!seenNodes.add(child)) { LogUtils.log(FocusFinder.class, Log.ERROR, "Cycle in node tree"); child.recycle(); return null; } } return null; }
From source file:com.android.talkback.eventprocessor.ProcessorScrollPosition.java
private static CharSequence getSelectedPageTitle(AccessibilityNodeInfo node) { // We need to refresh() after the scroll to get an accurate page title but we can only // do that on API 18+. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { return null; }//from w w w . ja v a2 s . co m if (node == null) { return null; } AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node); nodeCompat.refresh(); int numChildren = nodeCompat.getChildCount(); // Not the number of pages! CharSequence title = null; for (int i = 0; i < numChildren; ++i) { AccessibilityNodeInfoCompat child = nodeCompat.getChild(i); if (child != null) { try { if (child.isVisibleToUser()) { if (title == null) { // Try to roughly match RulePagerPage, which uses getNodeText // (but completely matching all the time is not critical). title = AccessibilityNodeInfoUtils.getNodeText(child); } else { // Multiple visible children, abort. return null; } } } finally { child.recycle(); } } } return title; }
From source file:com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckUtils.java
/** * Retrieve text for a node, which may include text from children of the node. This text is an * approximation of, but not always identical to, what TalkBack would speak for the node. One * difference is that there are no separators between the speakable text from different nodes. * * @param info The info whose text should be returned. * * @return Speakable text derived from the info and its children. Returns an empty string if there * is no such text, and {@code null} if {@code info == null}. *///w w w . ja va 2 s . c o m static CharSequence getSpeakableTextForInfo(AccessibilityNodeInfo info) { if (info == null) { return null; } /* getLabeledBy for API 17+ */ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { AccessibilityNodeInfo labeledBy = info.getLabeledBy(); if (labeledBy != null) { /* There could be a chain of labeledBy. Make sure it isn't a loop */ Set<AccessibilityNodeInfo> infosVisited = new HashSet<>(); infosVisited.add(info); infosVisited.add(labeledBy); AccessibilityNodeInfo endOfLabeledByChain = labeledBy.getLabeledBy(); while (endOfLabeledByChain != null) { if (infosVisited.contains(endOfLabeledByChain)) { infosVisited.remove(info); for (AccessibilityNodeInfo infoVisited : infosVisited) { infoVisited.recycle(); } return null; } infosVisited.add(endOfLabeledByChain); labeledBy = endOfLabeledByChain; endOfLabeledByChain = labeledBy.getLabeledBy(); } CharSequence labelText = getSpeakableTextForInfo(labeledBy); infosVisited.remove(info); for (AccessibilityNodeInfo infoVisited : infosVisited) { infoVisited.recycle(); } return labelText; } } AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(info); // TODO(caseburkhardt) Pull in TalkBack's actual logic CharSequence nodeText = AccessibilityNodeInfoUtils.getNodeText(compat); StringBuilder returnStringBuilder = new StringBuilder((nodeText == null) ? "" : nodeText); /* If this node has a contentDescription, it overrides anything in children */ if (TextUtils.isEmpty(compat.getContentDescription())) { for (int i = 0; i < compat.getChildCount(); ++i) { AccessibilityNodeInfoCompat child = compat.getChild(i); if (AccessibilityNodeInfoUtils.isVisibleOrLegacy(child) && !AccessibilityNodeInfoUtils.isActionableForAccessibility(child)) { returnStringBuilder.append(getSpeakableTextForInfo((AccessibilityNodeInfo) child.getInfo())); } } } return returnStringBuilder; }
From source file:com.android.utils.TreeDebug.java
private static void logNodeTree(AccessibilityNodeInfoCompat node, String indent, HashSet<AccessibilityNodeInfoCompat> seen) { if (!seen.add(node)) { LogUtils.log(TreeDebug.class, Log.VERBOSE, "Cycle: %d", node.hashCode()); return;//from w w w . jav a2s . c o m } // Include the hash code as a "poor man's" id, knowing that it // might not always be unique. LogUtils.log(TreeDebug.class, Log.VERBOSE, "%s(%d)%s", indent, node.hashCode(), nodeDebugDescription(node)); indent += " "; int childCount = node.getChildCount(); for (int i = 0; i < childCount; ++i) { AccessibilityNodeInfoCompat child = node.getChild(i); if (child == null) { LogUtils.log(TreeDebug.class, Log.VERBOSE, "%sCouldn't get child %d", indent, i); continue; } logNodeTree(child, indent, seen); } }
From source file:com.google.android.marvin.mytalkback.CursorGranularityManager.java
/** * Extract the child nodes from the given root and adds them to the supplied * list of nodes.//w ww . j a v a2 s . c o m * * @param root The root node. * @param nodes The list of child nodes. * @return The mask of supported all granularities supported by the root and * child nodes. */ private static int extractNavigableNodes(Context context, AccessibilityNodeInfoCompat root, ArrayList<AccessibilityNodeInfoCompat> nodes) { if (root == null) { return 0; } if (nodes != null) { nodes.add(AccessibilityNodeInfoCompat.obtain(root)); } int supportedGranularities = root.getMovementGranularities(); // Don pull children from nodes with content descriptions. if (!TextUtils.isEmpty(root.getContentDescription())) { return supportedGranularities; } final int childCount = root.getChildCount(); for (int i = 0; i < childCount; i++) { final AccessibilityNodeInfoCompat child = root.getChild(i); if (child == null) { continue; } child.performAction(AccessibilityNodeInfoCompat.ACTION_SET_SELECTION, null); // Only extract nodes that aren't reachable by traversal. if (!AccessibilityNodeInfoUtils.shouldFocusNode(context, child)) { supportedGranularities |= extractNavigableNodes(context, child, nodes); } child.recycle(); } return supportedGranularities; }
From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java
private static boolean hasNonActionableSpeakingChildren(Context context, AccessibilityNodeInfoCompat node) { final int childCount = node.getChildCount(); AccessibilityNodeInfoCompat child = null; // Has non-actionable, speaking children? for (int i = 0; i < childCount; i++) { try {/*w ww .jav a2 s. c o m*/ child = node.getChild(i); if (child == null) { LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Child %d is null, skipping it", i); continue; } // Ignore invisible nodes. if (!isVisibleOrLegacy(child)) { LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Child %d is invisible, skipping it", i); continue; } // Ignore focusable nodes. if (FILTER_ACCESSIBILITY_FOCUSABLE.accept(context, child)) { LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Child %d is focusable, skipping it", i); continue; } // Recursively check non-focusable child nodes. // TODO: Mutual recursion is probably not a good idea. if (isSpeakingNode(context, child)) { LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Does have actionable speaking children (child %d)", i); return true; } } finally { AccessibilityNodeInfoUtils.recycleNodes(child); } } LogUtils.log(AccessibilityNodeInfoUtils.class, Log.VERBOSE, "Does not have non-actionable speaking children"); return false; }
From source file:com.android.screenspeak.CursorGranularityManager.java
/** * Extract the child nodes from the given root and adds them to the supplied * list of nodes./*from w w w .jav a 2 s. c om*/ * * @param root The root node. * @param nodes The list of child nodes. * @return The mask of supported all granularities supported by the root and * child nodes. */ private static int extractNavigableNodes(AccessibilityNodeInfoCompat root, List<AccessibilityNodeInfoCompat> nodes, Set<AccessibilityNodeInfoCompat> visitedNodes) { if (root == null) { return 0; } AccessibilityNodeInfoCompat visitedNode = AccessibilityNodeInfoCompat.obtain(root); if (!visitedNodes.add(visitedNode)) { visitedNode.recycle(); return 0; } if (nodes != null) { nodes.add(AccessibilityNodeInfoCompat.obtain(root)); } int supportedGranularities = root.getMovementGranularities(); // Don pull children from nodes with content descriptions. if (!TextUtils.isEmpty(root.getContentDescription())) { return supportedGranularities; } final int childCount = root.getChildCount(); for (int i = 0; i < childCount; i++) { final AccessibilityNodeInfoCompat child = root.getChild(i); if (child == null) { continue; } PerformActionUtils.performAction(child, AccessibilityNodeInfoCompat.ACTION_SET_SELECTION, null); // Only extract nodes that aren't reachable by traversal. if (!AccessibilityNodeInfoUtils.shouldFocusNode(child)) { supportedGranularities |= extractNavigableNodes(child, nodes, visitedNodes); } child.recycle(); } return supportedGranularities; }