From db5eab10592cd53f25d8dd6b6917d41ad4271131 Mon Sep 17 00:00:00 2001 From: Ivan Tkachenko Date: Wed, 13 Sep 2023 14:07:29 +0100 Subject: Bubble expand/collapse accessibility announcement * When the bubble expands/collapses the Talkback will announce `expand/collapse ` * Video attached in bug comments Bug: 283709905 Test: manual Flag: none Change-Id: I807b8f165bc6cc628b728405b83a555b294799d8 --- libs/WindowManager/Shell/res/values/strings.xml | 4 +++ .../android/wm/shell/bubbles/BubbleStackView.java | 29 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml index eabe3a4eca0b..b556150e2ab9 100644 --- a/libs/WindowManager/Shell/res/values/strings.xml +++ b/libs/WindowManager/Shell/res/values/strings.xml @@ -142,6 +142,10 @@ Move bottom left Move bottom right + + expand %1$s + + collapse %1$s %1$s settings diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index d10de833ab89..df77cb73f386 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -2038,6 +2038,7 @@ public class BubbleStackView extends FrameLayout }); } notifyExpansionChanged(mExpandedBubble, mIsExpanded); + announceExpandForAccessibility(mExpandedBubble, mIsExpanded); } /** @@ -2054,6 +2055,34 @@ public class BubbleStackView extends FrameLayout } } + private void announceExpandForAccessibility(BubbleViewProvider bubble, boolean expanded) { + if (bubble instanceof Bubble) { + String contentDescription = getBubbleContentDescription((Bubble) bubble); + String message = getResources().getString( + expanded + ? R.string.bubble_accessibility_announce_expand + : R.string.bubble_accessibility_announce_collapse, contentDescription); + announceForAccessibility(message); + } + } + + @NonNull + private String getBubbleContentDescription(Bubble bubble) { + final String appName = bubble.getAppName(); + final String title = bubble.getTitle() != null + ? bubble.getTitle() + : getResources().getString(R.string.notification_bubble_title); + + if (appName == null || title.equals(appName)) { + // App bubble title equals the app name, so return only the title to avoid having + // content description like: ` from `. + return title; + } else { + return getResources().getString( + R.string.bubble_content_description_single, title, appName); + } + } + private boolean isGestureNavEnabled() { return mContext.getResources().getInteger( com.android.internal.R.integer.config_navBarInteractionMode) -- cgit v1.2.3-59-g8ed1b