List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat setParent
public void setParent(View parent)
From source file:com.yyl.inputmethod.accessibility.AccessibilityEntityProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>//from w ww. j a v a 2 s . com * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.mKeys; for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); rootInfo.addChild(mKeyboardView, childVirtualViewId); } return rootInfo; } // Find the view that corresponds to the given id. final Key key = mVirtualViewIdToKey.get(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.mHitBox; // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setBoundsInScreen(boundsInScreen); info.setEnabled(true); info.setVisibleToUser(true); if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>//from w w w.ja va 2 s .c o m * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.getKeys(); for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); rootInfo.addChild(mKeyboardView, childVirtualViewId); } return rootInfo; } // Find the view that corresponds to the given id. final Key key = mVirtualViewIdToKey.get(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.getHitBox(); // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setBoundsInScreen(boundsInScreen); info.setEnabled(true); info.setVisibleToUser(true); if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>// w w w. j a va 2s. co m * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); updateParentLocation(); // Add the virtual children of the root View. final List<Key> sortedKeys = mKeyboard.getSortedKeys(); final int size = sortedKeys.size(); for (int index = 0; index < size; index++) { final Key key = sortedKeys.get(index); if (key.isSpacer()) { continue; } // Use an index of the sorted keys list as a virtual view id. rootInfo.addChild(mKeyboardView, index); } return rootInfo; } // Find the key that corresponds to the given virtual view id. final Key key = getKeyOf(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.getHitBox(); // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setEnabled(key.isEnabled()); info.setVisibleToUser(true); // Don't add ACTION_CLICK and ACTION_LONG_CLOCK actions while hovering on the key. // See {@link #onHoverEnterTo(Key)} and {@link #onHoverExitFrom(Key)}. if (virtualViewId != mHoveringNodeId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); if (key.isLongPressEnabled()) { info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK); } } if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.android.utils.ExploreByTouchHelper.java
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. *//*from w ww. j av a 2s . com*/ 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<>(); 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; }
From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. *///w w w . j a v a 2 s .c o m 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; }
From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java
private AccessibilityNodeInfoCompat populateNodeForItemInternal(T item, AccessibilityNodeInfoCompat node) { final int virtualDescendantId = getIdForItem(item); // Ensure the client has good defaults. node.setEnabled(true);/*from www . j a va 2 s .co m*/ // Allow the client to populate the node. populateNodeForItem(item, node); if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) { throw new RuntimeException("You must add text or a content description in populateNodeForItem()"); } // Don't allow the client to override these properties. node.setPackageName(mParentView.getContext().getPackageName()); node.setClassName(item.getClass().getName()); node.setParent(mParentView); node.setSource(mParentView, virtualDescendantId); if (mFocusedItemId == virtualDescendantId) { node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("You must set parent bounds in populateNodeForItem()"); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mParentView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }
From source file:com.deange.datetimepicker.TouchExplorationHelper.java
private AccessibilityNodeInfoCompat populateNodeForItemInternal(T item, AccessibilityNodeInfoCompat node) { final int virtualDescendantId = getIdForItem(item); // Ensure the client has good defaults. node.setEnabled(true);/*from www . j a v a 2 s . c om*/ // Allow the client to populate the node. populateNodeForItem(item, node); if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) { throw new RuntimeException("You must add text or a content description in populateNodeForItem()"); } // Don't allow the client to override these properties. node.setPackageName(mParentView.getContext().getPackageName()); node.setClassName(item.getClass().getName()); node.setParent(mParentView); node.setSource(mParentView, virtualDescendantId); if (mFocusedItemId == virtualDescendantId) { node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } node.getBoundsInParent(mTempParentRect); if (mTempParentRect.isEmpty()) { throw new RuntimeException("You must set parent bounds in populateNodeForItem()"); } // Set the visibility based on the parent bound. if (intersectVisibleToUser(mTempParentRect)) { node.setVisibleToUser(true); node.setBoundsInParent(mTempParentRect); } // Calculate screen-relative bound. mParentView.getLocationOnScreen(mTempGlobalRect); final int offsetX = mTempGlobalRect[0]; final int offsetY = mTempGlobalRect[1]; mTempScreenRect.set(mTempParentRect); mTempScreenRect.offset(offsetX, offsetY); node.setBoundsInScreen(mTempScreenRect); return node; }
From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. *///from w w w .j av a2 s . co m 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 = mHost.getParent(); 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; }
From source file:com.android.utils.ExploreByTouchHelper.java
/** * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the * parent view populated with its virtual descendants. * * @return An {@link AccessibilityNodeInfoCompat} for the parent view. */// ww w . j a v a2 s . c o m 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; }
From source file:com.android.inputmethod.accessibility.AccessibilityEntityProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>//from w w w . j a v a2 s.co m * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual * descendant or the host View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) { AccessibilityNodeInfoCompat info = null; if (virtualViewId == UNDEFINED) { return null; } else if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. info = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.mKeys; for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); info.addChild(mKeyboardView, childVirtualViewId); } } else { // Find the view that corresponds to the given id. final Key key = mVirtualViewIdToKey.get(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.mHitBox; // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with // information about the virtual view. info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setBoundsInScreen(boundsInScreen); info.setEnabled(true); info.setVisibleToUser(true); if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } } return info; }