diff options
| author | 2020-05-07 11:38:59 +0000 | |
|---|---|---|
| committer | 2020-05-07 11:38:59 +0000 | |
| commit | 2f16758a0ad27df0c1ccdd19eaf73693c57c32d7 (patch) | |
| tree | 5c3a38b6b28b2af89923615aad2bca6642b986e8 | |
| parent | b3c02592e1cadfa9e5e032853d63b267fd7cfc34 (diff) | |
| parent | 877b5ec26272a7deaa8e273fa30926f75fe70a07 (diff) | |
Merge "Sharesheet/Resolver a11y adjustments" into rvc-dev
7 files changed, 95 insertions, 20 deletions
diff --git a/core/java/com/android/internal/app/ChooserGridLayoutManager.java b/core/java/com/android/internal/app/ChooserGridLayoutManager.java new file mode 100644 index 000000000000..317a987cf359 --- /dev/null +++ b/core/java/com/android/internal/app/ChooserGridLayoutManager.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.app; + +import android.content.Context; +import android.util.AttributeSet; + +import com.android.internal.widget.GridLayoutManager; +import com.android.internal.widget.RecyclerView; + +/** + * For a11y and per {@link RecyclerView#onInitializeAccessibilityNodeInfo}, override + * methods to ensure proper row counts. + */ +public class ChooserGridLayoutManager extends GridLayoutManager { + + /** + * Constructor used when layout manager is set in XML by RecyclerView attribute + * "layoutManager". If spanCount is not specified in the XML, it defaults to a + * single column. + * + */ + public ChooserGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + /** + * Creates a vertical GridLayoutManager + * + * @param context Current context, will be used to access resources. + * @param spanCount The number of columns in the grid + */ + public ChooserGridLayoutManager(Context context, int spanCount) { + super(context, spanCount); + } + + /** + * @param context Current context, will be used to access resources. + * @param spanCount The number of columns or rows in the grid + * @param orientation Layout orientation. Should be {@link #HORIZONTAL} or {@link + * #VERTICAL}. + * @param reverseLayout When set to true, layouts from end to start. + */ + public ChooserGridLayoutManager(Context context, int spanCount, int orientation, + boolean reverseLayout) { + super(context, spanCount, orientation, reverseLayout); + } + + @Override + public int getRowCountForAccessibility(RecyclerView.Recycler recycler, + RecyclerView.State state) { + // Do not count the footer view in the official count + return super.getRowCountForAccessibility(recycler, state) - 1; + } +} diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java index 2fd938f45291..24bf98b6502c 100644 --- a/core/java/com/android/internal/app/ResolverListAdapter.java +++ b/core/java/com/android/internal/app/ResolverListAdapter.java @@ -54,6 +54,7 @@ import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.ResolverActivity.ResolvedComponentInfo; import com.android.internal.app.chooser.DisplayResolveInfo; +import com.android.internal.app.chooser.SelectableTargetInfo; import com.android.internal.app.chooser.TargetInfo; import java.util.ArrayList; @@ -549,6 +550,15 @@ public class ResolverListAdapter extends BaseAdapter { getLoadLabelTask((DisplayResolveInfo) info, holder).execute(); } else { holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo()); + if (info instanceof SelectableTargetInfo) { + // direct share targets should append the application name for a better readout + DisplayResolveInfo rInfo = ((SelectableTargetInfo) info).getDisplayResolveInfo(); + CharSequence appName = rInfo != null ? rInfo.getDisplayLabel() : ""; + CharSequence extendedInfo = info.getExtendedInfo(); + String contentDescription = String.join(" ", info.getDisplayLabel(), + extendedInfo != null ? extendedInfo : "", appName); + holder.updateContentDescription(contentDescription); + } } if (info.isSuspended()) { @@ -697,6 +707,12 @@ public class ResolverListAdapter extends BaseAdapter { text2.setVisibility(View.VISIBLE); text2.setText(subLabel); } + + itemView.setContentDescription(null); + } + + public void updateContentDescription(String description) { + itemView.setContentDescription(description); } } diff --git a/core/java/com/android/internal/app/chooser/SelectableTargetInfo.java b/core/java/com/android/internal/app/chooser/SelectableTargetInfo.java index 246a07d3d0fe..900e18d468bb 100644 --- a/core/java/com/android/internal/app/chooser/SelectableTargetInfo.java +++ b/core/java/com/android/internal/app/chooser/SelectableTargetInfo.java @@ -44,7 +44,6 @@ import com.android.internal.app.ResolverListAdapter.ActivityInfoPresentationGett import com.android.internal.app.SimpleIconFactory; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -136,6 +135,10 @@ public final class SelectableTargetInfo implements ChooserTargetInfo { return mIsSuspended; } + public DisplayResolveInfo getDisplayResolveInfo() { + return mSourceInfo; + } + private Drawable getChooserTargetIconDrawable(ChooserTarget target, @Nullable ShortcutInfo shortcutInfo) { Drawable directShareIcon = null; diff --git a/core/java/com/android/internal/widget/GridLayoutManager.java b/core/java/com/android/internal/widget/GridLayoutManager.java index e0502f129f7f..09e6a991b1ac 100644 --- a/core/java/com/android/internal/widget/GridLayoutManager.java +++ b/core/java/com/android/internal/widget/GridLayoutManager.java @@ -153,13 +153,11 @@ public class GridLayoutManager extends LinearLayoutManager { if (mOrientation == HORIZONTAL) { info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain( glp.getSpanIndex(), glp.getSpanSize(), - spanGroupIndex, 1, - mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false)); + spanGroupIndex, 1, false, false)); } else { // VERTICAL info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain( spanGroupIndex, 1, - glp.getSpanIndex(), glp.getSpanSize(), - mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false)); + glp.getSpanIndex(), glp.getSpanSize(), false, false)); } } diff --git a/core/java/com/android/internal/widget/ResolverDrawerLayout.java b/core/java/com/android/internal/widget/ResolverDrawerLayout.java index fb2ecf3a478f..3f708f84750c 100644 --- a/core/java/com/android/internal/widget/ResolverDrawerLayout.java +++ b/core/java/com/android/internal/widget/ResolverDrawerLayout.java @@ -825,18 +825,6 @@ public class ResolverDrawerLayout extends ViewGroup { return true; } break; - case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: - case R.id.accessibilityActionScrollUp: - if (mCollapseOffset < mCollapsibleHeight) { - smoothScrollTo(mCollapsibleHeight, 0); - return true; - } else if ((mCollapseOffset < mCollapsibleHeight + mUncollapsibleHeight) - && isDismissable()) { - smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, 0); - mDismissOnScrollerFinished = true; - return true; - } - break; case AccessibilityNodeInfo.ACTION_COLLAPSE: if (mCollapseOffset < mCollapsibleHeight) { smoothScrollTo(mCollapsibleHeight, 0); @@ -886,7 +874,6 @@ public class ResolverDrawerLayout extends ViewGroup { } if ((mCollapseOffset < mCollapsibleHeight + mUncollapsibleHeight) && ((mCollapseOffset < mCollapsibleHeight) || isDismissable())) { - info.addAction(AccessibilityAction.ACTION_SCROLL_BACKWARD); info.addAction(AccessibilityAction.ACTION_SCROLL_UP); info.setScrollable(true); } diff --git a/core/res/res/layout/chooser_list_per_profile.xml b/core/res/res/layout/chooser_list_per_profile.xml index 6b1b002267cb..86dc71cbbfb8 100644 --- a/core/res/res/layout/chooser_list_per_profile.xml +++ b/core/res/res/layout/chooser_list_per_profile.xml @@ -20,7 +20,7 @@ <com.android.internal.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" - android:layoutManager="com.android.internal.widget.GridLayoutManager" + android:layoutManager="com.android.internal.app.ChooserGridLayoutManager" android:id="@+id/resolver_list" android:clipToPadding="false" android:background="?attr/colorBackgroundFloating" @@ -29,4 +29,4 @@ android:nestedScrollingEnabled="true" /> <include layout="@layout/resolver_empty_states" /> -</RelativeLayout>
\ No newline at end of file +</RelativeLayout> diff --git a/core/res/res/layout/resolver_list.xml b/core/res/res/layout/resolver_list.xml index 4d0837f495df..446ce3fbaf4b 100644 --- a/core/res/res/layout/resolver_list.xml +++ b/core/res/res/layout/resolver_list.xml @@ -83,6 +83,7 @@ android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" + android:accessibilityTraversalAfter="@id/title" android:background="?attr/colorBackgroundFloating"> <LinearLayout android:orientation="vertical" |