PiP: Add stash a11y support.

Bug: 186479769
Test: Use talkback, open up menu, tap on "Stash", see PIP stashes;
tap on "Unstash", see it unstashes

Change-Id: I617f078cee888ea4f592173c67b25d43fb4e9cd1
This commit is contained in:
Ben Lin
2021-05-05 18:28:58 -07:00
parent 0e05cb9d8b
commit 58b79104e7
7 changed files with 51 additions and 6 deletions

View File

@@ -16,6 +16,8 @@
-->
<resources>
<item type="id" name="action_pip_resize" />
<item type="id" name="action_pip_stash" />
<item type="id" name="action_pip_unstash" />
<!-- Accessibility actions for the docked stack divider -->
<item type="id" name="action_move_tl_full" />

View File

@@ -48,6 +48,12 @@
<!-- Accessibility action for resizing PIP [CHAR LIMIT=NONE] -->
<string name="accessibility_action_pip_resize">Resize</string>
<!-- Accessibility action for stashing PIP [CHAR LIMIT=NONE] -->
<string name="accessibility_action_pip_stash">Stash</string>
<!-- Accessibility action for unstashing PIP [CHAR LIMIT=NONE] -->
<string name="accessibility_action_pip_unstash">Unstash</string>
<!-- TODO Deprecated. Label for PIP action to Minimize the PIP. DO NOT TRANSLATE [CHAR LIMIT=25] -->
<string name="pip_phone_minimize">Minimize</string>

View File

@@ -55,7 +55,7 @@ public final class PipBoundsState {
STASH_TYPE_RIGHT
})
@Retention(RetentionPolicy.SOURCE)
@interface StashType {}
public @interface StashType {}
private static final String TAG = PipBoundsState.class.getSimpleName();

View File

@@ -15,6 +15,8 @@
*/
package com.android.wm.shell.pip.phone;
import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE;
import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Rect;
@@ -59,6 +61,7 @@ public class PipAccessibilityInteractionConnection {
private final PipTaskOrganizer mTaskOrganizer;
private final PipSnapAlgorithm mSnapAlgorithm;
private final Runnable mUpdateMovementBoundCallback;
private final Runnable mUnstashCallback;
private final AccessibilityCallbacks mCallbacks;
private final IAccessibilityInteractionConnection mConnectionImpl;
@@ -72,7 +75,7 @@ public class PipAccessibilityInteractionConnection {
@NonNull PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
PipTaskOrganizer taskOrganizer, PipSnapAlgorithm snapAlgorithm,
AccessibilityCallbacks callbacks, Runnable updateMovementBoundCallback,
ShellExecutor mainExcutor) {
Runnable unstashCallback, ShellExecutor mainExcutor) {
mContext = context;
mMainExcutor = mainExcutor;
mPipBoundsState = pipBoundsState;
@@ -80,6 +83,7 @@ public class PipAccessibilityInteractionConnection {
mTaskOrganizer = taskOrganizer;
mSnapAlgorithm = snapAlgorithm;
mUpdateMovementBoundCallback = updateMovementBoundCallback;
mUnstashCallback = unstashCallback;
mCallbacks = callbacks;
mConnectionImpl = new PipAccessibilityInteractionConnectionImpl();
}
@@ -118,6 +122,13 @@ public class PipAccessibilityInteractionConnection {
setToNormalBounds();
}
result = true;
} else if (action == R.id.action_pip_stash) {
mMotionHelper.animateToStashedClosestEdge();
result = true;
} else if (action == R.id.action_pip_unstash) {
mUnstashCallback.run();
mPipBoundsState.setStashed(STASH_TYPE_NONE);
result = true;
} else {
switch (action) {
case AccessibilityNodeInfo.ACTION_CLICK:
@@ -246,6 +257,10 @@ public class PipAccessibilityInteractionConnection {
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_pip_resize,
context.getString(R.string.accessibility_action_pip_resize)));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_pip_stash,
context.getString(R.string.accessibility_action_pip_stash)));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.action_pip_unstash,
context.getString(R.string.accessibility_action_pip_unstash)));
info.setImportantForAccessibility(true);
info.setClickable(true);
info.setVisibleToUser(true);

View File

@@ -21,7 +21,9 @@ import static androidx.dynamicanimation.animation.SpringForce.STIFFNESS_LOW;
import static androidx.dynamicanimation.animation.SpringForce.STIFFNESS_MEDIUM;
import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_EXPAND_OR_UNEXPAND;
import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT;
import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE;
import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT;
import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_DISMISS;
import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_NONE;
@@ -498,6 +500,28 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
}
}
/**
* Animates the PiP to the stashed state, choosing the closest edge.
*/
void animateToStashedClosestEdge() {
Rect tmpBounds = new Rect();
final Rect insetBounds = mPipBoundsState.getDisplayLayout().stableInsets();
final int stashType =
mPipBoundsState.getBounds().left == mPipBoundsState.getMovementBounds().left
? STASH_TYPE_LEFT : STASH_TYPE_RIGHT;
final float leftEdge = stashType == STASH_TYPE_LEFT
? mPipBoundsState.getStashOffset()
- mPipBoundsState.getBounds().width() + insetBounds.left
: mPipBoundsState.getDisplayBounds().right
- mPipBoundsState.getStashOffset() - insetBounds.right;
tmpBounds.set((int) leftEdge,
mPipBoundsState.getBounds().top,
(int) (leftEdge + mPipBoundsState.getBounds().width()),
mPipBoundsState.getBounds().bottom);
resizeAndAnimatePipUnchecked(tmpBounds, UNSTASH_DURATION);
mPipBoundsState.setStashed(stashType);
}
/**
* Animates the PiP from stashed state into un-stashed, popping it out from the edge.
*/

View File

@@ -199,7 +199,8 @@ public class PipTouchHandler {
mainExecutor);
mConnection = new PipAccessibilityInteractionConnection(mContext, pipBoundsState,
mMotionHelper, pipTaskOrganizer, mPipBoundsAlgorithm.getSnapAlgorithm(),
this::onAccessibilityShowMenu, this::updateMovementBounds, mainExecutor);
this::onAccessibilityShowMenu, this::updateMovementBounds,
this::animateToUnStashedState, mainExecutor);
}
public void init() {

View File

@@ -157,9 +157,6 @@
<item type="id" name="accessibility_action_qs_move_to_position" />
<item type="id" name="accessibility_action_qs_add_to_position" />
<!-- Accessibility actions for PIP -->
<item type="id" name="action_pip_resize" />
<!-- Accessibility actions for window magnification. -->
<item type="id" name="accessibility_action_zoom_in"/>
<item type="id" name="accessibility_action_zoom_out"/>