Add a11y action for expand / collapse items in WidgetsFullSheet
Test: Enable talkback. When focusing on a collapsed item, it announces
Collapsed "App Name" "n widgets/shortcuts". Action available. Use
tap with 3 fingers to view. 3 fingers tap > Action > Expand.
Widgets are expanded.
When focusing on an expanded item, it announces
Expanded "App Name" "n widgets/shortcuts". Action available. Use
tap with 3 fingers to view. 3 fingers tap > Action > Collapse.
Widgets are collapsed.
Bug: 183120145
Change-Id: Ibbb6025b929c141aa9e2fd2c72dce314e8be837e
diff --git a/res/layout/widgets_list_row_header.xml b/res/layout/widgets_list_row_header.xml
index 8259c16..cec32ea 100644
--- a/res/layout/widgets_list_row_header.xml
+++ b/res/layout/widgets_list_row_header.xml
@@ -35,6 +35,7 @@
tools:src="@drawable/ic_corp"/>
<LinearLayout
+ android:id="@+id/app_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
diff --git a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java
index 8794a4a..ccf3187 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java
@@ -19,7 +19,10 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
+import android.os.Bundle;
import android.util.AttributeSet;
+import android.view.View;
+import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -94,6 +97,32 @@
mTitle = findViewById(R.id.app_title);
mSubtitle = findViewById(R.id.app_subtitle);
mExpandToggle = findViewById(R.id.toggle);
+ findViewById(R.id.app_container).setAccessibilityDelegate(new AccessibilityDelegate() {
+
+ @Override
+ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
+ if (mIsExpanded) {
+ info.removeAction(AccessibilityNodeInfo.ACTION_EXPAND);
+ info.addAction(AccessibilityNodeInfo.ACTION_COLLAPSE);
+ } else {
+ info.removeAction(AccessibilityNodeInfo.ACTION_COLLAPSE);
+ info.addAction(AccessibilityNodeInfo.ACTION_EXPAND);
+ }
+ super.onInitializeAccessibilityNodeInfo(host, info);
+ }
+
+ @Override
+ public boolean performAccessibilityAction(View host, int action, Bundle args) {
+ switch (action) {
+ case AccessibilityNodeInfo.ACTION_EXPAND:
+ case AccessibilityNodeInfo.ACTION_COLLAPSE:
+ callOnClick();
+ return true;
+ default:
+ return super.performAccessibilityAction(host, action, args);
+ }
+ }
+ });
}
/**
@@ -106,7 +135,9 @@
// Use the entire touch area of this view to expand / collapse an app widgets section.
setOnClickListener(view -> {
setExpanded(!mIsExpanded);
- onExpandChangeListener.onExpansionChange(mIsExpanded);
+ if (onExpandChangeListener != null) {
+ onExpandChangeListener.onExpansionChange(mIsExpanded);
+ }
});
}