Improved expand accessibility experience
The expand action is now on the notification itself
instead of the expand button, this way a user immediately
know if it is expanded.
It also improves the click feedback of the expand button
Test: add notifications, observe accessibility feedback
Change-Id: I9c397d839df52d5354d7ae16725ce3e595da19c7
Fixes: 32322410
Fixes: 35064589
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java
index 16d4666..fe91978 100644
--- a/core/java/android/view/NotificationHeaderView.java
+++ b/core/java/android/view/NotificationHeaderView.java
@@ -23,9 +23,7 @@
import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import android.os.Bundle;
import android.util.AttributeSet;
-import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
import android.widget.RemoteViews;
@@ -67,33 +65,6 @@
}
}
};
- final AccessibilityDelegate mExpandDelegate = new AccessibilityDelegate() {
-
- @Override
- public boolean performAccessibilityAction(View host, int action, Bundle args) {
- if (super.performAccessibilityAction(host, action, args)) {
- return true;
- }
- if (action == AccessibilityNodeInfo.ACTION_COLLAPSE
- || action == AccessibilityNodeInfo.ACTION_EXPAND) {
- mExpandClickListener.onClick(mExpandButton);
- return true;
- }
- return false;
- }
-
- @Override
- public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(host, info);
- // Avoid that the button description is also spoken
- info.setClassName(getClass().getName());
- if (mExpanded) {
- info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
- } else {
- info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
- }
- }
- };
private boolean mAcceptAllTouches;
public NotificationHeaderView(Context context) {
@@ -124,9 +95,6 @@
mAppName = findViewById(com.android.internal.R.id.app_name_text);
mHeaderText = findViewById(com.android.internal.R.id.header_text);
mExpandButton = (ImageView) findViewById(com.android.internal.R.id.expand_button);
- if (mExpandButton != null) {
- mExpandButton.setAccessibilityDelegate(mExpandDelegate);
- }
mIcon = (CachingIconView) findViewById(com.android.internal.R.id.icon);
mProfileBadge = findViewById(com.android.internal.R.id.profile_badge);
}
@@ -295,13 +263,19 @@
private void updateExpandButton() {
int drawableId;
+ int contentDescriptionId;
if (mExpanded) {
drawableId = com.android.internal.R.drawable.ic_collapse_notification;
+ contentDescriptionId
+ = com.android.internal.R.string.expand_button_content_description_expanded;
} else {
drawableId = com.android.internal.R.drawable.ic_expand_notification;
+ contentDescriptionId
+ = com.android.internal.R.string.expand_button_content_description_collapsed;
}
mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
mExpandButton.setColorFilter(mOriginalNotificationColor);
+ mExpandButton.setContentDescription(mContext.getText(contentDescriptionId));
}
public void setShowWorkBadgeAtEnd(boolean showWorkBadgeAtEnd) {
@@ -391,7 +365,7 @@
break;
case MotionEvent.ACTION_UP:
if (mTrackGesture) {
- mExpandClickListener.onClick(NotificationHeaderView.this);
+ mExpandButton.performClick();
}
break;
}
diff --git a/core/java/com/android/internal/widget/NotificationExpandButton.java b/core/java/com/android/internal/widget/NotificationExpandButton.java
index f4f49b1..c64ace4 100644
--- a/core/java/com/android/internal/widget/NotificationExpandButton.java
+++ b/core/java/com/android/internal/widget/NotificationExpandButton.java
@@ -20,6 +20,8 @@
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.widget.Button;
import android.widget.ImageView;
import android.widget.RemoteViews;
@@ -59,4 +61,10 @@
rect.top = rect.centerY() - touchTargetSize / 2;
rect.bottom = rect.top + touchTargetSize;
}
+
+ @Override
+ public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+ super.onInitializeAccessibilityNodeInfo(info);
+ info.setClassName(Button.class.getName());
+ }
}
diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml
index 0dfeb62..448cd2e 100644
--- a/core/res/res/layout/notification_template_header.xml
+++ b/core/res/res/layout/notification_template_header.xml
@@ -97,7 +97,7 @@
android:layout_height="wrap_content"
android:paddingTop="1dp"
android:visibility="gone"
- android:contentDescription="@string/expand_button_content_description"
+ android:contentDescription="@string/expand_button_content_description_collapsed"
/>
<ImageView android:id="@+id/profile_badge"
android:layout_width="@dimen/notification_badge_size"
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index f6da660..2301269 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -4335,8 +4335,11 @@
<!-- Content description of the work profile icon in the notification. -->
<string name="notification_work_profile_content_description">Work profile</string>
- <!-- Content description of the expand button icon in the notification.-->
- <string name="expand_button_content_description">Expand button</string>
+ <!-- Content description of the expand button icon in the notification when collaped.-->
+ <string name="expand_button_content_description_collapsed">Expand</string>
+
+ <!-- Content description of the expand button icon in the notification when expanded.-->
+ <string name="expand_button_content_description_expanded">Collapse</string>
<!-- Accessibility action description on the expand button. -->
<string name="expand_action_accessibility">toggle expansion</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index eb248e5..1dd4dd4 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2877,6 +2877,9 @@
<java-symbol type="string" name="alert_windows_notification_turn_off_action" />
<java-symbol type="drawable" name="alert_window_layer" />
+ <java-symbol type="string" name="expand_button_content_description_collapsed" />
+ <java-symbol type="string" name="expand_button_content_description_expanded" />
+
<!-- Colon separated list of package names that should be granted Notification Listener access -->
<java-symbol type="string" name="config_defaultListenerAccessPackages" />
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
index 602c3df..2d7a03b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
@@ -1720,6 +1720,9 @@
@Override
public boolean isContentExpandable() {
+ if (mIsSummaryWithChildren && !mShowingPublic) {
+ return true;
+ }
NotificationContentView showingLayout = getShowingLayout();
return showingLayout.isContentExpandable();
}
@@ -1987,6 +1990,26 @@
if (canViewBeDismissed()) {
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
}
+ boolean expandable = mShowingPublic;
+ boolean isExpanded = false;
+ if (!expandable) {
+ if (mIsSummaryWithChildren) {
+ expandable = true;
+ if (!mIsLowPriority || isExpanded()) {
+ isExpanded = isGroupExpanded();
+ }
+ } else {
+ expandable = mPrivateLayout.isContentExpandable();
+ isExpanded = isExpanded();
+ }
+ }
+ if (expandable) {
+ if (isExpanded) {
+ info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
+ } else {
+ info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
+ }
+ }
}
@Override
@@ -1999,6 +2022,10 @@
NotificationStackScrollLayout.performDismiss(this, mGroupManager,
true /* fromAccessibility */);
return true;
+ case AccessibilityNodeInfo.ACTION_COLLAPSE:
+ case AccessibilityNodeInfo.ACTION_EXPAND:
+ mExpandClickListener.onClick(this);
+ return true;
}
return false;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
index 74e65fb..d759f5a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
@@ -131,6 +131,7 @@
private boolean mIconsVisible;
private int mClipBottomAmount;
private boolean mIsLowPriority;
+ private boolean mIsContentExpandable;
public NotificationContentView(Context context, AttributeSet attrs) {
@@ -949,7 +950,7 @@
}
public boolean isContentExpandable() {
- return mExpandedChild != null;
+ return mIsContentExpandable;
}
public void setDark(boolean dark, boolean fade, long delay) {
@@ -1214,6 +1215,7 @@
if (mHeadsUpChild != null) {
mHeadsUpWrapper.updateExpandability(expandable, mExpandClickListener);
}
+ mIsContentExpandable = expandable;
}
public NotificationHeaderView getNotificationHeader() {