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

Commit a1012904 authored by Thales Lima's avatar Thales Lima
Browse files

Make hotseat fit one line on tablets

When running on tablets in landscape, the QSB should inline with the hotseat icons. This does that and fixes small bugs that didn't account for the new hotseatBorderSpace.

Bug: 210118169
Test: atest Launcher3Tests:DeviceProfileTest
Test: visual, using HSV and Window
Change-Id: I5a89c5449bf59fde736618151eceaacca443ef67
parent 1b077203
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
    <dimen name="dynamic_grid_hotseat_top_padding">8dp</dimen>
    <dimen name="dynamic_grid_hotseat_bottom_padding">2dp</dimen>
    <dimen name="dynamic_grid_hotseat_bottom_tall_padding">0dp</dimen>
    <dimen name="inline_qsb_bottom_margin">0dp</dimen>

    <!-- Qsb -->
    <!-- Used for adjusting the position of QSB when placed in hotseat. This is a ratio and a higher
+51 −8
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public class DeviceProfile {
    public final boolean isPhone;
    public final boolean transposeLayoutWithOrientation;
    public final boolean isTwoPanels;
    public final boolean isQsbInline;

    // Device properties in current orientation
    public final boolean isLandscape;
@@ -165,6 +166,7 @@ public class DeviceProfile {

    public final float qsbBottomMarginOriginalPx;
    public int qsbBottomMarginPx;
    public int qsbWidth; // only used when isQsbInline

    // All apps
    public Point allAppsBorderSpacePx;
@@ -246,6 +248,7 @@ public class DeviceProfile {
        isPhone = !isTablet;
        isTwoPanels = isTablet && useTwoPanels;


        aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
        boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
        mQsbCenterFactor = context.getResources().getFloat(R.dimen.qsb_center_factor);
@@ -270,7 +273,6 @@ public class DeviceProfile {
            }
        }

        hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
        isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS
                && FeatureFlags.ENABLE_TASKBAR.get();
        if (isTaskbarPresent) {
@@ -333,6 +335,8 @@ public class DeviceProfile {

        workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);

        hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
        isQsbInline = isTablet && isLandscape && !isTwoPanels && hotseatQsbHeight > 0;
        numShownHotseatIcons =
                isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
        numShownAllAppsColumns =
@@ -340,10 +344,17 @@ public class DeviceProfile {
        hotseatBarSizeExtraSpacePx = 0;
        hotseatBarTopPaddingPx =
                res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
        if (isQsbInline) {
            hotseatBarBottomPaddingPx = res.getDimensionPixelSize(R.dimen.inline_qsb_bottom_margin);
            qsbWidth = calculateQsbWidth();
        } else {
            hotseatBarBottomPaddingPx = (isTallDevice ? res.getDimensionPixelSize(
                    R.dimen.dynamic_grid_hotseat_bottom_tall_padding)
                : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
                    : res.getDimensionPixelSize(
                            R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
                    + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
            qsbWidth = 0;
        }
        hotseatBarSidePaddingEndPx =
                res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
        // Add a bit of space between nav bar and hotseat in vertical bar layout.
@@ -472,6 +483,14 @@ public class DeviceProfile {
                new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
    }

    private int calculateQsbWidth() {
        return cellWidthPx * inv.numColumns
                + cellLayoutBorderSpacePx.x * (inv.numColumns - 1)
                - (cellWidthPx - iconSizePx) // left and right cell space
                - iconSizePx * numShownHotseatIcons
                - hotseatBorderSpace * numShownHotseatIcons;
    }

    private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
        if (isVerticalBarLayout()) {
            return 0;
@@ -717,6 +736,11 @@ public class DeviceProfile {

        // Hotseat
        hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics, scale);
        if (isQsbInline) {
            qsbWidth = calculateQsbWidth();
        } else {
            qsbWidth = 0;
        }
        updateHotseatIconSize(iconSizePx);

        if (!isVerticalLayout) {
@@ -895,15 +919,24 @@ public class DeviceProfile {
        } else if (isTaskbarPresent) {
            int hotseatHeight = workspacePadding.bottom;
            int taskbarOffset = getTaskbarOffsetY();
            int additionalLeftSpace = 0;

            // Center the QSB with hotseat and push icons to the right
            if (isQsbInline) {
                additionalLeftSpace = qsbWidth + hotseatBorderSpace;
            }

            int hotseatTopDiff = hotseatHeight - taskbarOffset;

            int endOffset = ApiWrapper.getHotseatEndOffset(context);
            int requiredWidth = iconSizePx * numShownHotseatIcons
                    + hotseatBorderSpace * (numShownHotseatIcons - 1);
                    + hotseatBorderSpace * (numShownHotseatIcons - 1)
                    + additionalLeftSpace;

            int hotseatSize = Math.min(requiredWidth, availableWidthPx - endOffset);
            int sideSpacing = (availableWidthPx - hotseatSize) / 2;
            mHotseatPadding.set(sideSpacing, hotseatTopDiff, sideSpacing, taskbarOffset);
            mHotseatPadding.set(sideSpacing + additionalLeftSpace, hotseatTopDiff, sideSpacing,
                    taskbarOffset);

            if (endOffset > sideSpacing) {
                int diff = Utilities.isRtl(context.getResources())
@@ -936,6 +969,10 @@ public class DeviceProfile {
     * Returns the number of pixels the QSB is translated from the bottom of the screen.
     */
    public int getQsbOffsetY() {
        if (isQsbInline) {
            return hotseatBarBottomPaddingPx;
        }

        int freeSpace = isTaskbarPresent
                ? workspacePadding.bottom
                : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight;
@@ -953,8 +990,12 @@ public class DeviceProfile {
     * Returns the number of pixels the taskbar is translated from the bottom of the screen.
     */
    public int getTaskbarOffsetY() {
        if (isQsbInline) {
            return getQsbOffsetY() + (Math.abs(hotseatQsbHeight - iconSizePx) / 2);
        } else {
            return (getQsbOffsetY() - taskbarSize) / 2;
        }
    }

    /**
     * @return the bounds for which the open folders should be contained within
@@ -1113,6 +1154,8 @@ public class DeviceProfile {
        writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
                hotseatBarSidePaddingEndPx));
        writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
        writer.println(prefix + "\tisQsbInline: " + isQsbInline);
        writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth));

        writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
        writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
+11 −2
Original line number Diff line number Diff line
@@ -173,7 +173,10 @@ public class Hotseat extends CellLayout implements Insettable {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int width = getShortcutsAndWidgets().getMeasuredWidth();
        int width = mActivity.getDeviceProfile().isQsbInline
                ? mActivity.getDeviceProfile().qsbWidth
                : getShortcutsAndWidgets().getMeasuredWidth();

        mQsb.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(mQsbHeight, MeasureSpec.EXACTLY));
    }
@@ -183,7 +186,13 @@ public class Hotseat extends CellLayout implements Insettable {
        super.onLayout(changed, l, t, r, b);

        int qsbWidth = mQsb.getMeasuredWidth();
        int left = (r - l - qsbWidth) / 2;
        int left;
        if (mActivity.getDeviceProfile().isQsbInline) {
            int qsbSpace = mActivity.getDeviceProfile().hotseatBorderSpace;
            left = l + getPaddingLeft() - qsbWidth - qsbSpace;
        } else {
            left = (r - l - qsbWidth) / 2;
        }
        int right = left + qsbWidth;

        int bottom = b - t - mActivity.getDeviceProfile().getQsbOffsetY();
+5 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3;
import static android.view.MotionEvent.ACTION_DOWN;

import static com.android.launcher3.CellLayout.FOLDER;
import static com.android.launcher3.CellLayout.HOTSEAT;
import static com.android.launcher3.CellLayout.WORKSPACE;

import android.app.WallpaperManager;
@@ -146,7 +147,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
            // No need to add padding when cell layout border spacing is present.
            boolean noPaddingX =
                    (dp.cellLayoutBorderSpacePx.x > 0 && mContainerType == WORKSPACE)
                            || (dp.folderCellLayoutBorderSpacePx.x > 0 && mContainerType == FOLDER);
                            || (dp.folderCellLayoutBorderSpacePx.x > 0 && mContainerType == FOLDER)
                            || (dp.hotseatBorderSpace > 0 && mContainerType == HOTSEAT);
            int cellPaddingX = noPaddingX
                    ? 0
                    : mContainerType == WORKSPACE
@@ -251,7 +253,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        // While the folder is open, the position of the icon cannot change.
        lp.canReorder = false;
        if (mContainerType == CellLayout.HOTSEAT) {
        if (mContainerType == HOTSEAT) {
            CellLayout cl = (CellLayout) getParent();
            cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
        }
@@ -260,7 +262,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
    @Override
    public void clearFolderLeaveBehind(FolderIcon child) {
        ((CellLayout.LayoutParams) child.getLayoutParams()).canReorder = true;
        if (mContainerType == CellLayout.HOTSEAT) {
        if (mContainerType == HOTSEAT) {
            CellLayout cl = (CellLayout) getParent();
            cl.clearFolderLeaveBehind();
        }
+4 −1
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@ package {
// Source code used for test
filegroup {
    name: "launcher-tests-src",
    srcs: ["src/**/*.java"],
    srcs: [
      "src/**/*.java",
      "src/**/*.kt"
    ],
}

// Source code used for oop test helpers
Loading