From 85d4b8bb72700ca9cea9457a1e99936b949fb9c8 Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Fri, 19 Jul 2024 18:11:45 -0700 Subject: [PATCH] Create a11y menu for a bubble in bubble bar A11y that supports the following actions: - collapse - dismiss - move bar to the left or right (depending on current location) Bug: 347028716 Test: select bubble in expanded bubble bar, open action menu Test: use action menu to: - collapse bubble bar - dismiss a bubble, ensure only selected bubble is dismissed - move bubble bar to other side Flag: com.android.wm.shell.enable_bubble_bar Change-Id: I70d90877e045abadb1fca4665ce315476d33c713 --- .../bubbles/BubbleBarViewController.java | 47 ++++++++++-- .../bubbles/BubbleDismissController.java | 2 +- .../taskbar/bubbles/BubbleDragController.java | 2 +- .../launcher3/taskbar/bubbles/BubbleView.java | 73 +++++++++++++++++++ 4 files changed, 115 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 74a673b066..45e6199057 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -73,6 +73,7 @@ public class BubbleBarViewController { private TaskbarInsetsController mTaskbarInsetsController; private View.OnClickListener mBubbleClickListener; private View.OnClickListener mBubbleBarClickListener; + private BubbleView.Controller mBubbleViewController; // These are exposed to {@link BubbleStashController} to animate for stashing/un-stashing private final MultiValueAlpha mBubbleBarAlpha; @@ -153,6 +154,31 @@ public class BubbleBarViewController { mBubbleBarController.updateBubbleBarLocation(location); } }); + + mBubbleViewController = new BubbleView.Controller() { + @Override + public BubbleBarLocation getBubbleBarLocation() { + return BubbleBarViewController.this.getBubbleBarLocation(); + } + + @Override + public void dismiss(BubbleView bubble) { + if (bubble.getBubble() != null) { + notifySysUiBubbleDismissed(bubble.getBubble()); + } + onBubbleDismissed(bubble); + } + + @Override + public void collapse() { + collapseBubbleBar(); + } + + @Override + public void updateBubbleBarLocation(BubbleBarLocation location) { + mBubbleBarController.updateBubbleBarLocation(location); + } + }; } private void onBubbleClicked(BubbleView bubbleView) { @@ -165,8 +191,7 @@ public class BubbleBarViewController { final String currentlySelected = mBubbleBarController.getSelectedBubbleKey(); if (mBarView.isExpanded() && Objects.equals(bubble.getKey(), currentlySelected)) { // Tapping the currently selected bubble while expanded collapses the view. - setExpanded(false); - mBubbleStashController.stashBubbleBar(); + collapseBubbleBar(); } else { mBubbleBarController.showAndSelectBubble(bubble); } @@ -196,6 +221,11 @@ public class BubbleBarViewController { } } + private void collapseBubbleBar() { + setExpanded(false); + mBubbleStashController.stashBubbleBar(); + } + /** Notifies that the stash state is changing. */ public void onStashStateChanging() { if (isAnimatingNewBubble()) { @@ -440,6 +470,7 @@ public class BubbleBarViewController { public void removeBubble(BubbleBarBubble b) { if (b != null) { mBarView.removeBubble(b.getView()); + b.getView().setController(null); } else { Log.w(TAG, "removeBubble, bubble was null!"); } @@ -450,6 +481,8 @@ public class BubbleBarViewController { BubbleBarBubble removedBubble, boolean isExpanding, boolean suppressAnimation) { mBarView.addBubbleAndRemoveBubble(addedBubble.getView(), removedBubble.getView()); addedBubble.getView().setOnClickListener(mBubbleClickListener); + addedBubble.getView().setController(mBubbleViewController); + removedBubble.getView().setController(null); mBubbleDragController.setupBubbleView(addedBubble.getView()); if (!suppressAnimation) { animateBubbleNotification(addedBubble, isExpanding, /* isUpdate= */ false); @@ -464,6 +497,7 @@ public class BubbleBarViewController { mBarView.addBubble(b.getView()); b.getView().setOnClickListener(mBubbleClickListener); mBubbleDragController.setupBubbleView(b.getView()); + b.getView().setController(mBubbleViewController); if (b instanceof BubbleBarOverflow) { return; @@ -580,8 +614,8 @@ public class BubbleBarViewController { mSystemUiProxy.stopBubbleDrag(location, mBarView.getRestingTopPositionOnScreen()); } - /** Notifies {@link BubbleBarView} that the dragged bubble was dismissed. */ - public void onBubbleDragDismissed(BubbleView bubble) { + /** Handle given bubble being dismissed */ + public void onBubbleDismissed(BubbleView bubble) { mBubbleBarController.onBubbleDismissed(bubble); mBarView.removeBubble(bubble); } @@ -624,10 +658,9 @@ public class BubbleBarViewController { } /** - * Called when given bubble was dismissed. Notifies SystemUI - * @param bubble dismissed bubble item + * Notify SystemUI that the given bubble has been dismissed. */ - public void onDismissBubble(@NonNull BubbleBarItem bubble) { + public void notifySysUiBubbleDismissed(@NonNull BubbleBarItem bubble) { mSystemUiProxy.dragBubbleToDismiss(bubble.getKey(), mTimeSource.currentTimeMillis()); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java index 6a63da890e..5eebbd8c36 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java @@ -143,7 +143,7 @@ public class BubbleDismissController { if (mMagnetizedObject.getUnderlyingObject() instanceof BubbleView) { BubbleView bubbleView = (BubbleView) mMagnetizedObject.getUnderlyingObject(); if (bubbleView.getBubble() != null) { - mBubbleBarViewController.onDismissBubble(bubbleView.getBubble()); + mBubbleBarViewController.notifySysUiBubbleDismissed(bubbleView.getBubble()); } } else if (mMagnetizedObject.getUnderlyingObject() instanceof BubbleBarView) { mBubbleBarViewController.onDismissAllBubbles(); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java index 8316b5bed3..656a26678e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java @@ -153,7 +153,7 @@ public class BubbleDragController { @Override protected void onDragDismiss() { mBubblePinController.onDragEnd(); - mBubbleBarViewController.onBubbleDragDismissed(bubbleView); + mBubbleBarViewController.onBubbleDismissed(bubbleView); mBubbleBarViewController.onBubbleDragEnd(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java index acb6b4ecfe..3bcaa16f40 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java @@ -23,11 +23,13 @@ import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Path; import android.graphics.Rect; +import android.os.Bundle; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewOutlineProvider; +import android.view.accessibility.AccessibilityNodeInfo; import android.widget.ImageView; import androidx.constraintlayout.widget.ConstraintLayout; @@ -36,6 +38,7 @@ import com.android.launcher3.R; import com.android.launcher3.icons.DotRenderer; import com.android.launcher3.icons.IconNormalizer; import com.android.wm.shell.animation.Interpolators; +import com.android.wm.shell.common.bubbles.BubbleBarLocation; import com.android.wm.shell.common.bubbles.BubbleInfo; // TODO: (b/276978250) This is will be similar to WMShell's BadgedImageView, it'd be nice to share. @@ -73,6 +76,9 @@ public class BubbleView extends ConstraintLayout { private BubbleBarItem mBubble; + @Nullable + private Controller mController; + public BubbleView(Context context) { this(context, null); } @@ -180,6 +186,58 @@ public class BubbleView extends ConstraintLayout { mDotRenderer.draw(canvas, mDrawParams); } + @Override + public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfoInternal(info); + info.addAction(AccessibilityNodeInfo.ACTION_COLLAPSE); + if (mBubble instanceof BubbleBarBubble) { + info.addAction(AccessibilityNodeInfo.ACTION_DISMISS); + } + if (mController != null) { + if (mController.getBubbleBarLocation().isOnLeft(isLayoutRtl())) { + info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_move_right, + getResources().getString(R.string.bubble_bar_action_move_right))); + } else { + info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_move_left, + getResources().getString(R.string.bubble_bar_action_move_left))); + } + } + } + + @Override + public boolean performAccessibilityActionInternal(int action, Bundle arguments) { + if (super.performAccessibilityActionInternal(action, arguments)) { + return true; + } + if (action == AccessibilityNodeInfo.ACTION_COLLAPSE) { + if (mController != null) { + mController.collapse(); + } + return true; + } + if (action == AccessibilityNodeInfo.ACTION_DISMISS) { + if (mController != null) { + mController.dismiss(this); + } + return true; + } + if (action == R.id.action_move_left) { + if (mController != null) { + mController.updateBubbleBarLocation(BubbleBarLocation.LEFT); + } + } + if (action == R.id.action_move_right) { + if (mController != null) { + mController.updateBubbleBarLocation(BubbleBarLocation.RIGHT); + } + } + return false; + } + + void setController(@Nullable Controller controller) { + mController = controller; + } + /** Sets the bubble being rendered in this view. */ public void setBubble(BubbleBarBubble bubble) { mBubble = bubble; @@ -337,4 +395,19 @@ public class BubbleView extends ConstraintLayout { String toString = mBubble != null ? mBubble.getKey() : "null"; return "BubbleView{" + toString + "}"; } + + /** Interface for BubbleView to communicate with its controller */ + public interface Controller { + /** Get current bubble bar {@link BubbleBarLocation} */ + BubbleBarLocation getBubbleBarLocation(); + + /** This bubble should be dismissed */ + void dismiss(BubbleView bubble); + + /** Collapse the bubble bar */ + void collapse(); + + /** Request bubble bar location to be updated to the given location */ + void updateBubbleBarLocation(BubbleBarLocation location); + } }