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

Commit a0cb1a84 authored by Ivan Tkachenko's avatar Ivan Tkachenko Committed by Android (Google) Code Review
Browse files

Merge "Bubble expand/collapse accessibility announcement" into main

parents 8eb8d824 db5eab10
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@
    <string name="bubble_accessibility_action_move_bottom_left">Move bottom left</string>
    <!-- Action in accessibility menu to move the stack of bubbles to the bottom right of the screen. [CHAR LIMIT=30]-->
    <string name="bubble_accessibility_action_move_bottom_right">Move bottom right</string>
    <!-- Accessibility announcement when the stack of bubbles expands. [CHAR LIMIT=NONE]-->
    <string name="bubble_accessibility_announce_expand">expand <xliff:g id="bubble_title" example="Messages">%1$s</xliff:g></string>
    <!-- Accessibility announcement when the stack of bubbles collapses. [CHAR LIMIT=NONE]-->
    <string name="bubble_accessibility_announce_collapse">collapse <xliff:g id="bubble_title" example="Messages">%1$s</xliff:g></string>
    <!-- Label for the button that takes the user to the notification settings for the given app. -->
    <string name="bubbles_app_settings"><xliff:g id="notification_title" example="Android Messages">%1$s</xliff:g> settings</string>
    <!-- Text used for the bubble dismiss area. Bubbles dragged to, or flung towards, this area will go away. [CHAR LIMIT=30] -->
+29 −0
Original line number Diff line number Diff line
@@ -2037,6 +2037,7 @@ public class BubbleStackView extends FrameLayout
            });
        }
        notifyExpansionChanged(mExpandedBubble, mIsExpanded);
        announceExpandForAccessibility(mExpandedBubble, mIsExpanded);
    }

    /**
@@ -2053,6 +2054,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: `<app> from <app>`.
            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)