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

Commit e05fd23c authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "Rename navigation icon hints to NavbarFlags" into main

parents 8ed28284 4c3eb117
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -205,31 +205,31 @@ public class StatusBarManager {
     *
     * @hide
     */
    public static final int NAVIGATION_HINT_BACK_DISMISS_IME = 1 << 0;
    public static final int NAVBAR_BACK_DISMISS_IME = 1 << 0;
    /**
     * The IME is visible.
     *
     * @hide
     */
    public static final int NAVIGATION_HINT_IME_VISIBLE = 1 << 1;
    public static final int NAVBAR_IME_VISIBLE = 1 << 1;
    /**
     * The IME Switcher button is visible. This only takes effect while the IME is visible.
     *
     * @hide
     */
    public static final int NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE = 1 << 2;
    public static final int NAVBAR_IME_SWITCHER_BUTTON_VISIBLE = 1 << 2;
    /**
     * Navigation bar flags related to the IME state.
     * Navigation bar state flags.
     *
     * @hide
     */
    @IntDef(flag = true, prefix = { "NAVIGATION_HINT_" }, value = {
            NAVIGATION_HINT_BACK_DISMISS_IME,
            NAVIGATION_HINT_IME_VISIBLE,
            NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE,
    @IntDef(flag = true, prefix = { "NAVBAR_" }, value = {
            NAVBAR_BACK_DISMISS_IME,
            NAVBAR_IME_VISIBLE,
            NAVBAR_IME_SWITCHER_BUTTON_VISIBLE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface NavigationHint {}
    public @interface NavbarFlags {}

    /** @hide */
    public static final int WINDOW_STATUS_BAR = 1;
@@ -1355,18 +1355,18 @@ public class StatusBarManager {

    /** @hide */
    @NonNull
    public static String navigationHintsToString(@NavigationHint int hints) {
        final var hintStrings = new ArrayList<String>();
        if ((hints & NAVIGATION_HINT_BACK_DISMISS_IME) != 0) {
            hintStrings.add("NAVIGATION_HINT_BACK_DISMISS_IME");
    public static String navbarFlagsToString(@NavbarFlags int flags) {
        final var flagStrings = new ArrayList<String>();
        if ((flags & NAVBAR_BACK_DISMISS_IME) != 0) {
            flagStrings.add("NAVBAR_BACK_DISMISS_IME");
        }
        if ((hints & NAVIGATION_HINT_IME_VISIBLE) != 0) {
            hintStrings.add("NAVIGATION_HINT_IME_VISIBLE");
        if ((flags & NAVBAR_IME_VISIBLE) != 0) {
            flagStrings.add("NAVBAR_IME_VISIBLE");
        }
        if ((hints & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0) {
            hintStrings.add("NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE");
        if ((flags & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0) {
            flagStrings.add("NAVBAR_IME_SWITCHER_BUTTON_VISIBLE");
        }
        return String.join(" | ", hintStrings);
        return String.join(" | ", flagStrings);
    }

    /** @hide */
+11 −11
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package android.inputmethodservice;

import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_VISIBLE;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_IME_VISIBLE;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;

@@ -242,11 +242,11 @@ final class NavigationBarController {
                        NavigationBarView.class::isInstance);
                if (navigationBarView != null) {
                    // TODO(b/213337792): Support InputMethodService#setBackDisposition().
                    // TODO(b/213337792): Set NAVIGATION_HINT_IME_VISIBLE only when necessary.
                    final int hints = NAVIGATION_HINT_BACK_DISMISS_IME | NAVIGATION_HINT_IME_VISIBLE
                    // TODO(b/213337792): Set NAVBAR_IME_VISIBLE only when necessary.
                    final int flags = NAVBAR_BACK_DISMISS_IME | NAVBAR_IME_VISIBLE
                            | (mShouldShowImeSwitcherWhenImeIsShown
                                    ? NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE : 0);
                    navigationBarView.setNavigationIconHints(hints);
                                    ? NAVBAR_IME_SWITCHER_BUTTON_VISIBLE : 0);
                    navigationBarView.setNavbarFlags(flags);
                    navigationBarView.prepareNavButtons(this);
                }
            } else {
@@ -515,11 +515,11 @@ final class NavigationBarController {
                        NavigationBarView.class::isInstance);
                if (navigationBarView != null) {
                    // TODO(b/213337792): Support InputMethodService#setBackDisposition().
                    // TODO(b/213337792): Set NAVIGATION_HINT_IME_VISIBLE only when necessary.
                    final int hints = NAVIGATION_HINT_BACK_DISMISS_IME | NAVIGATION_HINT_IME_VISIBLE
                    // TODO(b/213337792): Set NAVBAR_IME_VISIBLE only when necessary.
                    final int flags = NAVBAR_BACK_DISMISS_IME | NAVBAR_IME_VISIBLE
                            | (mShouldShowImeSwitcherWhenImeIsShown
                                    ? NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE : 0);
                    navigationBarView.setNavigationIconHints(hints);
                                    ? NAVBAR_IME_SWITCHER_BUTTON_VISIBLE : 0);
                    navigationBarView.setNavbarFlags(flags);
                }
            } else {
                uninstallNavigationBarFrameIfNecessary();
+15 −17
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.inputmethodservice.navigationbar;

import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
import static android.inputmethodservice.navigationbar.NavigationBarConstants.DARK_MODE_ICON_COLOR_SINGLE_TONE;
import static android.inputmethodservice.navigationbar.NavigationBarConstants.LIGHT_MODE_ICON_COLOR_SINGLE_TONE;
import static android.inputmethodservice.navigationbar.NavigationBarConstants.NAVBAR_BACK_BUTTON_IME_OFFSET;
@@ -30,7 +30,7 @@ import android.annotation.DrawableRes;
import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.app.StatusBarManager;
import android.app.StatusBarManager.NavigationHint;
import android.app.StatusBarManager.NavbarFlags;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
@@ -66,8 +66,8 @@ public final class NavigationBarView extends FrameLayout {
    private int mCurrentRotation = -1;

    int mDisabledFlags = 0;
    @NavigationHint
    private int mNavigationIconHints = 0;
    @NavbarFlags
    private int mNavbarFlags;
    private final int mNavBarMode = NAV_BAR_MODE_GESTURAL;

    private KeyButtonDrawable mBackIcon;
@@ -245,8 +245,7 @@ public final class NavigationBarView extends FrameLayout {
    }

    private void orientBackButton(KeyButtonDrawable drawable) {
        final boolean isBackDismissIme =
                (mNavigationIconHints & NAVIGATION_HINT_BACK_DISMISS_IME) != 0;
        final boolean isBackDismissIme = (mNavbarFlags & NAVBAR_BACK_DISMISS_IME) != 0;
        final boolean isRtl = mConfiguration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        float degrees = isBackDismissIme ? (isRtl ? 90 : -90) : 0;
        if (drawable.getRotation() == degrees) {
@@ -284,27 +283,26 @@ public final class NavigationBarView extends FrameLayout {
    }

    /**
     * Updates the navigation icons based on {@code hints}.
     * Sets the navigation bar state flags.
     *
     * @param hints bit flags defined in {@link StatusBarManager}.
     * @param flags the navigation bar state flags.
     */
    public void setNavigationIconHints(@NavigationHint int hints) {
        if (hints == mNavigationIconHints) {
    public void setNavbarFlags(@NavbarFlags int flags) {
        if (flags == mNavbarFlags) {
            return;
        }
        final boolean backDismissIme =
                (hints & StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME) != 0;
        final boolean backDismissIme = (flags & StatusBarManager.NAVBAR_BACK_DISMISS_IME) != 0;
        final boolean oldBackDismissIme =
                (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME) != 0;
                (mNavbarFlags & StatusBarManager.NAVBAR_BACK_DISMISS_IME) != 0;
        if (backDismissIme != oldBackDismissIme) {
            //onBackDismissImeChanged(backDismissIme);
        }

        if (DEBUG) {
            android.widget.Toast.makeText(getContext(), "Navigation icon hints = " + hints, 500)
            android.widget.Toast.makeText(getContext(), "Navbar flags = " + flags, 500)
                    .show();
        }
        mNavigationIconHints = hints;
        mNavbarFlags = flags;
        updateNavButtonIcons();
    }

@@ -321,7 +319,7 @@ public final class NavigationBarView extends FrameLayout {
        // Update IME switcher button visibility, a11y and rotate button always overrides
        // the appearance.
        final boolean isImeSwitcherButtonVisible =
                (mNavigationIconHints & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0;
                (mNavbarFlags & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0;
        getImeSwitchButton()
                .setVisibility(isImeSwitcherButtonVisible ? View.VISIBLE : View.INVISIBLE);

+31 −41
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package com.android.systemui.navigationbar.views;

import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_VISIBLE;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_IME_VISIBLE;
import static android.inputmethodservice.InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING;
import static android.inputmethodservice.InputMethodService.BACK_DISPOSITION_DEFAULT;
import static android.inputmethodservice.InputMethodService.IME_VISIBLE;
@@ -32,8 +32,8 @@ import static com.android.systemui.navigationbar.views.NavigationBar.NavBarActio
import static com.android.systemui.navigationbar.views.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS;
import static com.android.systemui.navigationbar.views.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BACK_DISMISS_IME;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_VISIBLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SWITCHER_BUTTON_VISIBLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_VISIBLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;

import static com.google.common.truth.Truth.assertThat;
@@ -569,31 +569,27 @@ public class NavigationBarTest extends SysuiTestCase {
        externalNavBar.init();

        defaultNavBar.setImeWindowStatus(DEFAULT_DISPLAY, IME_VISIBLE,
                BACK_DISPOSITION_DEFAULT, true);
                BACK_DISPOSITION_DEFAULT, true /* showImeSwitcher */);

        // Verify IME window state will be updated in default NavBar & external NavBar state reset.
        assertEquals(NAVIGATION_HINT_BACK_DISMISS_IME | NAVIGATION_HINT_IME_VISIBLE
                        | NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE,
                defaultNavBar.getNavigationIconHints());
        assertFalse((externalNavBar.getNavigationIconHints()
                & NAVIGATION_HINT_BACK_DISMISS_IME) != 0);
        assertFalse((externalNavBar.getNavigationIconHints() & NAVIGATION_HINT_IME_VISIBLE) != 0);
        assertFalse((externalNavBar.getNavigationIconHints()
                & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0);
        assertEquals(NAVBAR_BACK_DISMISS_IME | NAVBAR_IME_VISIBLE
                        | NAVBAR_IME_SWITCHER_BUTTON_VISIBLE,
                defaultNavBar.getNavbarFlags());
        assertFalse((externalNavBar.getNavbarFlags() & NAVBAR_BACK_DISMISS_IME) != 0);
        assertFalse((externalNavBar.getNavbarFlags() & NAVBAR_IME_VISIBLE) != 0);
        assertFalse((externalNavBar.getNavbarFlags() & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0);

        externalNavBar.setImeWindowStatus(EXTERNAL_DISPLAY_ID, IME_VISIBLE,
                BACK_DISPOSITION_DEFAULT, true);
                BACK_DISPOSITION_DEFAULT, true /* showImeSwitcher */);
        defaultNavBar.setImeWindowStatus(DEFAULT_DISPLAY, 0 /* vis */,
                BACK_DISPOSITION_DEFAULT, false);
                BACK_DISPOSITION_DEFAULT, false /* showImeSwitcher */);
        // Verify IME window state will be updated in external NavBar & default NavBar state reset.
        assertEquals(NAVIGATION_HINT_BACK_DISMISS_IME | NAVIGATION_HINT_IME_VISIBLE
                        | NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE,
                externalNavBar.getNavigationIconHints());
        assertFalse((defaultNavBar.getNavigationIconHints()
                & NAVIGATION_HINT_BACK_DISMISS_IME) != 0);
        assertFalse((defaultNavBar.getNavigationIconHints() & NAVIGATION_HINT_IME_VISIBLE) != 0);
        assertFalse((defaultNavBar.getNavigationIconHints()
                & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0);
        assertEquals(NAVBAR_BACK_DISMISS_IME | NAVBAR_IME_VISIBLE
                        | NAVBAR_IME_SWITCHER_BUTTON_VISIBLE,
                externalNavBar.getNavbarFlags());
        assertFalse((defaultNavBar.getNavbarFlags() & NAVBAR_BACK_DISMISS_IME) != 0);
        assertFalse((defaultNavBar.getNavbarFlags() & NAVBAR_IME_VISIBLE) != 0);
        assertFalse((defaultNavBar.getNavbarFlags() & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0);
    }

    @Test
@@ -608,35 +604,29 @@ public class NavigationBarTest extends SysuiTestCase {

        // Verify navbar altered back icon when an app is showing IME
        mNavigationBar.setImeWindowStatus(DEFAULT_DISPLAY, IME_VISIBLE,
                BACK_DISPOSITION_DEFAULT, true);
        assertTrue((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_BACK_DISMISS_IME) != 0);
        assertTrue((mNavigationBar.getNavigationIconHints() & NAVIGATION_HINT_IME_VISIBLE) != 0);
        assertTrue((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0);
                BACK_DISPOSITION_DEFAULT, true /* showImeSwitcher */);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_BACK_DISMISS_IME) != 0);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_IME_VISIBLE) != 0);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0);

        // Verify navbar didn't alter and showing back icon when the keyguard is showing without
        // requesting IME insets visible.
        doReturn(true).when(mKeyguardStateController).isShowing();
        mNavigationBar.setImeWindowStatus(DEFAULT_DISPLAY, IME_VISIBLE,
                BACK_DISPOSITION_DEFAULT, true);
        assertFalse((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_BACK_DISMISS_IME) != 0);
        assertFalse((mNavigationBar.getNavigationIconHints() & NAVIGATION_HINT_IME_VISIBLE) != 0);
        assertFalse((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0);
                BACK_DISPOSITION_DEFAULT, true /* showImeSwitcher */);
        assertFalse((mNavigationBar.getNavbarFlags() & NAVBAR_BACK_DISMISS_IME) != 0);
        assertFalse((mNavigationBar.getNavbarFlags() & NAVBAR_IME_VISIBLE) != 0);
        assertFalse((mNavigationBar.getNavbarFlags() & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0);

        // Verify navbar altered and showing back icon when the keyguard is showing and
        // requesting IME insets visible.
        windowInsets = new WindowInsets.Builder().setVisible(ime(), true).build();
        doReturn(windowInsets).when(mockShadeWindowView).getRootWindowInsets();
        mNavigationBar.setImeWindowStatus(DEFAULT_DISPLAY, IME_VISIBLE,
                BACK_DISPOSITION_DEFAULT, true);
        assertTrue((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_BACK_DISMISS_IME) != 0);
        assertTrue((mNavigationBar.getNavigationIconHints() & NAVIGATION_HINT_IME_VISIBLE) != 0);
        assertTrue((mNavigationBar.getNavigationIconHints()
                & NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE) != 0);
                BACK_DISPOSITION_DEFAULT, true /* showImeSwitcher */);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_BACK_DISMISS_IME) != 0);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_IME_VISIBLE) != 0);
        assertTrue((mNavigationBar.getNavbarFlags() & NAVBAR_IME_SWITCHER_BUTTON_VISIBLE) != 0);
    }

    @Test
+17 −17
Original line number Diff line number Diff line
@@ -16,12 +16,12 @@

package com.android.systemui.shared.recents.utilities;

import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_VISIBLE;
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_IME_VISIBLE;

import android.annotation.TargetApi;
import android.app.StatusBarManager.NavigationHint;
import android.app.StatusBarManager.NavbarFlags;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
@@ -104,46 +104,46 @@ public class Utilities {
    }

    /**
     * Gets the updated navigation icon hints, based on the current ones and the given IME state.
     * Updates the navigation bar state flags with the given IME state.
     *
     * @param oldHints        current navigation icon hints.
     * @param oldFlags        current navigation bar state flags.
     * @param backDisposition the IME back disposition mode. Only takes effect if
     *                        {@code isImeVisible} is {@code true}.
     * @param isImeVisible    whether the IME is currently visible.
     * @param showImeSwitcher whether the IME Switcher button should be shown. Only takes effect if
     *                        {@code isImeVisible} is {@code true}.
     */
    @NavigationHint
    public static int calculateNavigationIconHints(@NavigationHint int oldHints,
    @NavbarFlags
    public static int updateNavbarFlagsFromIme(@NavbarFlags int oldFlags,
            @BackDispositionMode int backDisposition, boolean isImeVisible,
            boolean showImeSwitcher) {
        int hints = oldHints;
        int flags = oldFlags;
        switch (backDisposition) {
            case InputMethodService.BACK_DISPOSITION_DEFAULT:
            case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
            case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
                if (isImeVisible) {
                    hints |= NAVIGATION_HINT_BACK_DISMISS_IME;
                    flags |= NAVBAR_BACK_DISMISS_IME;
                } else {
                    hints &= ~NAVIGATION_HINT_BACK_DISMISS_IME;
                    flags &= ~NAVBAR_BACK_DISMISS_IME;
                }
                break;
            case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
                hints &= ~NAVIGATION_HINT_BACK_DISMISS_IME;
                flags &= ~NAVBAR_BACK_DISMISS_IME;
                break;
        }
        if (isImeVisible) {
            hints |= NAVIGATION_HINT_IME_VISIBLE;
            flags |= NAVBAR_IME_VISIBLE;
        } else {
            hints &= ~NAVIGATION_HINT_IME_VISIBLE;
            flags &= ~NAVBAR_IME_VISIBLE;
        }
        if (showImeSwitcher && isImeVisible) {
            hints |= NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
            flags |= NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
        } else {
            hints &= ~NAVIGATION_HINT_IME_SWITCHER_BUTTON_VISIBLE;
            flags &= ~NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
        }

        return hints;
        return flags;
    }

    /** @return whether or not {@param context} represents that of a large screen device or not */
Loading