Java Code Examples for android.support.v4.view.ViewCompat#IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

The following examples show how to use android.support.v4.view.ViewCompat#IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS . 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: AccessibilityUtil.java    From stetho with MIT License 6 votes vote down vote up
/**
 * Returns whether the supplied {@link View} and {@link AccessibilityNodeInfoCompat} would
 * produce spoken feedback if it were accessibility focused.  NOTE: not all speaking nodes are
 * focusable.
 *
 * @param view The {@link View} to evaluate
 * @param node The {@link AccessibilityNodeInfoCompat} to evaluate
 * @return {@code true} if it meets the criterion for producing spoken feedback
 */
public static boolean isSpeakingNode(
    @Nullable AccessibilityNodeInfoCompat node,
    @Nullable View view) {
  if (node == null || view == null) {
    return false;
  }

  if (!node.isVisibleToUser()) {
    return false;
  }

  int important = ViewCompat.getImportantForAccessibility(view);
  if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS ||
      (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO &&
          node.getChildCount() <= 0)) {
    return false;
  }

  return node.isCheckable() || hasText(node) || hasNonActionableSpeakingDescendants(node, view);
}
 
Example 2
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
private static boolean includeChildForAccessibility(View child) {
    // If the child is not important for accessibility we make
    // sure this hides the entire subtree rooted at it as the
    // IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDATS is not
    // supported on older platforms but we want to hide the entire
    // content and not opened drawers if a drawer is opened.
    return ViewCompat.getImportantForAccessibility(child)
            != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
            && ViewCompat.getImportantForAccessibility(child)
            != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
}
 
Example 3
Source File: AccessibilityNodeInfoWrapper.java    From stetho with MIT License 5 votes vote down vote up
public static String getIgnoredReasons(View view) {
  int important = ViewCompat.getImportantForAccessibility(view);

  if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO) {
    return "View has importantForAccessibility set to 'NO'.";
  }

  if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
    return "View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
  }

  ViewParent parent = view.getParent();
  while (parent instanceof View) {
    if (ViewCompat.getImportantForAccessibility((View) parent)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
      return "An ancestor View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
    }
    parent = parent.getParent();
  }

  AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
  try {
    if (!node.isVisibleToUser()) {
      return "View is not visible.";
    }

    if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
      return "View is actionable, but has no description.";
    }

    if (AccessibilityUtil.hasText(node)) {
      return "View is not actionable, and an ancestor View has co-opted its description.";
    }

    return "View is not actionable and has no description.";
  } finally {
    node.recycle();
  }
}
 
Example 4
Source File: DrawerLayout.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private static boolean includeChildForAccessibility(View child) {
    // If the child is not important for accessibility we make
    // sure this hides the entire subtree rooted at it as the
    // IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDATS is not
    // supported on older platforms but we want to hide the entire
    // content and not opened drawers if a drawer is opened.
    return ViewCompat.getImportantForAccessibility(child)
            != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                && ViewCompat.getImportantForAccessibility(child)
            != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
}
 
Example 5
Source File: MarginDrawerLayout.java    From something.apk with MIT License 5 votes vote down vote up
private void addChildrenForAccessibility(AccessibilityNodeInfoCompat info, ViewGroup v) {
    final int childCount = v.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = v.getChildAt(i);
        if (filter(child)) {
            continue;
        }

        // Adding children that are marked as not important for
        // accessibility will break the hierarchy, so we need to check
        // that value and re-parent views if necessary.
        final int importance = ViewCompat.getImportantForAccessibility(child);
        switch (importance) {
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS:
                // Always skip NO_HIDE views and their descendants.
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO:
                // Re-parent children of NO view groups, skip NO views.
                if (child instanceof ViewGroup) {
                    addChildrenForAccessibility(info, (ViewGroup) child);
                }
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO:
                // Force AUTO views to YES and add them.
                ViewCompat.setImportantForAccessibility(
                        child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES:
                info.addChild(child);
                break;
        }
    }
}
 
Example 6
Source File: DrawerLayout.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private void addChildrenForAccessibility(AccessibilityNodeInfoCompat info, ViewGroup v) {
    final int childCount = v.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = v.getChildAt(i);
        if (filter(child)) {
            continue;
        }

        // Adding children that are marked as not important for
        // accessibility will break the hierarchy, so we need to check
        // that value and re-parent views if necessary.
        final int importance = ViewCompat.getImportantForAccessibility(child);
        switch (importance) {
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS:
                // Always skip NO_HIDE views and their descendants.
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO:
                // Re-parent children of NO view groups, skip NO views.
                if (child instanceof ViewGroup) {
                    addChildrenForAccessibility(info, (ViewGroup) child);
                }
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO:
                // Force AUTO views to YES and add them.
                ViewCompat.setImportantForAccessibility(
                        child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES:
                info.addChild(child);
                break;
        }
    }
}
 
