Java Code Examples for android.view.View#isImportantForAccessibility()

The following examples show how to use android.view.View#isImportantForAccessibility() . 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:    From letv with Apache License 2.0 4 votes vote down vote up
public static boolean isImportantForAccessibility(View view) {
    return view.isImportantForAccessibility();
Example 2
Source File:    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
/** See {@link View#isImportantForAccessibility()}. */
public static boolean isImportantForAccessibility(View view) {
  if (view == null) {
    return false;

    return view.isImportantForAccessibility();
    // Prior to Jelly Bean, all Views were considered important for accessibility.
    return true;
  } else {
    // On APIs between 16 and 21, we must piece together accessibility importance from the
    // available properties. We return false incorrectly for some cases where unretrievable
    // listeners prevent us from determining importance.

    // If the developer marked the view as explicitly not important, it isn't.
    int mode = view.getImportantForAccessibility();
      return false;

    // No parent view can be hiding us. (APIs 19 to 21)
    ViewParent parent = view.getParent();
    while (parent instanceof View) {
      if (((View) parent).getImportantForAccessibility()
        return false;
      parent = parent.getParent();

    // Interrogate the view's other properties to determine importance.
        || isActionableForAccessibility(view)
        || hasListenersForAccessibility(view)
        || (view.getAccessibilityNodeProvider() != null)
        || (ViewCompat.getAccessibilityLiveRegion(view)
            != ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE);
Example 3
Source File:    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
 * Sets the source to be a virtual descendant of the given <code>root</code>.
 * If <code>virtualDescendantId</code> equals to {@link View#NO_ID} the root
 * is set as the source.
 * <p>
 * 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>
 * @param root The root of the virtual subtree.
 * @param virtualDescendantId The id of the virtual descendant.
public void setSource(@Nullable View root, int virtualDescendantId) {
    boolean important = true;
    int rootViewId = AccessibilityNodeInfo.UNDEFINED_ITEM_ID;
    mSourceWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID;
    if (root != null) {
        important = root.isImportantForAccessibility();
        rootViewId = root.getAccessibilityViewId();
        mSourceWindowId = root.getAccessibilityWindowId();
    setBooleanProperty(PROPERTY_IMPORTANT_FOR_ACCESSIBILITY, important);
    mSourceNodeId = AccessibilityNodeInfo.makeNodeId(rootViewId, virtualDescendantId);