From 86bf12397bd0073f0acee9bb1c8b4099eb40b31f Mon Sep 17 00:00:00 2001 From: Ben Kwa Date: Wed, 17 Feb 2016 14:08:52 -0800 Subject: [PATCH] Fix focus issues on RV. Don't set focusable=false - that's the wrong thing to do, per Yigit. For now, just temporarily make the RV unfocusable while performing the focus search for kb navigation. BUG=27221751 Change-Id: I37ed77eb2aecf522a85c8a7c181e89c0bf73765d --- .../com/android/documentsui/dirlist/DirectoryFragment.java | 5 ----- .../src/com/android/documentsui/dirlist/FocusManager.java | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java index f8735b2f99a19..46ae67fc8d830 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -193,11 +193,6 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi mRecView.setItemAnimator(new DirectoryItemAnimator(getActivity())); - // Make the RecyclerView unfocusable. This is needed in order for the focus search code in - // FocusManager to work correctly. Setting android:focusable=false in the layout xml doesn't - // work, for some reason. - mRecView.setFocusable(false); - // TODO: Add a divider between views (which might use RecyclerView.ItemDecoration). if (DEBUG_ENABLE_DND) { setupDragAndDropOnDirectoryView(mRecView); diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java index 93ec8426e74f6..e90a4475d5d56 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java @@ -158,7 +158,14 @@ class FocusManager implements View.OnFocusChangeListener { } if (searchDir != -1) { + // Focus search behaves badly if the parent RecyclerView is focused. However, focusable + // shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after + // events that cause a UI rebuild (like rotating the device). Compromise: turn focusable + // off while performing the focus search. + // TODO: Revisit this when RV focus issues are resolved. + mView.setFocusable(false); View targetView = view.focusSearch(searchDir); + mView.setFocusable(true); // TargetView can be null, for example, if the user pressed at the bottom // of the list. if (targetView != null) {