summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ben Lin <linben@google.com> 2017-01-27 11:41:26 -0800
committer Ben Lin <linben@google.com> 2017-02-27 18:40:40 -0800
commit340ab17f468789bb507daeae116cf7940ba84b03 (patch)
treeb0caea1fd6cafad599f0eb1937e7dfc7f72a1c9f
parente4ffd06b9e745b7a26188122670ac901116f4e17 (diff)
Fixing Keyboard Navigation to match spec.
Couple known problems still: - Tabs go to the search/sort/etc icons first, as opposed to the breadcrumb. - There's no "focus" indicator for the sort items. Test: Manually checked, works. Bug: 32411179 Bug: 34243462 Bug: 31995556 Change-Id: I39240c0bafee9236f5ea5b760eff437739074cd3
-rw-r--r--res/layout/fragment_roots.xml4
-rw-r--r--res/layout/navigation_breadcrumb_item.xml2
-rw-r--r--src/com/android/documentsui/FocusManager.java4
-rw-r--r--src/com/android/documentsui/HorizontalBreadcrumb.java18
-rw-r--r--src/com/android/documentsui/SharedInputHandler.java5
-rw-r--r--src/com/android/documentsui/files/FilesActivity.java8
-rw-r--r--src/com/android/documentsui/sidebar/RootsList.java4
-rw-r--r--tests/functional/com/android/documentsui/KeyboardNavigationUiTest.java1
8 files changed, 36 insertions, 10 deletions
diff --git a/res/layout/fragment_roots.xml b/res/layout/fragment_roots.xml
index 382b98b5c..ee5ba3c3a 100644
--- a/res/layout/fragment_roots.xml
+++ b/res/layout/fragment_roots.xml
@@ -20,5 +20,5 @@
android:layout_height="match_parent"
android:paddingTop="8dp"
android:listSelector="@drawable/root_list_selector"
- android:divider="@null"
- android:background="@drawable/roots_list_border" />
+ acndroid:background="@drawable/roots_list_border"
+ android:divider="@null" />
diff --git a/res/layout/navigation_breadcrumb_item.xml b/res/layout/navigation_breadcrumb_item.xml
index d5b546c61..1dd6d921f 100644
--- a/res/layout/navigation_breadcrumb_item.xml
+++ b/res/layout/navigation_breadcrumb_item.xml
@@ -30,6 +30,7 @@
android:layout_width="wrap_content"
android:layout_height="@dimen/breadcrumb_item_height"
android:layout_alignParentTop="true"
+ android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
@@ -38,6 +39,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
+ android:duplicateParentState="true"
android:textAppearance="@android:style/TextAppearance.Material.Widget.ActionBar.Title"
android:background="@drawable/breadcrumb_item_background" />
diff --git a/src/com/android/documentsui/FocusManager.java b/src/com/android/documentsui/FocusManager.java
index 85f7f74c6..ecc425191 100644
--- a/src/com/android/documentsui/FocusManager.java
+++ b/src/com/android/documentsui/FocusManager.java
@@ -42,6 +42,7 @@ import android.widget.TextView;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.base.Events;
import com.android.documentsui.base.Procedure;
+import com.android.documentsui.base.Shared;
import com.android.documentsui.dirlist.DocumentHolder;
import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.dirlist.FocusHandler;
@@ -81,6 +82,9 @@ public final class FocusManager implements FocusHandler {
@Override
public boolean advanceFocusArea() {
+ // This should only be called in pre-O devices.
+ // O has built-in keyboard navigation support.
+ assert(!Shared.ENABLE_OMC_API_FEATURES);
boolean focusChanged = false;
if (mNavDrawerHasFocus) {
mDrawer.setOpen(false);
diff --git a/src/com/android/documentsui/HorizontalBreadcrumb.java b/src/com/android/documentsui/HorizontalBreadcrumb.java
index f45ab677a..dd77a488d 100644
--- a/src/com/android/documentsui/HorizontalBreadcrumb.java
+++ b/src/com/android/documentsui/HorizontalBreadcrumb.java
@@ -21,6 +21,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.GestureDetector;
+import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -69,7 +70,7 @@ public final class HorizontalBreadcrumb extends RecyclerView
mLayoutManager = new LinearLayoutManager(
getContext(), LinearLayoutManager.HORIZONTAL, false);
mAdapter = new BreadcrumbAdapter(
- state, env, new ItemDragListener<>(this));
+ state, env, new ItemDragListener<>(this), this::onKey);
// Since we are using GestureDetector to detect click events, a11y services don't know which views
// are clickable because we aren't using View.OnClickListener. Thus, we need to use a custom
// accessibility delegate to route click events correctly. See AccessibilityClickEventRouter
@@ -126,6 +127,15 @@ public final class HorizontalBreadcrumb extends RecyclerView
return false;
}
+ private boolean onKey(View v, int keyCode, KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_ENTER:
+ return onAccessibilityClick(v);
+ default:
+ return false;
+ }
+ }
+
@Override
public void postUpdate() {
}
@@ -175,15 +185,18 @@ public final class HorizontalBreadcrumb extends RecyclerView
private final Environment mEnv;
private final com.android.documentsui.base.State mState;
private final OnDragListener mDragListener;
+ private final View.OnKeyListener mClickListener;
// We keep the old item size so the breadcrumb will only re-render views that are necessary
private int mLastItemSize;
public BreadcrumbAdapter(com.android.documentsui.base.State state,
Environment env,
- OnDragListener dragListener) {
+ OnDragListener dragListener,
+ View.OnKeyListener clickListener) {
mState = state;
mEnv = env;
mDragListener = dragListener;
+ mClickListener = clickListener;
mLastItemSize = mState.stack.size();
}
@@ -215,6 +228,7 @@ public final class HorizontalBreadcrumb extends RecyclerView
holder.arrow.setVisibility(View.VISIBLE);
}
holder.itemView.setOnDragListener(mDragListener);
+ holder.itemView.setOnKeyListener(mClickListener);
}
private DocumentInfo getItem(int position) {
diff --git a/src/com/android/documentsui/SharedInputHandler.java b/src/com/android/documentsui/SharedInputHandler.java
index e14084fb7..c5417ea5a 100644
--- a/src/com/android/documentsui/SharedInputHandler.java
+++ b/src/com/android/documentsui/SharedInputHandler.java
@@ -19,6 +19,7 @@ import android.view.KeyEvent;
import com.android.documentsui.base.Events;
import com.android.documentsui.base.Procedure;
+import com.android.documentsui.base.Shared;
public class SharedInputHandler {
@@ -37,8 +38,10 @@ public class SharedInputHandler {
// which is probably what the user is trying to do.
mFocusManager.focusDirectoryList();
return true;
- } else if (keyCode == KeyEvent.KEYCODE_TAB) {
+ } else if (keyCode == KeyEvent.KEYCODE_TAB && !Shared.ENABLE_OMC_API_FEATURES) {
// Tab toggles focus on the navigation drawer.
+ // This should only be called in pre-O devices, since O has built-in keyboard navigation
+ // support.
mFocusManager.advanceFocusArea();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java
index f5a96649a..6988d05ec 100644
--- a/src/com/android/documentsui/files/FilesActivity.java
+++ b/src/com/android/documentsui/files/FilesActivity.java
@@ -96,10 +96,10 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons
mInjector.selectionMgr = new SelectionManager(SelectionManager.MODE_MULTIPLE);
mInjector.focusManager = new FocusManager(
- mInjector.selectionMgr,
- mDrawer,
- this::focusSidebar,
- getColor(R.color.accent_dark));
+ mInjector.selectionMgr,
+ mDrawer,
+ this::focusSidebar,
+ getColor(R.color.accent_dark));
mInjector.menuManager = new MenuManager(
mInjector.prefs,
diff --git a/src/com/android/documentsui/sidebar/RootsList.java b/src/com/android/documentsui/sidebar/RootsList.java
index 248384983..1de2710b5 100644
--- a/src/com/android/documentsui/sidebar/RootsList.java
+++ b/src/com/android/documentsui/sidebar/RootsList.java
@@ -20,6 +20,8 @@ import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.ListView;
+import com.android.documentsui.base.Shared;
+
/**
* The list in the navigation drawer. This class exists for the purpose of overriding the key
* handler on ListView. Ignoring keystrokes (e.g. the tab key) cannot be properly done using
@@ -51,7 +53,7 @@ public class RootsList extends ListView {
// Ignore tab key events - this causes them to bubble up to the global key handler where
// they are appropriately handled. See BaseActivity.onKeyDown.
case KeyEvent.KEYCODE_TAB:
- return false;
+ return Shared.ENABLE_OMC_API_FEATURES ? super.onKeyDown(keyCode, event) : false;
// Prevent left/right arrow keystrokes from shifting focus away from the roots list.
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
diff --git a/tests/functional/com/android/documentsui/KeyboardNavigationUiTest.java b/tests/functional/com/android/documentsui/KeyboardNavigationUiTest.java
index d9e20656e..6dcad17b8 100644
--- a/tests/functional/com/android/documentsui/KeyboardNavigationUiTest.java
+++ b/tests/functional/com/android/documentsui/KeyboardNavigationUiTest.java
@@ -63,6 +63,7 @@ public class KeyboardNavigationUiTest extends ActivityTest<FilesActivity> {
}
}
+ @Suppress
public void testKeyboard_tabFocuses() throws Exception {
bots.roots.closeDrawer();
if (bots.main.inFixedLayout()) {