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

Commit d6c51475 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Landscape 3 button nav on taskbar phone supported

* TODO: Seascape bar positioning, add tests

Change-Id: I542be2f2f682d8c8a9cdd9bb6c667c44ca167f3e
Merged-In: I542be2f2f682d8c8a9cdd9bb6c667c44ca167f3e
parent 126d1783
Loading
Loading
Loading
Loading
+105 −120
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.Utilities.getDescendantCoordRelativeToAncestor;
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.SYSUI_SURFACE_PROGRESS_INDEX;
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneButtonNavMode;
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BACK;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME;
@@ -54,6 +53,7 @@ import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Region.Op;
@@ -81,6 +81,9 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AlphaUpdateListener;
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton;
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory;
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter;
import com.android.launcher3.util.DimensionUtils;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.views.BaseDragLayer;
@@ -181,6 +184,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
    private final ViewTreeObserver.OnComputeInternalInsetsListener mSeparateWindowInsetsComputer =
            this::onComputeInsetsForSeparateWindow;
    private final RecentsHitboxExtender mHitboxExtender = new RecentsHitboxExtender();
    private View mRecentsButton;

    public NavbarButtonsViewController(TaskbarActivityContext context, FrameLayout navButtonsView) {
        mContext = context;
@@ -203,11 +207,11 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
        boolean isThreeButtonNav = mContext.isThreeButtonNav();
        DeviceProfile deviceProfile = mContext.getDeviceProfile();
        Resources resources = mContext.getResources();
        mNavButtonsView.getLayoutParams().height = !isPhoneMode(deviceProfile) ?
                mContext.isUserSetupComplete()
                        ? deviceProfile.taskbarSize
                        : resources.getDimensionPixelSize(R.dimen.taskbar_suw_frame)
                : resources.getDimensionPixelSize(R.dimen.taskbar_size);
        Point p = !mContext.isUserSetupComplete()
                ? new Point(0, resources.getDimensionPixelSize(R.dimen.taskbar_suw_frame))
                : DimensionUtils.getTaskbarPhoneDimensions(deviceProfile, resources,
                        TaskbarManager.isPhoneMode(deviceProfile));
        mNavButtonsView.getLayoutParams().height = p.y;

        mIsImeRenderingNavButtons =
                InputMethodService.canImeRenderGesturalNavButtons() && mContext.imeDrawsImeNavBar();
@@ -268,81 +272,6 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
                    mControllers.navButtonController);
            updateButtonLayoutSpacing();
            updateStateForFlag(FLAG_SMALL_SCREEN, isPhoneButtonNavMode(mContext));
            if (isInSetup) {
                handleSetupUi();

                // Hide back button in SUW if keyboard is showing (IME draws its own back).
                mPropertyHolders.add(new StatePropertyHolder(
                        mBackButtonAlpha.getProperty(ALPHA_INDEX_SUW),
                        flags -> (flags & FLAG_IME_VISIBLE) == 0));

                // TODO(b/210906568) Dark intensity is currently not propagated during setup, so set
                //  it based on dark theme for now.
                int mode = resources.getConfiguration().uiMode
                        & Configuration.UI_MODE_NIGHT_MASK;
                boolean isDarkTheme = mode == Configuration.UI_MODE_NIGHT_YES;
                mTaskbarNavButtonDarkIntensity.updateValue(isDarkTheme ? 0 : 1);
            } else if (isInKidsMode) {
                int iconSize = resources.getDimensionPixelSize(
                        R.dimen.taskbar_icon_size_kids);
                int buttonWidth = resources.getDimensionPixelSize(
                        R.dimen.taskbar_nav_buttons_width_kids);
                int buttonHeight = resources.getDimensionPixelSize(
                        R.dimen.taskbar_nav_buttons_height_kids);
                int buttonRadius = resources.getDimensionPixelSize(
                        R.dimen.taskbar_nav_buttons_corner_radius_kids);
                int paddingleft = (buttonWidth - iconSize) / 2;
                int paddingRight = paddingleft;
                int paddingTop = (buttonHeight - iconSize) / 2;
                int paddingBottom = paddingTop;

                // Update icons
                ((ImageView) mBackButton).setImageDrawable(
                        mBackButton.getContext().getDrawable(R.drawable.ic_sysbar_back_kids));
                ((ImageView) mBackButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
                mBackButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
                ((ImageView) mHomeButton).setImageDrawable(
                        mHomeButton.getContext().getDrawable(R.drawable.ic_sysbar_home_kids));
                ((ImageView) mHomeButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
                mHomeButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);

                // Home button layout
                LinearLayout.LayoutParams homeLayoutparams = new LinearLayout.LayoutParams(
                        buttonWidth,
                        buttonHeight
                );
                int homeButtonLeftMargin = resources.getDimensionPixelSize(
                        R.dimen.taskbar_home_button_left_margin_kids);
                homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0);
                mHomeButton.setLayoutParams(homeLayoutparams);

                // Back button layout
                LinearLayout.LayoutParams backLayoutParams = new LinearLayout.LayoutParams(
                        buttonWidth,
                        buttonHeight
                );
                int backButtonLeftMargin = resources.getDimensionPixelSize(
                        R.dimen.taskbar_back_button_left_margin_kids);
                backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0);
                mBackButton.setLayoutParams(backLayoutParams);

                // Button backgrounds
                int whiteWith10PctAlpha = Color.argb(0.1f, 1, 1, 1);
                PaintDrawable buttonBackground = new PaintDrawable(whiteWith10PctAlpha);
                buttonBackground.setCornerRadius(buttonRadius);
                mHomeButton.setBackground(buttonBackground);
                mBackButton.setBackground(buttonBackground);

                // Update alignment within taskbar
                FrameLayout.LayoutParams navButtonsLayoutParams = (FrameLayout.LayoutParams)
                        mNavButtonContainer.getLayoutParams();
                navButtonsLayoutParams.setMarginStart(navButtonsLayoutParams.getMarginEnd() / 2);
                navButtonsLayoutParams.setMarginEnd(navButtonsLayoutParams.getMarginStart());
                navButtonsLayoutParams.gravity = Gravity.CENTER;
                mNavButtonContainer.requestLayout();

                mHomeButton.setOnLongClickListener(null);
            }

            // Animate taskbar background when either..
            // notification shade expanded AND not on keyguard
