Skip to content

Commit 1434e29

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Check for null ViewRootImpl when saving accessibility focus in ListView." into jb-mr1-dev
2 parents 562af68 + 27093de commit 1434e29

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

core/java/android/widget/ListView.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.view.ViewDebug;
3939
import android.view.ViewGroup;
4040
import android.view.ViewParent;
41+
import android.view.ViewRootImpl;
4142
import android.view.accessibility.AccessibilityEvent;
4243
import android.view.accessibility.AccessibilityNodeInfo;
4344
import android.widget.RemoteViews.RemoteView;
@@ -1590,20 +1591,25 @@ protected void layoutChildren() {
15901591
}
15911592

15921593
// 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+
}
16071613
}
16081614
}
16091615
}

0 commit comments

Comments
 (0)