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

Commit c92b40f1 authored by Thales Lima's avatar Thales Lima Committed by Android (Google) Code Review
Browse files

Merge "Calculate hotseat width based on available width" into tm-qpr-dev

parents e749617c 9938c2f7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@

    <!--  Taskbar 3 button spacing  -->
    <dimen name="taskbar_button_margin_5_5">94.5dp</dimen>
    <dimen name="taskbar_button_margin_6_5">94.5dp</dimen>
    <dimen name="taskbar_button_margin_6_5">219.6dp</dimen>
    <dimen name="taskbar_button_margin_4_5">84dp</dimen>
    <dimen name="taskbar_button_margin_4_4">79dp</dimen>
</resources>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@
    <!--  Taskbar 3 button spacing  -->
    <dimen name="taskbar_button_space_inbetween">24dp</dimen>
    <dimen name="taskbar_button_margin_5_5">26dp</dimen>
    <dimen name="taskbar_button_margin_6_5">26dp</dimen>
    <dimen name="taskbar_button_margin_6_5">75dp</dimen>
    <dimen name="taskbar_button_margin_4_5">47dp</dimen>
    <dimen name="taskbar_button_margin_4_4">47dp</dimen>
    <dimen name="taskbar_button_margin_default">47dp</dimen>
+14 −14
Original line number Diff line number Diff line
@@ -338,18 +338,18 @@ class DeviceProfileTest : DeviceProfileBaseTest() {
                "\thotseatBarBottomSpacePx: 80.0px (40.0dp)\n" +
                "\thotseatBarSidePaddingStartPx: 0.0px (0.0dp)\n" +
                "\thotseatBarSidePaddingEndPx: 0.0px (0.0dp)\n" +
                "\thotseatBarEndOffset: 597.0px (298.5dp)\n" +
                "\thotseatBarEndOffset: 705.0px (352.5dp)\n" +
                "\thotseatQsbSpace: 64.0px (32.0dp)\n" +
                "\thotseatQsbHeight: 126.0px (63.0dp)\n" +
                "\tspringLoadedHotseatBarTopMarginPx: 128.0px (64.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).top: -8.0px (-4.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).bottom: 73.0px (36.5dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 959.0px (479.5dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 597.0px (298.5dp)\n" +
                "\tnumShownHotseatIcons: 5\n" +
                "\thotseatBorderSpace: 101.0px (50.5dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 954.0px (477.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 705.0px (352.5dp)\n" +
                "\tnumShownHotseatIcons: 6\n" +
                "\thotseatBorderSpace: 36.0px (18.0dp)\n" +
                "\tisQsbInline: true\n" +
                "\thotseatQsbWidth: 855.0px (427.5dp)\n" +
                "\thotseatQsbWidth: 619.0px (309.5dp)\n" +
                "\tisTaskbarPresent:true\n" +
                "\tisTaskbarPresentInApps:true\n" +
                "\ttaskbarSize: 120.0px (60.0dp)\n" +
@@ -578,16 +578,16 @@ class DeviceProfileTest : DeviceProfileBaseTest() {
                "\thotseatBarBottomSpacePx: 72.0px (36.0dp)\n" +
                "\thotseatBarSidePaddingStartPx: 0.0px (0.0dp)\n" +
                "\thotseatBarSidePaddingEndPx: 0.0px (0.0dp)\n" +
                "\thotseatBarEndOffset: 460.0px (230.0dp)\n" +
                "\thotseatBarEndOffset: 558.0px (279.0dp)\n" +
                "\thotseatQsbSpace: 64.0px (32.0dp)\n" +
                "\thotseatQsbHeight: 126.0px (63.0dp)\n" +
                "\tspringLoadedHotseatBarTopMarginPx: 216.0px (108.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).top: 158.0px (79.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).bottom: 65.0px (32.5dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 76.0px (38.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 460.0px (230.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 150.0px (75.0dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 558.0px (279.0dp)\n" +
                "\tnumShownHotseatIcons: 5\n" +
                "\thotseatBorderSpace: 116.0px (58.0dp)\n" +
                "\thotseatBorderSpace: 73.0px (36.5dp)\n" +
                "\tisQsbInline: false\n" +
                "\thotseatQsbWidth: 1300.0px (650.0dp)\n" +
                "\tisTaskbarPresent:true\n" +
@@ -824,10 +824,10 @@ class DeviceProfileTest : DeviceProfileBaseTest() {
                "\tspringLoadedHotseatBarTopMarginPx: 116.0px (44.190475dp)\n" +
                "\tgetHotseatLayoutPadding(context).top: 197.0px (75.04762dp)\n" +
                "\tgetHotseatLayoutPadding(context).bottom: 43.0px (16.380953dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 216.0px (82.28571dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 106.0px (40.38095dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 744.0px (283.42856dp)\n" +
                "\tnumShownHotseatIcons: 6\n" +
                "\thotseatBorderSpace: 61.0px (23.238094dp)\n" +
                "\thotseatBorderSpace: 83.0px (31.619047dp)\n" +
                "\tisQsbInline: false\n" +
                "\thotseatQsbWidth: 1467.0px (558.8571dp)\n" +
                "\tisTaskbarPresent:true\n" +
@@ -1064,10 +1064,10 @@ class DeviceProfileTest : DeviceProfileBaseTest() {
                "\tspringLoadedHotseatBarTopMarginPx: 171.0px (65.14286dp)\n" +
                "\tgetHotseatLayoutPadding(context).top: 219.0px (83.42857dp)\n" +
                "\tgetHotseatLayoutPadding(context).bottom: 87.0px (33.142857dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 128.0px (48.761906dp)\n" +
                "\tgetHotseatLayoutPadding(context).left: 78.0px (29.714285dp)\n" +
                "\tgetHotseatLayoutPadding(context).right: 660.0px (251.42857dp)\n" +
                "\tnumShownHotseatIcons: 6\n" +
                "\thotseatBorderSpace: 47.0px (17.904762dp)\n" +
                "\thotseatBorderSpace: 57.0px (21.714285dp)\n" +
                "\tisQsbInline: false\n" +
                "\thotseatQsbWidth: 1236.0px (470.85715dp)\n" +
                "\tisTaskbarPresent:true\n" +
+163 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep

import android.graphics.Rect
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.launcher3.DeviceProfileBaseTest
import com.android.launcher3.util.WindowBounds
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class HotseatWidthCalculationTest : DeviceProfileBaseTest() {

    /**
     * This is a case when after setting the hotseat, the space needs to be recalculated
     * but it doesn't need to change QSB width or remove icons
     */
    @Test
    fun distribute_border_space_when_space_is_enough_portrait() {
        initializeVarsForTablet(isGestureMode = false)
        windowBounds = WindowBounds(Rect(0, 0, 1800, 2560), Rect(0, 104, 0, 0))
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(558)
        assertThat(dp.numShownHotseatIcons).isEqualTo(6)
        assertThat(dp.hotseatBorderSpace).isEqualTo(69)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(176)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(558)

        assertThat(dp.isQsbInline).isFalse()
        assertThat(dp.hotseatQsbWidth).isEqualTo(1445)
    }

    /**
     * This is a case when after setting the hotseat, and recalculating spaces
     * it still needs to remove icons for everything to fit
     */
    @Test
    fun decrease_num_of_icons_when_not_enough_space_portrait() {
        initializeVarsForTablet(isGestureMode = false)
        windowBounds = WindowBounds(Rect(0, 0, 1300, 2560), Rect(0, 104, 0, 0))
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(558)
        assertThat(dp.numShownHotseatIcons).isEqualTo(4)
        assertThat(dp.hotseatBorderSpace).isEqualTo(76)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(122)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(558)

        assertThat(dp.isQsbInline).isFalse()
        assertThat(dp.hotseatQsbWidth).isEqualTo(1058)
    }

    /**
     * This is a case when after setting the hotseat, the space needs to be recalculated
     * but it doesn't need to change QSB width or remove icons
     */
    @Test
    fun distribute_border_space_when_space_is_enough_landscape() {
        initializeVarsForTwoPanel(isGestureMode = false, isLandscape = true)
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(744)
        assertThat(dp.numShownHotseatIcons).isEqualTo(6)
        assertThat(dp.hotseatBorderSpace).isEqualTo(83)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(106)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(744)

        assertThat(dp.isQsbInline).isFalse()
        assertThat(dp.hotseatQsbWidth).isEqualTo(1467)
    }

    /**
     * This is a case when the hotseat spans a certain amount of columns
     * and the nav buttons push the hotseat to the side, but not enough to change the border space.
     */
    @Test
    fun nav_buttons_dont_interfere_with_required_hotseat_width() {
        initializeVarsForTablet(isGestureMode = false, isLandscape = true)
        inv?.apply {
            hotseatColumnSpan = IntArray(4) { 4 }
            inlineQsb = BooleanArray(4) { false }
        }
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(705)
        assertThat(dp.numShownHotseatIcons).isEqualTo(6)
        assertThat(dp.hotseatBorderSpace).isEqualTo(108)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(631)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(705)

        assertThat(dp.isQsbInline).isFalse()
        assertThat(dp.hotseatQsbWidth).isEqualTo(1227)
    }

    /**
     * This is a case when after setting the hotseat, the QSB width needs to be changed to fit
     */
    @Test
    fun decrease_qsb_when_not_enough_space_landscape() {
        initializeVarsForTablet(isGestureMode = false, isLandscape = true)
        windowBounds = WindowBounds(Rect(0, 0, 2460, 1600), Rect(0, 104, 0, 0))
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(705)
        assertThat(dp.numShownHotseatIcons).isEqualTo(6)
        assertThat(dp.hotseatBorderSpace).isEqualTo(36)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(884)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(705)

        assertThat(dp.isQsbInline).isTrue()
        assertThat(dp.hotseatQsbWidth).isEqualTo(559)
    }

    /**
     * This is a case when after setting the hotseat, changing QSB width, and recalculating spaces
     * it still needs to remove icons for everything to fit
     */
    @Test
    fun decrease_num_of_icons_when_not_enough_space_landscape() {
        initializeVarsForTablet(isGestureMode = false, isLandscape = true)
        windowBounds = WindowBounds(Rect(0, 0, 2260, 1600), Rect(0, 104, 0, 0))
        val dp = newDP()
        dp.isTaskbarPresentInApps = true

        assertThat(dp.hotseatBarEndOffset).isEqualTo(705)
        assertThat(dp.numShownHotseatIcons).isEqualTo(5)
        assertThat(dp.hotseatBorderSpace).isEqualTo(56)

        assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(801)
        assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(705)

        assertThat(dp.isQsbInline).isTrue()
        assertThat(dp.hotseatQsbWidth).isEqualTo(480)
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -158,9 +158,6 @@

        <!-- numHotseatIcons defaults to numColumns, if not specified -->
        <attr name="numHotseatIcons" format="integer" />
        <!-- Number of icons to use when shrinking the hotseat size,
         defaults to numHotseatIcons / 2 -->
        <attr name="numShrunkenHotseatIcons" format="integer" />
        <!-- Number of icons to use when extending the hotseat size,
         defaults to 2 * numHotseatIcons -->
        <attr name="numExtendedHotseatIcons" format="integer" />
@@ -328,15 +325,6 @@
        if not specified -->
        <attr name="allAppsBorderSpaceTwoPanelLandscapeVertical" format="float" />

        <!-- defaults to borderSpaceDps, if not specified -->
        <attr name="hotseatBorderSpace" format="float" />
        <!-- defaults to hotseatBorderSpace, if not specified -->
        <attr name="hotseatBorderSpaceLandscape" format="float" />
        <!-- defaults to hotseatBorderSpace, if not specified -->
        <attr name="hotseatBorderSpaceTwoPanelLandscape" format="float" />
        <!-- defaults to hotseatBorderSpace, if not specified -->
        <attr name="hotseatBorderSpaceTwoPanelPortrait" format="float" />

        <!-- defaults to res.hotseat_bar_bottom_space_default, if not specified -->
        <attr name="hotseatBarBottomSpace" format="float" />
        <!-- defaults to hotseatBarBottomSpace, if not specified -->
Loading