@@ -445,20 +374,20 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
                        (flags & FLAG_DISABLE_HOME) == 0));

        // Recents button
        View recentsButton = addButton(R.drawable.ic_sysbar_recent, BUTTON_RECENTS,
        mRecentsButton = addButton(R.drawable.ic_sysbar_recent, BUTTON_RECENTS,
                navContainer, navButtonController, R.id.recent_apps);
        mHitboxExtender.init(recentsButton, mNavButtonsView, mContext.getDeviceProfile(),
        mHitboxExtender.init(mRecentsButton, mNavButtonsView, mContext.getDeviceProfile(),
                () -> {
                    float[] recentsCoords = new float[2];
                    getDescendantCoordRelativeToAncestor(recentsButton, mNavButtonsView,
                    getDescendantCoordRelativeToAncestor(mRecentsButton, mNavButtonsView,
                            recentsCoords, false);
                    return recentsCoords;
                }, new Handler());
        recentsButton.setOnClickListener(v -> {
        mRecentsButton.setOnClickListener(v -> {
            navButtonController.onButtonClick(BUTTON_RECENTS, v);
            mHitboxExtender.onRecentsButtonClicked();
        });
        mPropertyHolders.add(new StatePropertyHolder(recentsButton,
        mPropertyHolders.add(new StatePropertyHolder(mRecentsButton,
                flags -> (flags & FLAG_KEYGUARD_VISIBLE) == 0 && (flags & FLAG_DISABLE_RECENTS) == 0
                        && !mContext.isNavBarKidsModeActive()));

@@ -773,15 +702,23 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
                || !mContext.isUserSetupComplete()) {
            return;
        }
        DeviceProfile dp = mContext.getDeviceProfile();
        Resources res = mContext.getResources();
        boolean isInSetup = !mContext.isUserSetupComplete();
        // TODO(b/244231596) we're getting the incorrect kidsMode value in small-screen
        boolean isInKidsMode = mContext.isNavBarKidsModeActive();

        if (isPhoneButtonNavMode(mContext)) {
            updatePhoneButtonSpacing();
        if (TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW) {
            boolean isThreeButtonNav = mContext.isThreeButtonNav();

            NavButtonLayoutter navButtonLayoutter =
                    NavButtonLayoutFactory.Companion.getUiLayoutter(
                            dp, mNavButtonsView, res, isInKidsMode, isInSetup, isThreeButtonNav,
                            TaskbarManager.isPhoneMode(dp));
            navButtonLayoutter.layoutButtons(dp, isContextualButtonShowing());
            return;
        }

        DeviceProfile dp = mContext.getDeviceProfile();
        Resources res = mContext.getResources();

        // Add spacing after the end of the last nav button
        FrameLayout.LayoutParams navButtonParams =
                (FrameLayout.LayoutParams) mNavButtonContainer.getLayoutParams();
@@ -816,38 +753,84 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
                buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
            }
        }
    }

    /** Uniformly spaces out the 3 button nav for smaller phone screens */
    private void updatePhoneButtonSpacing() {
        DeviceProfile dp = mContext.getDeviceProfile();
        Resources res = mContext.getResources();
        if (isInSetup) {
            handleSetupUi();

        // TODO: Polish pending, this is just to make it usable
        FrameLayout.LayoutParams navContainerParams =
                (FrameLayout.LayoutParams) mNavButtonContainer.getLayoutParams();
        int endStartMargins = res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size);
        navContainerParams.gravity = Gravity.CENTER;
        navContainerParams.setMarginEnd(endStartMargins);
        navContainerParams.setMarginStart(endStartMargins);
        mNavButtonContainer.setLayoutParams(navContainerParams);
            // Hide back button in SUW if keyboard is showing (IME draws its own back).
            mPropertyHolders.add(new StatePropertyHolder(
                    mBackButtonAlpha.getProperty(ALPHA_INDEX_SUW),
                    flags -> (flags & FLAG_IME_VISIBLE) == 0));

        // Add the spaces in between the nav buttons
        int spaceInBetween = res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone);
        for (int i = 0; i < mNavButtonContainer.getChildCount(); i++) {
            View navButton = mNavButtonContainer.getChildAt(i);
            LinearLayout.LayoutParams buttonLayoutParams =
                    (LinearLayout.LayoutParams) navButton.getLayoutParams();
            buttonLayoutParams.weight = 1;
            if (i == 0) {
                buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
            } else if (i == mNavButtonContainer.getChildCount() - 1) {
                buttonLayoutParams.setMarginStart(spaceInBetween / 2);
            } else {
                buttonLayoutParams.setMarginStart(spaceInBetween / 2);
                buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
            }
            // TODO(b/210906568) Dark intensity is currently not propagated during setup, so set
            //  it based on dark theme for now.
            int mode = res.getConfiguration().uiMode
                    & Configuration.UI_MODE_NIGHT_MASK;
            boolean isDarkTheme = mode == Configuration.UI_MODE_NIGHT_YES;
            mTaskbarNavButtonDarkIntensity.updateValue(isDarkTheme ? 0 : 1);
        } else if (isInKidsMode) {
            int iconSize = res.getDimensionPixelSize(
                    R.dimen.taskbar_icon_size_kids);
            int buttonWidth = res.getDimensionPixelSize(
                    R.dimen.taskbar_nav_buttons_width_kids);
            int buttonHeight = res.getDimensionPixelSize(
                    R.dimen.taskbar_nav_buttons_height_kids);
            int buttonRadius = res.getDimensionPixelSize(
                    R.dimen.taskbar_nav_buttons_corner_radius_kids);
            int paddingleft = (buttonWidth - iconSize) / 2;
            int paddingRight = paddingleft;
            int paddingTop = (buttonHeight - iconSize) / 2;
            int paddingBottom = paddingTop;

            // Update icons
            ((ImageView) mBackButton).setImageDrawable(
                    mBackButton.getContext().getDrawable(R.drawable.ic_sysbar_back_kids));
            ((ImageView) mBackButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
            mBackButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
            ((ImageView) mHomeButton).setImageDrawable(
                    mHomeButton.getContext().getDrawable(R.drawable.ic_sysbar_home_kids));
            ((ImageView) mHomeButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
            mHomeButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);

            // Home button layout
            LinearLayout.LayoutParams homeLayoutparams = new LinearLayout.LayoutParams(
                    buttonWidth,
                    buttonHeight
            );
            int homeButtonLeftMargin = res.getDimensionPixelSize(
                    R.dimen.taskbar_home_button_left_margin_kids);
            homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0);
            mHomeButton.setLayoutParams(homeLayoutparams);

            // Back button layout
            LinearLayout.LayoutParams backLayoutParams = new LinearLayout.LayoutParams(
                    buttonWidth,
                    buttonHeight
            );
            int backButtonLeftMargin = res.getDimensionPixelSize(
                    R.dimen.taskbar_back_button_left_margin_kids);
            backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0);
            mBackButton.setLayoutParams(backLayoutParams);

            // Button backgrounds
            int whiteWith10PctAlpha = Color.argb(0.1f, 1, 1, 1);
            PaintDrawable buttonBackground = new PaintDrawable(whiteWith10PctAlpha);
            buttonBackground.setCornerRadius(buttonRadius);
            mHomeButton.setBackground(buttonBackground);
            mBackButton.setBackground(buttonBackground);

            // Update alignment within taskbar
            FrameLayout.LayoutParams navButtonsLayoutParams = (FrameLayout.LayoutParams)
                    mNavButtonContainer.getLayoutParams();
            navButtonsLayoutParams.setMarginStart(
                    navButtonsLayoutParams.getMarginEnd() / 2);
            navButtonsLayoutParams.setMarginEnd(navButtonsLayoutParams.getMarginStart());
            navButtonsLayoutParams.gravity = Gravity.CENTER;
            mNavButtonContainer.requestLayout();

            mHomeButton.setOnLongClickListener(null);
        }

    }

    public void onDestroy() {
@@ -859,6 +842,8 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT

        moveNavButtonsBackToTaskbarWindow();
        mNavButtonContainer.removeAllViews();
        mEndContextualContainer.removeAllViews();
        mStartContextualContainer.removeAllViews();
        mAllButtons.clear();
    }

+2 −2
Original line number Diff line number Diff line
@@ -101,8 +101,8 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
                    resources.getDimensionPixelSize(R.dimen.taskbar_stashed_small_screen);
        } else {
            mStashedHandleView.getLayoutParams().height = deviceProfile.taskbarSize;
            mStashedHandleWidth =
                    resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width);
            mStashedHandleWidth = resources
                    .getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width);
        }

        mTaskbarStashedHandleAlpha.getProperty(ALPHA_INDEX_STASHED).setValue(
+13 −4
Original line number Diff line number Diff line
@@ -154,6 +154,8 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), 0);
        mIsNavBarForceVisible = settingsCache.getValue(
                Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), 0);
        // TODO(b/244231596) For shared Taskbar window, update this value in init() instead so
        //  to get correct value when recreating the taskbar
        mIsNavBarKidsMode = settingsCache.getValue(
                Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), 0);

