Fix broken a11y function
Due some a11y delegate change on Androidx RecyclerView, some a11y
founctions on docsui are broken.
Remove using RecyclerViewAccessibityDelegate and set a11y delegate
on each ViewHolder on RecyclerView.
Fine tune HorizontalBreadcrumb layout of text also during checking
function normally.
Fix: 139101197
Test: atest DocumentsUIGoogle
Change-Id: I22345a117849167093fd21d5603de3161ab2219a
diff --git a/src/com/android/documentsui/HorizontalBreadcrumb.java b/src/com/android/documentsui/HorizontalBreadcrumb.java
index 6a7cce1..91480db 100644
--- a/src/com/android/documentsui/HorizontalBreadcrumb.java
+++ b/src/com/android/documentsui/HorizontalBreadcrumb.java
@@ -71,14 +71,8 @@
mLayoutManager = new LinearLayoutManager(
getContext(), LinearLayoutManager.HORIZONTAL, false);
mAdapter = new BreadcrumbAdapter(
- 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
- // for more details on how we are routing these a11y events.
- setAccessibilityDelegateCompat(
- new AccessibilityEventRouter(this,
- (View child) -> onAccessibilityClick(child), null));
+ state, env, new ItemDragListener<>(this), this::onKey,
+ new AccessibilityEventRouter(this::onAccessibilityClick, null));
setLayoutManager(mLayoutManager);
addOnItemTouchListener(new ClickListener(getContext(), this::onSingleTapUp));
@@ -192,17 +186,20 @@
private final com.android.documentsui.base.State mState;
private final OnDragListener mDragListener;
private final View.OnKeyListener mClickListener;
+ private final View.AccessibilityDelegate mAccessibilityDelegate;
// 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,
- View.OnKeyListener clickListener) {
+ View.OnKeyListener clickListener,
+ View.AccessibilityDelegate accessibilityDelegate) {
mState = state;
mEnv = env;
mDragListener = dragListener;
mClickListener = clickListener;
+ mAccessibilityDelegate = accessibilityDelegate;
mLastItemSize = mState.stack.size();
}
@@ -235,6 +232,12 @@
}
holder.itemView.setOnDragListener(mDragListener);
holder.itemView.setOnKeyListener(mClickListener);
+ // 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 for more details on how we are routing these
+ // a11y events.
+ holder.itemView.setAccessibilityDelegate(mAccessibilityDelegate);
}
private DocumentInfo getItem(int position) {