From 58b79104e7e8850d6c9f1fd74934e2aa1f8efaee Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Wed, 5 May 2021 18:28:58 -0700 Subject: [PATCH] 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 --- libs/WindowManager/Shell/res/values/ids.xml | 2 ++ .../Shell/res/values/strings.xml | 6 +++++ .../android/wm/shell/pip/PipBoundsState.java | 2 +- ...PipAccessibilityInteractionConnection.java | 17 ++++++++++++- .../wm/shell/pip/phone/PipMotionHelper.java | 24 +++++++++++++++++++ .../wm/shell/pip/phone/PipTouchHandler.java | 3 ++- packages/SystemUI/res/values/ids.xml | 3 --- 7 files changed, 51 insertions(+), 6 deletions(-) diff --git a/libs/WindowManager/Shell/res/values/ids.xml b/libs/WindowManager/Shell/res/values/ids.xml index 434a000010c43..8831b610f44a5 100644 --- a/libs/WindowManager/Shell/res/values/ids.xml +++ b/libs/WindowManager/Shell/res/values/ids.xml @@ -16,6 +16,8 @@ --> + + diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml index b1425e4eeb287..e512698ab66c0 100644 --- a/libs/WindowManager/Shell/res/values/strings.xml +++ b/libs/WindowManager/Shell/res/values/strings.xml @@ -48,6 +48,12 @@ Resize + + Stash + + + Unstash + Minimize diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java index 561dff0da6ca0..e3674dc920d5d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java @@ -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(); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java index 3b65899364cd5..47a8c67a22e6c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java @@ -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); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index 9401cd6a2954e..15e7f07a1f6c4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -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. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index 0a0798ef24c12..d3e4cf3a835ea 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -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() { diff --git a/packages/SystemUI/res/values/ids.xml b/packages/SystemUI/res/values/ids.xml index bb9d331520438..bdc7bdb2d2f73 100644 --- a/packages/SystemUI/res/values/ids.xml +++ b/packages/SystemUI/res/values/ids.xml @@ -157,9 +157,6 @@ - - -