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

Commit 354d367c authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Create a11y menu for a bubble in bubble bar" into main

parents 72054af8 85d4b8bb
Loading
Loading
Loading
Loading
+40 −7
Original line number Diff line number Diff line
@@ -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());
    }

+1 −1
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class BubbleDragController {
            @Override
            protected void onDragDismiss() {
                mBubblePinController.onDragEnd();
                mBubbleBarViewController.onBubbleDragDismissed(bubbleView);
                mBubbleBarViewController.onBubbleDismissed(bubbleView);
                mBubbleBarViewController.onBubbleDragEnd();
            }

+73 −0
Original line number Diff line number Diff line
@@ -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);
    }
}