public static boolean shouldFocusNode ( Context context , AccessibilityNodeInfoCompat node ) { if ( node == null ) { return false ; } if ( ! isVisibleOrLegacy ( node ) ) { LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Don't focus, node is not visible" ) ; return false ; } if ( FILTER_ACCESSIBILITY_FOCUSABLE . accept ( context , node ) ) { // TODO: This may still result in focusing non-speaking nodes, but it // won't prevent unlabeled buttons from receiving focus. if ( node . getChildCount ( ) <= 0 ) { LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Focus, node is focusable and has no children" ) ; return true ; } else if ( isSpeakingNode ( context , node ) ) { LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Focus, node is focusable and has something to speak" ) ; return true ; } else { LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Don't focus, node is focusable but has nothing to speak" ) ; return false ; } } // If this node has no focusable ancestors, but it still has text, // then it should receive focus from navigation and be read aloud. if ( ! hasMatchingAncestor ( context , node , FILTER_ACCESSIBILITY_FOCUSABLE ) && hasText ( node ) ) { LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Focus, node has text and no focusable ancestors" ) ; return true ; } LogUtils . log ( AccessibilityNodeInfoUtils . class , Log . VERBOSE , "Don't focus, failed all focusability tests" ) ; return false ; }
Returns whether a node should receive accessibility focus from navigation . This method should never be called recursively since it traverses up the parent hierarchy on every call .