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

Commit 0973d5b1 authored by Ben Kwa's avatar Ben Kwa Committed by Android (Google) Code Review
Browse files

Merge "Introduce ChromeOS-style keyboard navigation."

parents 0816fcfd 1c9f9222
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -16,11 +16,14 @@

<!-- CoordinatorLayout is necessary for various components (e.g. Snackbars, and
     floating action buttons) to operate correctly. -->
<!-- focusableInTouchMode is set in order to force key events to go to the activity's global key
     callback, which is necessary for proper event routing. See BaseActivity.onKeyDown. -->
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/coordinator_layout">
    android:id="@+id/coordinator_layout"
    android:focusableInTouchMode="true">

    <LinearLayout
        android:layout_width="match_parent"
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:id="@+id/dir_list"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
+2 −2
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
     limitations under the License.
-->

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
<com.android.documentsui.RootsList xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/roots_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="8dp"
+4 −1
Original line number Diff line number Diff line
@@ -16,11 +16,14 @@

<!-- CoordinatorLayout is necessary for various components (e.g. Snackbars, and
     floating action buttons) to operate correctly. -->
<!-- focusableInTouchMode is set in order to force key events to go to the activity's global key 
     callback, which is necessary for proper event routing. See BaseActivity.onKeyDown. -->
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/coordinator_layout">
    android:id="@+id/coordinator_layout"
    android:focusableInTouchMode="true">

    <LinearLayout
        android:layout_width="match_parent"
+51 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.support.annotation.CallSuper;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Spinner;
@@ -83,6 +84,8 @@ public abstract class BaseActivity extends Activity
    // We use the time gap to figure out whether to close app or reopen the drawer.
    private long mDrawerLastFiddled;

    private boolean mNavDrawerHasFocus;

    public abstract void onDocumentPicked(DocumentInfo doc, @Nullable SiblingProvider siblings);
    public abstract void onDocumentsPicked(List<DocumentInfo> docs);

@@ -580,6 +583,54 @@ public abstract class BaseActivity extends Activity
        }
    }

    /**
     * Declare a global key handler to route key events when there isn't a specific focus view. This
     * covers the scenario where a user opens DocumentsUI and just starts typing.
     *
     * @param keyCode
     * @param event
     * @return
     */
    @CallSuper
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (Events.isNavigationKeyCode(keyCode)) {
            // Forward all unclaimed navigation keystrokes to the DirectoryFragment. This causes any
            // stray navigation keystrokes focus the content pane, which is probably what the user
            // is trying to do.
            DirectoryFragment df = DirectoryFragment.get(getFragmentManager());
            if (df != null) {
                df.requestFocus();
                return true;
            }
        } else if (keyCode == KeyEvent.KEYCODE_TAB) {
            toggleNavDrawerFocus();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * Toggles focus between the navigation drawer and the directory listing. If the drawer isn't
     * locked, open/close it as appropriate.
     */
    void toggleNavDrawerFocus() {
        if (mNavDrawerHasFocus) {
            mDrawer.setOpen(false);
            DirectoryFragment df = DirectoryFragment.get(getFragmentManager());
            if (df != null) {
                df.requestFocus();
            }
        } else {
            mDrawer.setOpen(true);
            RootsFragment rf = RootsFragment.get(getFragmentManager());
            if (rf != null) {
                rf.requestFocus();
            }
        }
        mNavDrawerHasFocus = !mNavDrawerHasFocus;
    }

    DocumentInfo getRootDocumentBlocking(RootInfo root) {
        try {
            final Uri uri = DocumentsContract.buildDocumentUri(
Loading