diff options
4 files changed, 113 insertions, 69 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java index 917eaa061d1b..46b8e6098273 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java @@ -234,11 +234,12 @@ public class TvPipController implements PipTransitionController.PipTransitionCal } setState(STATE_PIP_MENU); + mTvPipMenuController.showMenu(); updatePinnedStackBounds(); } @Override - public void closeMenu() { + public void onMenuClosed() { if (DEBUG) { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: closeMenu(), state before=%s", TAG, stateToName(mState)); @@ -285,6 +286,12 @@ public class TvPipController implements PipTransitionController.PipTransitionCal } @Override + public void enterPipMovementMenu() { + setState(STATE_PIP_MENU); + mTvPipMenuController.showMovementMenuOnly(); + } + + @Override public void movePip(int keycode) { if (mTvPipBoundsAlgorithm.updateGravity(keycode)) { mTvPipMenuController.updateGravity(mTvPipBoundsState.getTvPipGravity()); @@ -438,7 +445,7 @@ public class TvPipController implements PipTransitionController.PipTransitionCal } mPipNotificationController.dismiss(); - mTvPipMenuController.hideMenu(); + mTvPipMenuController.closeMenu(); mTvPipBoundsState.resetTvPipState(); setState(STATE_NO_PIP); mPinnedTaskId = NONEXISTENT_TASK_ID; @@ -478,16 +485,6 @@ public class TvPipController implements PipTransitionController.PipTransitionCal TAG, stateToName(state), stateToName(mState)); } mState = state; - - if (mState == STATE_PIP_MENU) { - if (DEBUG) { - ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: > show menu", TAG); - } - mTvPipMenuController.showMenu(); - } - - updatePinnedStackBounds(); } private void loadConfigurations() { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java index b6ae398c1eb9..35c34ac8315f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java @@ -65,6 +65,9 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis // User can actively move the PiP via the DPAD. private boolean mInMoveMode; + // Used when only showing the move menu since we want to close the menu completely when + // exiting the move menu instead of showing the regular button menu. + private boolean mCloseAfterExitMoveMenu; private final List<RemoteAction> mMediaActions = new ArrayList<>(); private final List<RemoteAction> mAppActions = new ArrayList<>(); @@ -102,7 +105,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis final BroadcastReceiver closeSystemDialogsBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - hideMenu(); + closeMenu(); } }; context.registerReceiverForAllUsers(closeSystemDialogsBroadcastReceiver, @@ -155,29 +158,49 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis 0, SHELL_ROOT_LAYER_PIP); } + void showMovementMenuOnly() { + if (DEBUG) { + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, + "%s: showMovementMenuOnly()", TAG); + } + mInMoveMode = true; + mCloseAfterExitMoveMenu = true; + showMenuInternal(); + } + @Override public void showMenu() { if (DEBUG) { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showMenu()", TAG); } + mInMoveMode = false; + mCloseAfterExitMoveMenu = false; + showMenuInternal(); + } - if (mPipMenuView != null) { - Rect menuBounds = getMenuBounds(mTvPipBoundsState.getBounds()); - mSystemWindows.updateViewLayout(mPipMenuView, getPipMenuLayoutParams( - MENU_WINDOW_TITLE, menuBounds.width(), menuBounds.height())); - maybeUpdateMenuViewActions(); - updateExpansionState(); - - SurfaceControl menuSurfaceControl = getSurfaceControl(); - if (menuSurfaceControl != null) { - SurfaceControl.Transaction t = new SurfaceControl.Transaction(); - t.setRelativeLayer(mPipMenuView.getWindowSurfaceControl(), mLeash, 1); - t.setPosition(menuSurfaceControl, menuBounds.left, menuBounds.top); - t.apply(); - } - grantPipMenuFocus(true); - mPipMenuView.show(mInMoveMode, mDelegate.getPipGravity()); + private void showMenuInternal() { + if (mPipMenuView == null) { + return; + } + Rect menuBounds = getMenuBounds(mTvPipBoundsState.getBounds()); + mSystemWindows.updateViewLayout(mPipMenuView, getPipMenuLayoutParams( + MENU_WINDOW_TITLE, menuBounds.width(), menuBounds.height())); + maybeUpdateMenuViewActions(); + updateExpansionState(); + + SurfaceControl menuSurfaceControl = getSurfaceControl(); + if (menuSurfaceControl != null) { + SurfaceControl.Transaction t = new SurfaceControl.Transaction(); + t.setRelativeLayer(mPipMenuView.getWindowSurfaceControl(), mLeash, 1); + t.setPosition(menuSurfaceControl, menuBounds.left, menuBounds.top); + t.apply(); + } + grantPipMenuFocus(true); + if (mInMoveMode) { + mPipMenuView.showMoveMenu(mDelegate.getPipGravity()); + } else { + mPipMenuView.showButtonMenu(); } } @@ -199,25 +222,18 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis return menuBounds; } - void hideMenu() { - if (!isMenuVisible()) { - if (DEBUG) { - ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: hideMenu() - Menu isn't visible, so don't hide", TAG); - } + void closeMenu() { + if (DEBUG) { + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, + "%s: closeMenu()", TAG); + } + if (mPipMenuView == null) { return; - } else { - if (DEBUG) { - ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: hideMenu()", TAG); - } } - mPipMenuView.hide(); - if (!mInMoveMode) { - grantPipMenuFocus(false); - mDelegate.closeMenu(); - } + mPipMenuView.hideAll(); + grantPipMenuFocus(false); + mDelegate.onMenuClosed(); } boolean isInMoveMode() { @@ -228,25 +244,29 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis public void onEnterMoveMode() { if (DEBUG) { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: onEnterMoveMode - %b", TAG, mInMoveMode); + "%s: onEnterMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode, + mCloseAfterExitMoveMenu); } mInMoveMode = true; - mPipMenuView.showMenuButtons(false); - mPipMenuView.showMovementHints(mDelegate.getPipGravity()); - mDelegate.onInMoveModeChanged(); + mPipMenuView.showMoveMenu(mDelegate.getPipGravity()); } @Override public boolean onExitMoveMode() { if (DEBUG) { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: onExitMoveMode - %b", TAG, mInMoveMode); + "%s: onExitMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode, + mCloseAfterExitMoveMenu); + } + if (mCloseAfterExitMoveMenu) { + mInMoveMode = false; + mCloseAfterExitMoveMenu = false; + closeMenu(); + return true; } if (mInMoveMode) { mInMoveMode = false; - mPipMenuView.showMenuButtons(true); - mPipMenuView.hideMovementHints(); - mDelegate.onInMoveModeChanged(); + mPipMenuView.showButtonMenu(); return true; } return false; @@ -266,7 +286,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis @Override public void detach() { - hideMenu(); + closeMenu(); detachPipMenuView(); mLeash = null; } @@ -486,7 +506,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis @Override public void onBackPress() { if (!onExitMoveMode()) { - hideMenu(); + closeMenu(); } } @@ -516,7 +536,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis void togglePipExpansion(); - void closeMenu(); + void onMenuClosed(); void closePip(); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java index 7fdb9ed90875..ccd054aa7680 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java @@ -177,29 +177,43 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { expanded ? R.string.pip_collapse : R.string.pip_expand); } - void show(boolean inMoveMode, int gravity) { + /** + * @param gravity for the arrow hints + */ + void showMoveMenu(int gravity) { if (DEBUG) { - ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: show(), inMoveMode: %b", TAG, inMoveMode); + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showMoveMenu()", TAG); } - if (inMoveMode) { - showMovementHints(gravity); - } else { - animateAlphaTo(1, mActionButtonsContainer); + showMenuButtons(false); + showMovementHints(gravity); + showMenuFrame(true); + } + + void showButtonMenu() { + if (DEBUG) { + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showButtonMenu()", TAG); } - animateAlphaTo(1, mMenuFrameView); + showMenuButtons(true); + hideMovementHints(); + showMenuFrame(true); } - void hide() { + /** + * Hides all menu views, including the menu frame. + */ + void hideAll() { if (DEBUG) { - ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: hide()", TAG); + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: hideAll()", TAG); } - animateAlphaTo(0, mActionButtonsContainer); - animateAlphaTo(0, mMenuFrameView); + showMenuButtons(false); hideMovementHints(); + showMenuFrame(false); } private void animateAlphaTo(float alpha, View view) { + if (view.getAlpha() == alpha) { + return; + } view.animate() .alpha(alpha) .setInterpolator(alpha == 0f ? TvPipInterpolators.EXIT : TvPipInterpolators.ENTER) @@ -419,6 +433,10 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { animateAlphaTo(show ? 1 : 0, mActionButtonsContainer); } + private void showMenuFrame(boolean show) { + animateAlphaTo(show ? 1 : 0, mMenuFrameView); + } + interface Listener { void onBackPress(); @@ -426,7 +444,10 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { void onEnterMoveMode(); /** - * @return whether move mode was exited + * Called when a button for exiting move mode was pressed. + * + * @return true if the event was handled or false if the key event should be handled by the + * next receiver. */ boolean onExitMoveMode(); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java index 7bd3ce9c45b2..f9948a274650 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java @@ -56,6 +56,8 @@ public class TvPipNotificationController { "com.android.wm.shell.pip.tv.notification.action.SHOW_PIP_MENU"; private static final String ACTION_CLOSE_PIP = "com.android.wm.shell.pip.tv.notification.action.CLOSE_PIP"; + private static final String ACTION_MOVE_PIP = + "com.android.wm.shell.pip.tv.notification.action.MOVE_PIP"; private final Context mContext; private final PackageManager mPackageManager; @@ -222,6 +224,7 @@ public class TvPipNotificationController { mIntentFilter = new IntentFilter(); mIntentFilter.addAction(ACTION_CLOSE_PIP); mIntentFilter.addAction(ACTION_SHOW_PIP_MENU); + mIntentFilter.addAction(ACTION_MOVE_PIP); } boolean mRegistered = false; @@ -252,6 +255,8 @@ public class TvPipNotificationController { mDelegate.showPictureInPictureMenu(); } else if (ACTION_CLOSE_PIP.equals(action)) { mDelegate.closePip(); + } else if (ACTION_MOVE_PIP.equals(action)) { + mDelegate.enterPipMovementMenu(); } } } @@ -259,5 +264,6 @@ public class TvPipNotificationController { interface Delegate { void showPictureInPictureMenu(); void closePip(); + void enterPipMovementMenu(); } } |