From b53c5f6b6f84518145c5cbfd3cc1729758fbc7c0 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Fri, 15 Mar 2013 15:50:37 -0700 Subject: [PATCH] Remember which list child has A11y focus BEFORE clearing A11y focus. Bug: 8332399 Change-Id: I0293efe5cef4a011a584e62fc4a64cde7d354efe --- core/java/android/widget/ListView.java | 50 +++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 69e3177e74b11..7c40a64944426 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -1550,6 +1550,32 @@ public class ListView extends AbsListView { setSelectedPositionInt(mNextSelectedPosition); + // Remember which child, if any, had accessibility focus. This must + // occur before recycling any views, since that will clear + // accessibility focus. + final ViewRootImpl viewRootImpl = getViewRootImpl(); + if (viewRootImpl != null) { + final View accessFocusedView = viewRootImpl.getAccessibilityFocusedHost(); + if (accessFocusedView != null) { + final View accessFocusedChild = findAccessibilityFocusedChild( + accessFocusedView); + if (accessFocusedChild != null) { + if (!dataChanged || isDirectChildHeaderOrFooter(accessFocusedChild)) { + // If the views won't be changing, try to maintain + // focus on the current view host and (if + // applicable) its virtual view. + accessibilityFocusLayoutRestoreView = accessFocusedView; + accessibilityFocusLayoutRestoreNode = viewRootImpl + .getAccessibilityFocusedVirtualView(); + } else { + // Otherwise, try to maintain focus at the same + // position. + accessibilityFocusPosition = getPositionForView(accessFocusedChild); + } + } + } + } + // Pull all children into the RecycleBin. // These views will be reused if possible final int firstPosition = mFirstPosition; @@ -1590,30 +1616,6 @@ public class ListView extends AbsListView { requestFocus(); } - // Remember which child, if any, had accessibility focus. - final ViewRootImpl viewRootImpl = getViewRootImpl(); - if (viewRootImpl != null) { - final View accessFocusedView = viewRootImpl.getAccessibilityFocusedHost(); - if (accessFocusedView != null) { - final View accessFocusedChild = findAccessibilityFocusedChild( - accessFocusedView); - if (accessFocusedChild != null) { - if (!dataChanged || isDirectChildHeaderOrFooter(accessFocusedChild)) { - // If the views won't be changing, try to maintain - // focus on the current view host and (if - // applicable) its virtual view. - accessibilityFocusLayoutRestoreView = accessFocusedView; - accessibilityFocusLayoutRestoreNode = viewRootImpl - .getAccessibilityFocusedVirtualView(); - } else { - // Otherwise, try to maintain focus at the same - // position. - accessibilityFocusPosition = getPositionForView(accessFocusedChild); - } - } - } - } - // Clear out old views detachAllViewsFromParent(); recycleBin.removeSkippedScrap();