Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66310f65 authored by Ben Kwa's avatar Ben Kwa Committed by android-build-merger
Browse files

Make left- and right- arrow jump rows in grid mode.

am: d7211c85

* commit 'd7211c85':
  Make left- and right- arrow jump rows in grid mode.
parents 75535725 d7211c85
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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);
+31 −9
Original line number Diff line number Diff line
@@ -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;
@@ -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();
    }

    /**
@@ -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);
@@ -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;
    }
}