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

Commit 78a2dd66 authored by Pat Manning's avatar Pat Manning Committed by Android (Google) Code Review
Browse files

Merge "Close allapps on press of ESC key." into main

parents 2e1b2870 a7a04fe9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -118,6 +118,15 @@ public class TaskbarOverlayDragLayer extends
                topView.onBackInvoked();
                return true;
            }
        } else if (event.getAction() == KeyEvent.ACTION_DOWN
                && event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) {
            // Ignore escape if pressed in conjunction with any modifier keys. Close each
            // floating view one at a time for each key press.
            AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mActivity);
            if (topView != null) {
                topView.close(/* animate= */ true);
                return true;
            }
        }
        return super.dispatchKeyEvent(event);
    }
+17 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.view.KeyboardShortcutGroup;
import android.view.KeyboardShortcutInfo;
import android.view.Menu;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -108,14 +109,26 @@ public class KeyboardShortcutsDelegate {
     * @see android.view.KeyEvent
     */
    public Boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
            // Close any open floating views.
            mLauncher.closeOpenViews();
        // Ignore escape if pressed in conjunction with any modifier keys.
        if (keyCode == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) {
            AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mLauncher);
            if (topView != null) {
                // Close each floating view one at a time for each key press.
                topView.close(/* animate= */ true);
                return true;
            } else if (mLauncher.getAppsView().isInAllApps()) {
                // Close all apps if there are no open floating views.
                closeAllApps();
                return true;
            }
        }
        return null;
    }

    private void closeAllApps() {
        mLauncher.getStateManager().goToState(NORMAL, true);
    }

    /**
     * Handle key up event.
     * @param keyCode code of the key being pressed.
+6 −0
Original line number Diff line number Diff line
@@ -217,4 +217,10 @@ public class TaplOpenCloseAllApps extends AbstractLauncherUiTest {
        mLauncher.getWorkspace();
        waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
    }

    @Test
    public void testDismissAllAppsWithEscKey() {
        mLauncher.goHome().switchToAllApps().dismissByEscKey();
        waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.launcher3.tapl;

import static android.view.KeyEvent.KEYCODE_ESCAPE;
import static android.view.KeyEvent.KEYCODE_META_RIGHT;

import static com.android.launcher3.tapl.LauncherInstrumentation.DEFAULT_POLL_INTERVAL;
@@ -39,6 +40,7 @@ import com.android.launcher3.testing.shared.TestProtocol;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
@@ -53,6 +55,11 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer

    private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background";

    private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile(
            "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_ESCAPE.*?metaState=0");
    private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile(
            "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_ESCAPE.*?metaState=0");

    private final int mHeight;
    private final int mIconHeight;

@@ -383,6 +390,19 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer
        }
    }

    /** Presses the esc key to dismiss AllApps. */
    public void dismissByEscKey() {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN);
            mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP);
            mLauncher.getDevice().pressKeyCode(KEYCODE_ESCAPE);
            try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                    "pressed esc key")) {
                verifyVisibleContainerOnDismiss();
            }
        }
    }

    protected abstract void verifyVisibleContainerOnDismiss();

    /**