Java Code Examples for android.support.v4.view.ViewCompat#onInitializeAccessibilityNodeInfo()
The following examples show how to use
android.support.v4.view.ViewCompat#onInitializeAccessibilityNodeInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExploreByTouchHelper.java From brailleback with Apache License 2.0 | 6 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. */ private AccessibilityNodeInfoCompat getNodeForRoot() { // The root node is identical to the parent node, except that it is a // child of the parent view and is populated with virtual descendants. final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mHost); ViewCompat.onInitializeAccessibilityNodeInfo(mHost, node); // Add the virtual descendants. final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>(); getVisibleVirtualViewIds(virtualViewIds); for (Integer virtualViewId : virtualViewIds) { node.addChild(mHost, virtualViewId); } // Set up the node as a child of the parent. node.setParent(mHost); node.setSource(mHost, ROOT_ID); return node; }
Example 2
Source File: ExploreByTouchHelper.java From letv with Apache License 2.0 | 5 votes |
private AccessibilityNodeInfoCompat createNodeForHost() { AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(this.mView); ViewCompat.onInitializeAccessibilityNodeInfo(this.mView, node); onPopulateNodeForHost(node); LinkedList<Integer> virtualViewIds = new LinkedList(); getVisibleVirtualViews(virtualViewIds); Iterator i$ = virtualViewIds.iterator(); while (i$.hasNext()) { node.addChild(this.mView, ((Integer) i$.next()).intValue()); } return node; }
Example 3
Source File: ExploreByTouchHelper.java From brailleback with Apache License 2.0 | 5 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. */ private AccessibilityNodeInfoCompat getNodeForHost() { // Since we don't want the parent to be focusable, but we can't remove // actions from a node, copy over the necessary fields. final AccessibilityNodeInfoCompat result = AccessibilityNodeInfoCompat.obtain(mHost); final AccessibilityNodeInfoCompat source = AccessibilityNodeInfoCompat.obtain(mHost); ViewCompat.onInitializeAccessibilityNodeInfo(mHost, source); // Copy over parent and screen bounds. source.getBoundsInParent(mTempParentRect); source.getBoundsInScreen(mTempScreenRect); result.setBoundsInParent(mTempParentRect); result.setBoundsInScreen(mTempScreenRect); // Set up the parent view, if applicable. final ViewParent parent = ViewCompat.getParentForAccessibility(mHost); if (parent instanceof View) { result.setParent((View) parent); } // Populate the minimum required fields. result.setVisibleToUser(source.isVisibleToUser()); result.setPackageName(source.getPackageName()); result.setClassName(source.getClassName()); // Add the fake root node. result.addChild(mHost, ROOT_ID); return result; }
Example 4
Source File: AccessibilityUtil.java From stetho with MIT License | 5 votes |
/** * Determines if the supplied {@link View} and {@link AccessibilityNodeInfoCompat} has any * children which are not independently accessibility focusable and also have a spoken * description. * <p> * NOTE: Accessibility services will include these children's descriptions in the closest * focusable ancestor. * * @param view The {@link View} to evaluate * @param node The {@link AccessibilityNodeInfoCompat} to evaluate * @return {@code true} if it has any non-actionable speaking descendants within its subtree */ public static boolean hasNonActionableSpeakingDescendants( @Nullable AccessibilityNodeInfoCompat node, @Nullable View view) { if (node == null || view == null || !(view instanceof ViewGroup)) { return false; } ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { View childView = viewGroup.getChildAt(i); if (childView == null) { continue; } AccessibilityNodeInfoCompat childNode = AccessibilityNodeInfoCompat.obtain(); try { ViewCompat.onInitializeAccessibilityNodeInfo(childView, childNode); if (isAccessibilityFocusable(childNode, childView)) { continue; } if (isSpeakingNode(childNode, childView)) { return true; } } finally { childNode.recycle(); } } return false; }
Example 5
Source File: AccessibilityUtil.java From stetho with MIT License | 5 votes |
/** * Determines if any of the provided {@link View}'s and {@link AccessibilityNodeInfoCompat}'s * ancestors can receive accessibility focus * * @param view The {@link View} to evaluate * @param node The {@link AccessibilityNodeInfoCompat} to evaluate * @return {@code true} if an ancestor of may receive accessibility focus */ public static boolean hasFocusableAncestor( @Nullable AccessibilityNodeInfoCompat node, @Nullable View view) { if (node == null || view == null) { return false; } ViewParent parentView = ViewCompat.getParentForAccessibility(view); if (!(parentView instanceof View)) { return false; } AccessibilityNodeInfoCompat parentNode = AccessibilityNodeInfoCompat.obtain(); try { ViewCompat.onInitializeAccessibilityNodeInfo((View) parentView, parentNode); if (parentNode == null) { return false; } if (isAccessibilityFocusable(parentNode, (View) parentView)) { return true; } if (hasFocusableAncestor(parentNode, (View) parentView)) { return true; } } finally { parentNode.recycle(); } return false; }
Example 6
Source File: ExploreByTouchHelper.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
private AccessibilityNodeInfoCompat b() { AccessibilityNodeInfoCompat accessibilitynodeinfocompat = AccessibilityNodeInfoCompat.obtain(h); ViewCompat.onInitializeAccessibilityNodeInfo(h, accessibilitynodeinfocompat); LinkedList linkedlist = new LinkedList(); getVisibleVirtualViews(linkedlist); Integer integer; for (Iterator iterator = linkedlist.iterator(); iterator.hasNext(); accessibilitynodeinfocompat.addChild(h, integer.intValue())) { integer = (Integer)iterator.next(); } return accessibilitynodeinfocompat; }
Example 7
Source File: ExploreByTouchHelper.java From adt-leanback-support with Apache License 2.0 | 5 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * host view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent node. */ private AccessibilityNodeInfoCompat createNodeForHost() { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mView); ViewCompat.onInitializeAccessibilityNodeInfo(mView, node); // Add the virtual descendants. final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>(); getVisibleVirtualViews(virtualViewIds); for (Integer childVirtualViewId : virtualViewIds) { node.addChild(mView, childVirtualViewId); } return node; }
Example 8
Source File: ExploreByTouchHelper.java From android-recipes-app with Apache License 2.0 | 5 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * host view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent node. */ private AccessibilityNodeInfoCompat createNodeForHost() { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mView); ViewCompat.onInitializeAccessibilityNodeInfo(mView, node); // Add the virtual descendants. final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>(); getVisibleVirtualViews(virtualViewIds); for (Integer childVirtualViewId : virtualViewIds) { node.addChild(mView, childVirtualViewId); } return node; }
Example 9
Source File: TouchExplorationHelper.java From DateTimepicker with Apache License 2.0 | 5 votes |
private AccessibilityNodeInfoCompat getNodeForParent() { final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(mParentView); ViewCompat.onInitializeAccessibilityNodeInfo(mParentView, info); final LinkedList<T> items = new LinkedList<T>(); getVisibleItems(items); for (T item : items) { final int virtualDescendantId = getIdForItem(item); info.addChild(mParentView, virtualDescendantId); } return info; }
Example 10
Source File: ExploreByTouchHelper.java From V.FlyoutTest with MIT License | 5 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * host view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent node. */ private AccessibilityNodeInfoCompat createNodeForHost() { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mView); ViewCompat.onInitializeAccessibilityNodeInfo(mView, node); // Add the virtual descendants. final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>(); getVisibleVirtualViews(virtualViewIds); for (Integer childVirtualViewId : virtualViewIds) { node.addChild(mView, childVirtualViewId); } return node; }
Example 11
Source File: ExploreByTouchHelper.java From guideshow with MIT License | 5 votes |
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * host view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent node. */ private AccessibilityNodeInfoCompat createNodeForHost() { final AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(mView); ViewCompat.onInitializeAccessibilityNodeInfo(mView, node); // Add the virtual descendants. final LinkedList<Integer> virtualViewIds = new LinkedList<Integer>(); getVisibleVirtualViews(virtualViewIds); for (Integer childVirtualViewId : virtualViewIds) { node.addChild(mView, childVirtualViewId); } return node; }
Example 12
Source File: AccessibilityNodeInfoWrapper.java From stetho with MIT License | 4 votes |
public static AccessibilityNodeInfoCompat createNodeInfoFromView(View view) { AccessibilityNodeInfoCompat nodeInfo = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(view, nodeInfo); return nodeInfo; }
Example 13
Source File: AccessibilityNodeInfoWrapper.java From stetho with MIT License | 4 votes |
@Nullable public static CharSequence getDescription(View view) { AccessibilityNodeInfoCompat node = createNodeInfoFromView(view); try { CharSequence contentDescription = node.getContentDescription(); CharSequence nodeText = node.getText(); boolean hasNodeText = !TextUtils.isEmpty(nodeText); boolean isEditText = view instanceof EditText; // EditText's prioritize their own text content over a contentDescription if (!TextUtils.isEmpty(contentDescription) && (!isEditText || !hasNodeText)) { return contentDescription; } if (hasNodeText) { return nodeText; } // If there are child views and no contentDescription the text of all non-focusable children, // comma separated, becomes the description. if (view instanceof ViewGroup) { final StringBuilder concatChildDescription = new StringBuilder(); final String separator = ", "; ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { final View child = viewGroup.getChildAt(i); AccessibilityNodeInfoCompat childNodeInfo = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(child, childNodeInfo); CharSequence childNodeDescription = null; if (AccessibilityUtil.isSpeakingNode(childNodeInfo, child) && !AccessibilityUtil.isAccessibilityFocusable(childNodeInfo, child)) { childNodeDescription = getDescription(child); } if (!TextUtils.isEmpty(childNodeDescription)) { if (concatChildDescription.length() > 0) { concatChildDescription.append(separator); } concatChildDescription.append(childNodeDescription); } childNodeInfo.recycle(); } return concatChildDescription.length() > 0 ? concatChildDescription.toString() : null; } return null; } finally { node.recycle(); } }