Example 7
Source File: DrawerLayout.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private void addChildrenForAccessibility(AccessibilityNodeInfoCompat info, ViewGroup v) {
    final int childCount = v.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = v.getChildAt(i);
        if (filter(child)) {
            continue;
        }

        // Adding children that are marked as not important for
        // accessibility will break the hierarchy, so we need to check
        // that value and re-parent views if necessary.
        final int importance = ViewCompat.getImportantForAccessibility(child);
        switch (importance) {
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS:
                // Always skip NO_HIDE views and their descendants.
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO:
                // Re-parent children of NO view groups, skip NO views.
                if (child instanceof ViewGroup) {
                    addChildrenForAccessibility(info, (ViewGroup) child);
                }
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO:
                // Force AUTO views to YES and add them.
                ViewCompat.setImportantForAccessibility(
                        child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES:
                info.addChild(child);
                break;
        }
    }
}
 
Example 8
Source File: DrawerLayout.java    From guideshow with MIT License 5 votes vote down vote up
private void addChildrenForAccessibility(AccessibilityNodeInfoCompat info, ViewGroup v) {
    final int childCount = v.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = v.getChildAt(i);
        if (filter(child)) {
            continue;
        }

        // Adding children that are marked as not important for
        // accessibility will break the hierarchy, so we need to check
        // that value and re-parent views if necessary.
        final int importance = ViewCompat.getImportantForAccessibility(child);
        switch (importance) {
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS:
                // Always skip NO_HIDE views and their descendants.
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO:
                // Re-parent children of NO view groups, skip NO views.
                if (child instanceof ViewGroup) {
                    addChildrenForAccessibility(info, (ViewGroup) child);
                }
                break;
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO:
                // Force AUTO views to YES and add them.
                ViewCompat.setImportantForAccessibility(
                        child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
            case ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES:
                info.addChild(child);
                break;
        }
    }
}
 
Example 9
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private static boolean includeChildForAccessibility(View child) {
  // If the child is not important for accessibility we make
  // sure this hides the entire subtree rooted at it as the
  // IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDATS is not
  // supported on older platforms but we want to hide the entire
  // content and not opened drawers if a drawer is opened.
  return ViewCompat.getImportantForAccessibility(child)
      != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
      && ViewCompat.getImportantForAccessibility(child)
      != ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
}
 
Example 10
Source File: AccessibilityNodeInfoWrapper.java    From stetho with MIT License 4 votes vote down vote up
public static boolean getIgnored(View view) {
  int important = ViewCompat.getImportantForAccessibility(view);
  if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO ||
      important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
    return true;
  }

  // Go all the way up the tree to make sure no parent has hidden its descendants
  ViewParent parent = view.getParent();
  while (parent instanceof View) {
    if (ViewCompat.getImportantForAccessibility((View) parent)
        == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
      return true;
    }
    parent = parent.getParent();
  }

  AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
  try {
    if (!node.isVisibleToUser()) {
      return true;
    }

    if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
      if (node.getChildCount() <= 0) {
        // Leaves that are accessibility focusable are never ignored, even if they don't have a
        // speakable description
        return false;
      } else if (AccessibilityUtil.isSpeakingNode(node, view)) {
        // Node is focusable and has something to speak
        return false;
      }

      // Node is focusable and has nothing to speak
      return true;
    }

    // If this node has no focusable ancestors, but it still has text,
    // then it should receive focus from navigation and be read aloud.
    if (!AccessibilityUtil.hasFocusableAncestor(node, view) && AccessibilityUtil.hasText(node)) {
      return false;
    }

    return true;
  } finally {
    node.recycle();
  }
}
 
Example 11
Source File: AppsCustomizePagedView.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
private void updateAccessibilityFlags() {
    int accessible = mState == State.NORMAL ?
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES :
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
    setImportantForAccessibility(accessible);
}
 
Example 12
Source File: Workspace.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
private void updateAccessibilityFlags() {
    int accessible = mState == State.NORMAL ?
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES :
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
    setImportantForAccessibility(accessible);
}