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

Commit 75b7b903 authored by Ben Lin's avatar Ben Lin
Browse files

Let focused item also act as a starting anchor for range selection.

Bug: 31991343
Change-Id: Id59cc99a61550cd4a13feb508f13889a8598a3c9
parent 2db2ede5
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ public abstract class BaseActivity<T extends ActionHandler>
    protected MessageBuilder mMessages;
    protected DrawerController mDrawer;
    protected NavigationViewManager mNavigator;
    protected FocusManager mFocusManager;
    protected SortController mSortController;

    protected T mActions;
@@ -165,10 +164,8 @@ public abstract class BaseActivity<T extends ActionHandler>
    public abstract ActionModeController getActionModeController(
            SelectionDetails selectionDetails, EventHandler<MenuItem> menuItemClicker, View view);

    public final FocusManager getFocusManager(RecyclerView view, Model model) {
        assert(mFocusManager != null);
        return mFocusManager.reset(view, model);
    }

    public abstract FocusManager getFocusManager(RecyclerView view, Model model);

    public final MessageBuilder getMessages() {
        assert(mMessages != null);
@@ -190,7 +187,6 @@ public abstract class BaseActivity<T extends ActionHandler>
        setContentView(mLayoutId);

        mState = getState(icicle);
        mFocusManager = new FocusManager(getColor(R.color.accent_dark));
        mDrawer = DrawerController.create(this, getActivityConfig());
        Metrics.logActivityLaunch(this, mState, intent);

+24 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui;

import static com.android.documentsui.base.DocumentInfo.getCursorString;
import static com.android.documentsui.base.Shared.DEBUG;

import android.annotation.ColorRes;
import android.annotation.Nullable;
@@ -45,6 +46,7 @@ import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.dirlist.FocusHandler;
import com.android.documentsui.dirlist.Model;
import com.android.documentsui.dirlist.Model.Update;
import com.android.documentsui.selection.SelectionManager;

import java.util.ArrayList;
import java.util.List;
@@ -59,8 +61,10 @@ public final class FocusManager implements FocusHandler {

    private final ContentScope mScope = new ContentScope();
    private final TitleSearchHelper mSearchHelper;
    private final SelectionManager mSelectionMgr;

    public FocusManager(@ColorRes int color) {
    public FocusManager(@ColorRes int color, SelectionManager selectionMgr) {
        mSelectionMgr = selectionMgr;
        mSearchHelper = new TitleSearchHelper(color);
    }

@@ -94,19 +98,24 @@ public final class FocusManager implements FocusHandler {
    }

    @Override
    public void restoreLastFocus() {
    public boolean requestFocus() {
        if (mScope.adapter.getItemCount() == 0) {
            // Nothing to focus.
            return;
            if (DEBUG) Log.v(TAG, "Nothing to focus.");
            return false;
        }

        if (mScope.lastFocusPosition != RecyclerView.NO_POSITION) {
            // The system takes care of situations when a view is no longer on screen, etc,
            focusItem(mScope.lastFocusPosition);
        } else {
            // Focus the first visible item
            focusItem(mScope.layout.findFirstVisibleItemPosition());
        // If there's a selection going on, we don't want to grant user the ability to focus
        // on any individual item to prevent ambiguity in operations (Cut selection vs. Cut focused
        // item)
        if (mSelectionMgr.hasSelection()) {
            if (DEBUG) Log.v(TAG, "Existing selection found. No focus will be done.");
            return false;
        }

        final int focusPos = (mScope.lastFocusPosition != RecyclerView.NO_POSITION)
                ? mScope.lastFocusPosition : mScope.layout.findFirstVisibleItemPosition();
        focusItem(focusPos);
        return true;
    }

    /*
@@ -146,6 +155,11 @@ public final class FocusManager implements FocusHandler {
        return mScope.lastFocusPosition;
    }

    @Override
    public boolean hasFocusedItem() {
        return mScope.lastFocusPosition != RecyclerView.NO_POSITION;
    }

    @Override
    public @Nullable String getFocusModelId() {
        if (mScope.lastFocusPosition != RecyclerView.NO_POSITION) {
+1 −5
Original line number Diff line number Diff line
@@ -885,11 +885,7 @@ public class DirectoryFragment extends Fragment
     * Attempts to restore focus on the directory listing.
     */
    public boolean requestFocus() {
        if (mSelectionMgr.hasSelection()) {
            return false;
        }
        mFocusManager.restoreLastFocus();
        return true;
        return mFocusManager.requestFocus();
    }

    private void setupDragAndDropOnDocumentView(View view, Cursor cursor) {
+8 −2
Original line number Diff line number Diff line
@@ -44,15 +44,21 @@ public interface FocusHandler extends View.OnFocusChangeListener {
    void focusDocument(String modelId);

    /**
     * Requests focus on the item that last had focus. Scrolls to that item if necessary.
     * Requests focus on the item that last had focus. Scrolls to that item if necessary. If focus
     * is unsuccessful, return false.
     */
    void restoreLastFocus();
    boolean requestFocus();

    /**
     * @return The adapter position of the last focused item.
     */
    int getFocusPosition();

    /**
     * @return True if there is currently an item in focus, false otherwise.
     */
    boolean hasFocusedItem();

    /**
     * @return The modelId of the last focused item. If no item is focused, this should return null.
     */
+7 −1
Original line number Diff line number Diff line
@@ -375,8 +375,14 @@ public final class UserInputHandler<T extends InputEvent>
                return false;
            }

            if (mFocusHandler.hasFocusedItem() && event.isShiftKeyDown()) {
                mSelectionMgr.formNewSelectionRange(mFocusHandler.getFocusPosition(),
                        doc.getAdapterPosition());
                return true;
            } else {
                return selectDocument(doc);
            }
        }

        boolean onDoubleTap(T event) {
            if (DEBUG) Log.v(MTAG, "Delegated onDoubleTap event.");
Loading