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

Commit 445e78bd authored by Wenbo Jie (介文博)'s avatar Wenbo Jie (介文博) Committed by Android (Google) Code Review
Browse files

Merge "[DocsUI M3] Update a11y voice announcement for file selection" into main

parents 9c7ad319 e9ff03cc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@
                android:singleLine="true"
                android:text="@string/bullet"
                android:textAlignment="viewStart"
                android:textAppearance="@style/ItemCaptionTextM3" />
                android:textAppearance="@style/ItemCaptionTextM3"
                android:importantForAccessibility="no" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/date"
+16 −0
Original line number Diff line number Diff line
@@ -476,6 +476,22 @@
    </plurals>
    <!-- Text used as the content description of the cancel button when files are selected. -->
    <string name="clear_selection">Clear selection</string>
    <!-- The voice announcement used as the description of the click action in the file
         list/grid for normal document in browsing mode. For example: Double tap to open. -->
    <string name="document_click_action">open</string>
    <!-- The voice announcement used as the description of the click action in the file list/grid.
         For example: Double tap to deselect. -->
    <string name="selected_document_click_action">deselect</string>
    <!-- The voice announcement used as the description of the long click action in the file
         list/grid for normal document. For example: Double tap and hold to select. -->
    <string name="document_long_click_action">select</string>
    <!-- The voice announcement used as the description of the long click action in the file
         list/grid for selected document. For example: Double tap and hold to drag. -->
    <string name="selected_document_long_click_action">drag</string>
    <!-- The voice announcement used as the description of the long click action in the file
         list/grid for normal document in picking mode.
         For example: Double tap and hold to select multiple. -->
    <string name="document_long_click_action_picker">select multiple</string>

    <!-- Label text showing user how many items are being dragged. Can be one or more elements. -->
    <plurals name="elements_dragged">
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public final class HorizontalBreadcrumb extends RecyclerView implements Breadcru
        // events.
        setAccessibilityDelegateCompat(
                new AccessibilityEventRouter(this,
                        (View child) -> onAccessibilityClick(child), null));
                        (View child) -> onAccessibilityClick(child), null, state.action));

        setLayoutManager(mLayoutManager);
        addOnItemTouchListener(new ClickListener(getContext(), this::onSingleTapUp));
+70 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui.dirlist;

import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;

import android.os.Bundle;
import android.view.View;

@@ -28,6 +30,8 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate;

import com.android.documentsui.BreadcrumbHolder;
import com.android.documentsui.R;
import com.android.documentsui.base.State;

import java.util.function.Function;

@@ -53,7 +57,8 @@ public class AccessibilityEventRouter extends RecyclerViewAccessibilityDelegate

    public AccessibilityEventRouter(
            RecyclerView recyclerView, @NonNull Function<View, Boolean> clickCallback,
            @Nullable Function<View, Boolean> longClickCallback) {
            @Nullable Function<View, Boolean> longClickCallback,
            @State.ActionType int actionType) {
        super(recyclerView);
        mClickCallback = clickCallback;
        mLongClickCallback = longClickCallback;
@@ -67,8 +72,12 @@ public class AccessibilityEventRouter extends RecyclerViewAccessibilityDelegate
                // is null, it can't be clicked
                if (holder instanceof DocumentHolder) {
                    if (((DocumentHolder) holder).getItemDetails() != null) {
                        if (isUseMaterial3FlagEnabled()) {
                            addActionForDocumentHolder(info, host, actionType);
                        } else {
                            addAction(info);
                        }
                    }
                } else if (holder instanceof BreadcrumbHolder) {
                    if (!((BreadcrumbHolder) holder).isLast()) {
                        addAction(info);
@@ -104,4 +113,63 @@ public class AccessibilityEventRouter extends RecyclerViewAccessibilityDelegate
            info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK);
        }
    }

    private void addActionForDocumentHolder(AccessibilityNodeInfoCompat info, View host,
            @State.ActionType int actionType) {
        // The click and long click actions behave differently based on its selection state
        // and app intent action mode (e.g. browsing/picker mode):
        // * browsing:
        //      * for unselected document: click -> open, long click -> select
        //      * for selected document: click -> deselect, long click -> drag
        // * picker:
        //      * for unselected document: click -> select, long click -> select multiple
        //      * for selected document: click -> deselect, long click -> no op

        String clickDescription =
                host.getResources().getString(R.string.document_click_action);
        String longClickDescription =
                host.getResources().getString(R.string.document_long_click_action);
        String clickForSelectedDescription =
                host.getResources().getString(R.string.selected_document_click_action);
        String longClickForSelectedDescription =
                host.getResources().getString(R.string.selected_document_long_click_action);
        String clickPickerDescription =
                host.getResources().getString(R.string.document_long_click_action);
        String longClickPickerDescription =
                host.getResources().getString(R.string.document_long_click_action_picker);
        String clickForSelectedPickerDescription =
                host.getResources().getString(R.string.selected_document_click_action);

        final boolean isBrowsingMode = actionType == State.ACTION_BROWSE;
        final boolean isSelected = host.isActivated();
        final boolean isLongClickSupported = mLongClickCallback != null;
        String clickActionDescription;
        String longClickActionDescription;
        if (isSelected) {
            clickActionDescription = isBrowsingMode ? clickForSelectedDescription
                    : clickForSelectedPickerDescription;
            longClickActionDescription = isBrowsingMode ? longClickForSelectedDescription : "";
        } else {
            clickActionDescription = isBrowsingMode ? clickDescription : clickPickerDescription;
            longClickActionDescription =
                    isBrowsingMode ? longClickDescription : longClickPickerDescription;
        }
        // Add click action.
        AccessibilityActionCompat clickAction =
                new AccessibilityActionCompat(AccessibilityNodeInfoCompat.ACTION_CLICK,
                        clickActionDescription);
        info.addAction(clickAction);
        // Add long click action if supported.
        if (!isLongClickSupported) {
            return;
        }
        if (longClickActionDescription.isEmpty()) {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK);
        } else {
            AccessibilityActionCompat longClickAction =
                    new AccessibilityActionCompat(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK,
                            longClickActionDescription);
            info.addAction(longClickAction);
        }
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -585,7 +585,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        mRecView.setAccessibilityDelegateCompat(
                new AccessibilityEventRouter(mRecView,
                        (View child) -> onAccessibilityClick(child),
                        (View child) -> onAccessibilityLongClick(child)));
                        (View child) -> onAccessibilityLongClick(child), mState.action));
        mSelectionMetadata = new SelectionMetadata(mModel::getItem);
        mDetailsLookup = new DocsItemDetailsLookup(mRecView);

Loading