Loading packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +5 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,11 @@ 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); Loading packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java +31 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.documentsui.dirlist; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.KeyEvent; Loading @@ -32,14 +32,14 @@ class FocusManager implements View.OnFocusChangeListener { private RecyclerView mView; private RecyclerView.Adapter<?> mAdapter; private LinearLayoutManager mLayout; private GridLayoutManager mLayout; private int mLastFocusPosition = RecyclerView.NO_POSITION; public FocusManager(RecyclerView view) { mView = view; mAdapter = view.getAdapter(); mLayout = (LinearLayoutManager) view.getLayoutManager(); mLayout = (GridLayoutManager) view.getLayoutManager(); } /** Loading Loading @@ -134,13 +134,28 @@ class FocusManager implements View.OnFocusChangeListener { case KeyEvent.KEYCODE_DPAD_DOWN: searchDir = View.FOCUS_DOWN; break; } if (inGridMode()) { int currentPosition = mView.getChildAdapterPosition(view); // Left and right arrow keys only work in grid mode. switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: searchDir = View.FOCUS_LEFT; if (currentPosition > 0) { // Stop backward focus search at the first item, otherwise focus will wrap // around to the last visible item. searchDir = View.FOCUS_BACKWARD; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: searchDir = View.FOCUS_RIGHT; if (currentPosition < mAdapter.getItemCount() - 1) { // Stop forward focus search at the last item, otherwise focus will wrap // around to the first visible item. searchDir = View.FOCUS_FORWARD; } break; } } if (searchDir != -1) { View targetView = view.focusSearch(searchDir); Loading Loading @@ -238,4 +253,11 @@ class FocusManager implements View.OnFocusChangeListener { }); } } /** * @return Whether the layout manager is currently in a grid-configuration. */ private boolean inGridMode() { return mLayout.getSpanCount() > 1; } } Loading
packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +5 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,11 @@ 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); Loading
packages/DocumentsUI/src/com/android/documentsui/dirlist/FocusManager.java +31 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.documentsui.dirlist; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.KeyEvent; Loading @@ -32,14 +32,14 @@ class FocusManager implements View.OnFocusChangeListener { private RecyclerView mView; private RecyclerView.Adapter<?> mAdapter; private LinearLayoutManager mLayout; private GridLayoutManager mLayout; private int mLastFocusPosition = RecyclerView.NO_POSITION; public FocusManager(RecyclerView view) { mView = view; mAdapter = view.getAdapter(); mLayout = (LinearLayoutManager) view.getLayoutManager(); mLayout = (GridLayoutManager) view.getLayoutManager(); } /** Loading Loading @@ -134,13 +134,28 @@ class FocusManager implements View.OnFocusChangeListener { case KeyEvent.KEYCODE_DPAD_DOWN: searchDir = View.FOCUS_DOWN; break; } if (inGridMode()) { int currentPosition = mView.getChildAdapterPosition(view); // Left and right arrow keys only work in grid mode. switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: searchDir = View.FOCUS_LEFT; if (currentPosition > 0) { // Stop backward focus search at the first item, otherwise focus will wrap // around to the last visible item. searchDir = View.FOCUS_BACKWARD; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: searchDir = View.FOCUS_RIGHT; if (currentPosition < mAdapter.getItemCount() - 1) { // Stop forward focus search at the last item, otherwise focus will wrap // around to the first visible item. searchDir = View.FOCUS_FORWARD; } break; } } if (searchDir != -1) { View targetView = view.focusSearch(searchDir); Loading Loading @@ -238,4 +253,11 @@ class FocusManager implements View.OnFocusChangeListener { }); } } /** * @return Whether the layout manager is currently in a grid-configuration. */ private boolean inGridMode() { return mLayout.getSpanCount() > 1; } }