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

Commit 33f8bfba authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Add IME switch button long click support

This adds support for handling long clicking on the IME switch button.
Initially it will behave exactly like short clicking, i.e. show the IME
switcher menu.

Flag: android.view.inputmethod.ime_switcher_revamp
Test: atest
  TaskbarNavButtonControllerTest#testPressImeSwitcher
  TaskbarNavButtonControllerTest#testLongPressImeSwitcher
Bug: 311791923
Change-Id: Ibd0d6bce2bab11511bc082f46731ec86038c8cf8
parent d529345e
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_BACK_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_HOME_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_HOME_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_OVERVIEW_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_OVERVIEW_BUTTON_TAP;
@@ -37,6 +38,7 @@ import android.os.Handler;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.view.inputmethod.Flags;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
@@ -147,7 +149,7 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
                break;
            case BUTTON_IME_SWITCH:
                logEvent(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP);
                showIMESwitcher();
                onImeSwitcherPress();
                break;
            case BUTTON_A11Y:
                logEvent(LAUNCHER_TASKBAR_A11Y_BUTTON_TAP);
@@ -190,6 +192,12 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
                backRecentsLongpress(buttonType);
                return true;
            case BUTTON_IME_SWITCH:
                if (Flags.imeSwitcherRevamp()) {
                    logEvent(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS);
                    onImeSwitcherLongPress();
                    return true;
                }
                return false;
            default:
                return false;
        }
@@ -305,10 +313,14 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
        mSystemUiProxy.onBackPressed();
    }

    private void showIMESwitcher() {
    private void onImeSwitcherPress() {
        mSystemUiProxy.onImeSwitcherPressed();
    }

    private void onImeSwitcherLongPress() {
        mSystemUiProxy.onImeSwitcherLongPress();
    }

    private void notifyA11yClick(boolean longClick) {
        if (longClick) {
            mSystemUiProxy.notifyAccessibilityButtonLongClicked();
+11 −0
Original line number Diff line number Diff line
@@ -228,6 +228,17 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle, SafeCloseable {
        }
    }

    @Override
    public void onImeSwitcherLongPress() {
        if (mSystemUiProxy != null) {
            try {
                mSystemUiProxy.onImeSwitcherLongPress();
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call onImeSwitcherLongPress");
            }
        }
    }

    @Override
    public void setHomeRotationEnabled(boolean enabled) {
        if (mSystemUiProxy != null) {
+22 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_BACK_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_HOME_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_HOME_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_OVERVIEW_BUTTON_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_OVERVIEW_BUTTON_TAP;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y;
@@ -26,6 +28,7 @@ import static org.mockito.Mockito.when;

import android.os.Handler;
import android.view.View;
import android.view.inputmethod.Flags;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
@@ -109,8 +112,27 @@ public class TaskbarNavButtonControllerTest {

    @Test
    public void testPressImeSwitcher() {
        mNavButtonController.init(mockTaskbarControllers);
        mNavButtonController.onButtonClick(BUTTON_IME_SWITCH, mockView);
        verify(mockStatsLogger, times(1)).log(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP);
        verify(mockStatsLogger, never()).log(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS);
        verify(mockSystemUiProxy, times(1)).onImeSwitcherPressed();
        verify(mockSystemUiProxy, never()).onImeSwitcherLongPress();
    }

    @Test
    public void testLongPressImeSwitcher() {
        mNavButtonController.init(mockTaskbarControllers);
        mNavButtonController.onButtonLongClick(BUTTON_IME_SWITCH, mockView);
        verify(mockStatsLogger, never()).log(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP);
        verify(mockSystemUiProxy, never()).onImeSwitcherPressed();
        if (Flags.imeSwitcherRevamp()) {
            verify(mockStatsLogger, times(1)).log(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS);
            verify(mockSystemUiProxy, times(1)).onImeSwitcherLongPress();
        } else {
            verify(mockStatsLogger, never()).log(LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS);
            verify(mockSystemUiProxy, never()).onImeSwitcherLongPress();
        }
    }

    @Test
+3 −0
Original line number Diff line number Diff line
@@ -795,6 +795,9 @@ public class StatsLogManager implements ResourceBasedOverride {
        @UiEvent(doc = "User launches Overview from meta+tab keyboard shortcut")
        LAUNCHER_OVERVIEW_SHOW_OVERVIEW_FROM_KEYBOARD_SHORTCUT(1765),

        @UiEvent(doc = "User long pressed on the taskbar IME switcher button")
        LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_LONGPRESS(1798),

        // ADD MORE
        ;