@@ -276,9 +278,13 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
     * @param type The window type to pass to the created WindowManager.LayoutParams.
     */
    public WindowManager.LayoutParams createDefaultWindowLayoutParams(int type) {
        DeviceProfile deviceProfile = getDeviceProfile();
        // Taskbar is on the logical bottom of the screen
        boolean isVerticalBarLayout = TaskbarManager.isPhoneMode(deviceProfile) &&
                deviceProfile.isLandscape;
        WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
                MATCH_PARENT,
                mLastRequestedNonFullscreenHeight,
                isVerticalBarLayout ? mLastRequestedNonFullscreenHeight : MATCH_PARENT,
                isVerticalBarLayout ? MATCH_PARENT : mLastRequestedNonFullscreenHeight,
                type,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_SLIPPERY
@@ -286,7 +292,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                PixelFormat.TRANSLUCENT);
        windowLayoutParams.setTitle(WINDOW_TITLE);
        windowLayoutParams.packageName = getPackageName();
        windowLayoutParams.gravity = Gravity.BOTTOM;
        windowLayoutParams.gravity = !isVerticalBarLayout ?
                Gravity.BOTTOM :
                Gravity.END; // TODO(b/230394142): seascape

        windowLayoutParams.setFitInsetsTypes(0);
        windowLayoutParams.receiveInsetsIgnoringZOrder = true;
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
@@ -803,7 +812,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        return mIsUserSetupComplete;
    }

    protected boolean isNavBarKidsModeActive() {
    public boolean isNavBarKidsModeActive() {
        return mIsNavBarKidsMode && isThreeButtonNav();
    }

+8 −3
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@
package com.android.launcher3.taskbar;

import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.ViewTreeObserver;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.util.DimensionUtils;
import com.android.launcher3.util.TouchController;
import com.android.quickstep.AnimatedFloat;

@@ -177,9 +179,12 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
            DeviceProfile deviceProfile = mActivity.getDeviceProfile();
            if (TaskbarManager.isPhoneMode(deviceProfile)) {
                Resources resources = mActivity.getResources();
                return mActivity.isThreeButtonNav() ?
                        resources.getDimensionPixelSize(R.dimen.taskbar_size) :
                        resources.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
                Point taskbarDimensions =
                        DimensionUtils.getTaskbarPhoneDimensions(deviceProfile, resources,
                                TaskbarManager.isPhoneMode(deviceProfile));
                return taskbarDimensions.y == -1 ?
                        deviceProfile.getDisplayInfo().currentSize.y :
                        taskbarDimensions.y;
            } else {
                return deviceProfile.taskbarSize;
            }
+19 −4
Original line number Diff line number Diff line
@@ -84,16 +84,16 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
        val tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        for (provider in windowLayoutParams.providedInsets) {
            if (provider.type == ITYPE_EXTRA_NAVIGATION_BAR) {
                provider.insetsSize = Insets.of(0, 0, 0, contentHeight)
                provider.insetsSize = getInsetsByNavMode(contentHeight)
            } else if (provider.type == ITYPE_BOTTOM_TAPPABLE_ELEMENT
                      || provider.type == ITYPE_BOTTOM_MANDATORY_GESTURES) {
                provider.insetsSize = Insets.of(0, 0, 0, tappableHeight)
                provider.insetsSize = getInsetsByNavMode(tappableHeight)
            }
        }

        val imeInsetsSize = Insets.of(0, 0, 0, taskbarHeightForIme)
        val imeInsetsSize = getInsetsByNavMode(taskbarHeightForIme)
        // Use 0 insets for the VoiceInteractionWindow (assistant) when gesture nav is enabled.
        val visInsetsSize = Insets.of(0, 0, 0, if (context.isGestureNav) 0 else tappableHeight)
        val visInsetsSize = getInsetsByNavMode(if (context.isGestureNav) 0 else tappableHeight)
        val insetsSizeOverride = arrayOf(
            InsetsFrameProvider.InsetsSizeOverride(
                TYPE_INPUT_METHOD,
@@ -109,6 +109,21 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
        }
    }

    /**
     * @return [Insets] where the [bottomInset] is either used as a bottom inset or
     *         right/left inset if using 3 button nav
     */
    private fun getInsetsByNavMode(bottomInset: Int) : Insets {
        val devicePortrait = !context.deviceProfile.isLandscape
        if (!TaskbarManager.isPhoneButtonNavMode(context) || devicePortrait) {
            // Taskbar or portrait phone mode
            return Insets.of(0, 0, 0, bottomInset)
        }

        // TODO(b/230394142): seascape
        return Insets.of(0, 0, bottomInset, 0)
    }

    /**
     * Sets {@param providesInsetsTypes} as the inset types provided by {@param params}.
     * @param params The window layout params.
Loading