|
38 | 38 | import android.view.ViewDebug; |
39 | 39 | import android.view.ViewGroup; |
40 | 40 | import android.view.ViewParent; |
| 41 | +import android.view.ViewRootImpl; |
41 | 42 | import android.view.accessibility.AccessibilityEvent; |
42 | 43 | import android.view.accessibility.AccessibilityNodeInfo; |
43 | 44 | import android.widget.RemoteViews.RemoteView; |
@@ -1590,20 +1591,25 @@ protected void layoutChildren() { |
1590 | 1591 | } |
1591 | 1592 |
|
1592 | 1593 | // Remember which child, if any, had accessibility focus. |
1593 | | - final View accessFocusedView = getViewRootImpl().getAccessibilityFocusedHost(); |
1594 | | - if (accessFocusedView != null) { |
1595 | | - final View accessFocusedChild = findAccessibilityFocusedChild(accessFocusedView); |
1596 | | - if (accessFocusedChild != null) { |
1597 | | - if (!dataChanged || isDirectChildHeaderOrFooter(accessFocusedChild)) { |
1598 | | - // If the views won't be changing, try to maintain focus |
1599 | | - // on the current view host and (if applicable) its |
1600 | | - // virtual view. |
1601 | | - accessibilityFocusLayoutRestoreView = accessFocusedView; |
1602 | | - accessibilityFocusLayoutRestoreNode = getViewRootImpl() |
1603 | | - .getAccessibilityFocusedVirtualView(); |
1604 | | - } else { |
1605 | | - // Otherwise, try to maintain focus at the same position. |
1606 | | - accessibilityFocusPosition = getPositionForView(accessFocusedChild); |
| 1594 | + final ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 1595 | + if (viewRootImpl != null) { |
| 1596 | + final View accessFocusedView = viewRootImpl.getAccessibilityFocusedHost(); |
| 1597 | + if (accessFocusedView != null) { |
| 1598 | + final View accessFocusedChild = findAccessibilityFocusedChild( |
| 1599 | + accessFocusedView); |
| 1600 | + if (accessFocusedChild != null) { |
| 1601 | + if (!dataChanged || isDirectChildHeaderOrFooter(accessFocusedChild)) { |
| 1602 | + // If the views won't be changing, try to maintain |
| 1603 | + // focus on the current view host and (if |
| 1604 | + // applicable) its virtual view. |
| 1605 | + accessibilityFocusLayoutRestoreView = accessFocusedView; |
| 1606 | + accessibilityFocusLayoutRestoreNode = viewRootImpl |
| 1607 | + .getAccessibilityFocusedVirtualView(); |
| 1608 | + } else { |
| 1609 | + // Otherwise, try to maintain focus at the same |
| 1610 | + // position. |
| 1611 | + accessibilityFocusPosition = getPositionForView(accessFocusedChild); |
| 1612 | + } |
1607 | 1613 | } |
1608 | 1614 | } |
1609 | 1615 | } |
|
0 commit comments