Merge "Create accessibility menu for bubble bar" into main

This commit is contained in:
Ats Jenk
2024-07-19 23:40:47 +00:00
committed by Android (Google) Code Review
5 changed files with 103 additions and 8 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2024 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Used for A11y actions for bubble bar -->
<item type="id" name="action_move_left" />
<item type="id" name="action_move_right" />
<item type="id" name="action_dismiss_all" />
</resources>

View File

@@ -342,4 +342,10 @@
<string name="bubble_bar_bubble_description"><xliff:g id="notification_title" example="some title">%1$s</xliff:g> from <xliff:g id="app_name" example="YouTube">%2$s</xliff:g></string>
<!-- Content description for bubble bar when it has multiple bubbles. [CHAR_LIMIT=NONE] -->
<string name="bubble_bar_description_multiple_bubbles"><xliff:g id="bubble_bar_bubble_description" example="some title from YouTube">%1$s</xliff:g> and <xliff:g id="bubble_count" example="4">%2$d</xliff:g> more</string>
<!-- Action in accessibility menu to move the bubble bar to the left side of the screen. [CHAR_LIMIT=30] -->
<string name="bubble_bar_action_move_left">Move left</string>
<!-- Action in accessibility menu to move the bubble bar to the right side of the screen. [CHAR_LIMIT=30] -->
<string name="bubble_bar_action_move_right">Move right</string>
<!-- Action in accessibility menu to dismiss all bubbles. [CHAR_LIMIT=30] -->
<string name="bubble_bar_action_dismiss_all">Dismiss all</string>
</resources>

View File

@@ -30,6 +30,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.LayoutDirection;
@@ -38,6 +39,7 @@ import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import androidx.dynamicanimation.animation.SpringForce;
@@ -367,6 +369,47 @@ public class BubbleBarView extends FrameLayout {
}
}
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfoInternal(info);
// Always show only expand action as the menu is only for collapsed bubble bar
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_dismiss_all,
getResources().getString(R.string.bubble_bar_action_dismiss_all)));
if (mBubbleBarLocation.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,
@androidx.annotation.Nullable Bundle arguments) {
if (super.performAccessibilityActionInternal(action, arguments)) {
return true;
}
if (action == AccessibilityNodeInfo.ACTION_EXPAND) {
mController.expandBubbleBar();
return true;
}
if (action == R.id.action_dismiss_all) {
mController.dismissBubbleBar();
return true;
}
if (action == R.id.action_move_left) {
mController.updateBubbleBarLocation(BubbleBarLocation.LEFT);
return true;
}
if (action == R.id.action_move_right) {
mController.updateBubbleBarLocation(BubbleBarLocation.RIGHT);
return true;
}
return false;
}
@SuppressLint("RtlHardcoded")
private void onBubbleBarLocationChanged() {
final boolean onLeft = mBubbleBarLocation.isOnLeft(isLayoutRtl());
@@ -1382,5 +1425,14 @@ public class BubbleBarView extends FrameLayout {
/** Notifies the controller that the bubble bar was touched while it was animating. */
void onBubbleBarTouchedWhileAnimating();
/** Requests the controller to expand bubble bar */
void expandBubbleBar();
/** Requests the controller to dismiss the bubble bar */
void dismissBubbleBar();
/** Requests the controller to update bubble bar location to the given value */
void updateBubbleBarLocation(BubbleBarLocation location);
}
}

View File

@@ -117,7 +117,7 @@ public class BubbleBarViewController {
dp -> onBubbleBarConfigurationChanged(/* animate= */ true));
mBubbleBarScale.updateValue(1f);
mBubbleClickListener = v -> onBubbleClicked((BubbleView) v);
mBubbleBarClickListener = v -> onBubbleBarClicked();
mBubbleBarClickListener = v -> expandBubbleBar();
mBubbleDragController.setupBubbleBarView(mBarView);
mBarView.setOnClickListener(mBubbleBarClickListener);
mBarView.addOnLayoutChangeListener(
@@ -137,6 +137,21 @@ public class BubbleBarViewController {
public void onBubbleBarTouchedWhileAnimating() {
BubbleBarViewController.this.onBubbleBarTouchedWhileAnimating();
}
@Override
public void expandBubbleBar() {
BubbleBarViewController.this.expandBubbleBar();
}
@Override
public void dismissBubbleBar() {
onDismissAllBubbles();
}
@Override
public void updateBubbleBarLocation(BubbleBarLocation location) {
mBubbleBarController.updateBubbleBarLocation(location);
}
});
}
@@ -162,7 +177,7 @@ public class BubbleBarViewController {
mBubbleStashController.onNewBubbleAnimationInterrupted(false, mBarView.getTranslationY());
}
private void onBubbleBarClicked() {
private void expandBubbleBar() {
if (mShouldShowEducation) {
mShouldShowEducation = false;
// Get the bubble bar bounds on screen
@@ -609,17 +624,17 @@ public class BubbleBarViewController {
}
/**
* Called when bubble was dragged into the dismiss target. Notifies System
* Called when given bubble was dismissed. Notifies SystemUI
* @param bubble dismissed bubble item
*/
public void onDismissBubbleWhileDragging(@NonNull BubbleBarItem bubble) {
public void onDismissBubble(@NonNull BubbleBarItem bubble) {
mSystemUiProxy.dragBubbleToDismiss(bubble.getKey(), mTimeSource.currentTimeMillis());
}
/**
* Called when bubble stack was dragged into the dismiss target
* Called when bubble stack was dismissed
*/
public void onDismissAllBubblesWhileDragging() {
public void onDismissAllBubbles() {
mSystemUiProxy.removeAllBubbles();
}

View File

@@ -143,10 +143,10 @@ public class BubbleDismissController {
if (mMagnetizedObject.getUnderlyingObject() instanceof BubbleView) {
BubbleView bubbleView = (BubbleView) mMagnetizedObject.getUnderlyingObject();
if (bubbleView.getBubble() != null) {
mBubbleBarViewController.onDismissBubbleWhileDragging(bubbleView.getBubble());
mBubbleBarViewController.onDismissBubble(bubbleView.getBubble());
}
} else if (mMagnetizedObject.getUnderlyingObject() instanceof BubbleBarView) {
mBubbleBarViewController.onDismissAllBubblesWhileDragging();
mBubbleBarViewController.onDismissAllBubbles();
}
}