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

Commit 3f14afe8 authored by Maitri Mangal's avatar Maitri Mangal
Browse files

Hiding the PiP Menu after 10s of inactivity

Bug: 266670883
Test: manual - took a video (in comment)

Change-Id: I786cc0ec200ce29f77feecbd72a17d2cc8d72e91
parent 60e05d60
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    private TvPipBackgroundView mPipBackgroundView;

    private boolean mIsReloading;
    private static final int PIP_MENU_FORCE_CLOSE_DELAY_MS = 10_000;
    private final Runnable mClosePipMenuRunnable = this::closeMenu;

    @TvPipMenuMode
    private int mCurrentMenuMode = MODE_NO_MENU;
@@ -280,6 +282,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: closeMenu()", TAG);
        requestMenuMode(MODE_NO_MENU);
        mMainHandler.removeCallbacks(mClosePipMenuRunnable);
    }

    @Override
@@ -488,13 +491,17 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis

    private void requestMenuMode(@TvPipMenuMode int menuMode) {
        if (isMenuOpen() == isMenuOpen(menuMode)) {
            if (mMainHandler.hasCallbacks(mClosePipMenuRunnable)) {
                mMainHandler.removeCallbacks(mClosePipMenuRunnable);
                mMainHandler.postDelayed(mClosePipMenuRunnable, PIP_MENU_FORCE_CLOSE_DELAY_MS);
            }
            // No need to request a focus change. We can directly switch to the new mode.
            switchToMenuMode(menuMode);
        } else {
            if (isMenuOpen(menuMode)) {
                mMainHandler.postDelayed(mClosePipMenuRunnable, PIP_MENU_FORCE_CLOSE_DELAY_MS);
                mMenuModeOnFocus = menuMode;
            }

            // Send a request to gain window focus if the menu is open, or lose window focus
            // otherwise. Once the focus change happens, we will request the new mode in the
            // callback {@link #onPipWindowFocusChanged}.
@@ -583,6 +590,14 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
        requestMenuMode(isInMoveMode() ? mPrevMenuMode : MODE_NO_MENU);
    }

    @Override
    public void onUserInteracting() {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onUserInteracting - mCurrentMenuMode=%s", TAG, getMenuModeString());
        mMainHandler.removeCallbacks(mClosePipMenuRunnable);
        mMainHandler.postDelayed(mClosePipMenuRunnable, PIP_MENU_FORCE_CLOSE_DELAY_MS);

    }
    @Override
    public void onPipMovement(int keycode) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+22 −14
Original line number Diff line number Diff line
@@ -491,30 +491,33 @@ public class TvPipMenuView extends FrameLayout implements TvPipActionsProvider.L
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == ACTION_UP) {

            if (event.getKeyCode() == KEYCODE_BACK) {
                mListener.onExitCurrentMenuMode();
                return true;
            }

            if (mCurrentMenuMode == MODE_MOVE_MENU && !mA11yManager.isEnabled()) {
            switch (event.getKeyCode()) {
                case KEYCODE_DPAD_UP:
                case KEYCODE_DPAD_DOWN:
                case KEYCODE_DPAD_LEFT:
                case KEYCODE_DPAD_RIGHT:
                    mListener.onUserInteracting();
                    if (mCurrentMenuMode == MODE_MOVE_MENU && !mA11yManager.isEnabled()) {
                        mListener.onPipMovement(event.getKeyCode());
                        return true;
                    }
                    break;
                case KEYCODE_ENTER:
                case KEYCODE_DPAD_CENTER:
                    mListener.onUserInteracting();
                    if (mCurrentMenuMode == MODE_MOVE_MENU && !mA11yManager.isEnabled()) {
                        mListener.onExitCurrentMenuMode();
                        return true;
                    }
                    break;
                default:
                    // Dispatch key event as normal below
            }
        }
        }

        return super.dispatchKeyEvent(event);
    }

@@ -636,6 +639,11 @@ public class TvPipMenuView extends FrameLayout implements TvPipActionsProvider.L

    interface Listener {

        /**
         * Called when any button (that affects the menu) on current menu mode was pressed.
         */
        void onUserInteracting();

        /**
         * Called when a button for exiting the current menu mode was pressed.
         */