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

Commit d2c58cc5 authored by Jorge Gil's avatar Jorge Gil
Browse files

Fix Handle Menu window width and height

The height value in dimen was larger than the actual max height of the
menu, which meant the HandleMenu window had additional empty space after
the pills. This caused input in there (but from a user's POV, input
outside the window) to be treated as non-dimissing, which made
dismissing from that area feel unresponsive.

Additionally, the spacing (top margin) between each pill was not being
subtracted when pills were invisible.

Finally adds right and bottom padding to the view hierarchy and removes
clipping of the pills to account for the elevation that was getting
clipped by the view bounds. This requires adding that 1dp to the menu
width and height calculations before creating the
AdditionalViewContainer.

Bug: 339509495
Test: tap right below the menu's view bounds, menu is dismissed
Test: atest HandleMenuTest
Flag: EXEMPT bugfix
Change-Id: I6fefd013c7463d8690ecf9436e8c7bfe7b61744f
parent 58ec4858
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="@dimen/desktop_mode_handle_menu_width"
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:paddingBottom="@dimen/desktop_mode_handle_menu_pill_elevation"
    android:paddingRight="@dimen/desktop_mode_handle_menu_pill_elevation"
    android:orientation="vertical">

    <LinearLayout
@@ -27,7 +31,7 @@
        android:layout_height="@dimen/desktop_mode_handle_menu_app_info_pill_height"
        android:layout_marginTop="@dimen/desktop_mode_handle_menu_margin_top"
        android:layout_marginStart="1dp"
        android:elevation="1dp"
        android:elevation="@dimen/desktop_mode_handle_menu_pill_elevation"
        android:orientation="horizontal"
        android:background="@drawable/desktop_mode_decor_handle_menu_background"
        android:gravity="center_vertical">
@@ -73,7 +77,7 @@
        android:layout_marginTop="@dimen/desktop_mode_handle_menu_pill_spacing_margin"
        android:layout_marginStart="1dp"
        android:orientation="horizontal"
        android:elevation="1dp"
        android:elevation="@dimen/desktop_mode_handle_menu_pill_elevation"
        android:background="@drawable/desktop_mode_decor_handle_menu_background"
        android:gravity="center_vertical">

@@ -124,7 +128,7 @@
        android:layout_marginTop="@dimen/desktop_mode_handle_menu_pill_spacing_margin"
        android:layout_marginStart="1dp"
        android:orientation="vertical"
        android:elevation="1dp"
        android:elevation="@dimen/desktop_mode_handle_menu_pill_elevation"
        android:background="@drawable/desktop_mode_decor_handle_menu_background">

        <Button
@@ -143,7 +147,7 @@
        android:layout_marginTop="@dimen/desktop_mode_handle_menu_pill_spacing_margin"
        android:layout_marginStart="1dp"
        android:orientation="vertical"
        android:elevation="1dp"
        android:elevation="@dimen/desktop_mode_handle_menu_pill_elevation"
        android:background="@drawable/desktop_mode_decor_handle_menu_background">

        <Button
+10 −6
Original line number Diff line number Diff line
@@ -498,6 +498,13 @@
    <!-- The width of the handle menu in desktop mode.  -->
    <dimen name="desktop_mode_handle_menu_width">216dp</dimen>

    <!-- The maximum height of the handle menu in desktop mode. Four pills (52dp each) plus 2dp
        spacing between them plus 4dp top padding. -->
    <dimen name="desktop_mode_handle_menu_height">218dp</dimen>

    <!-- The elevation set on the handle menu pills. -->
    <dimen name="desktop_mode_handle_menu_pill_elevation">1dp</dimen>

    <!-- The height of the handle menu's "App Info" pill in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_app_info_pill_height">52dp</dimen>

@@ -510,8 +517,8 @@
    <!-- The height of the handle menu's "Open in browser" pill in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_open_in_browser_pill_height">52dp</dimen>

    <!-- The height of the handle menu in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_height">380dp</dimen>
    <!-- The margin between pills of the handle menu in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_pill_spacing_margin">2dp</dimen>

    <!-- The top margin of the handle menu in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_margin_top">4dp</dimen>
@@ -519,9 +526,6 @@
    <!-- The start margin of the handle menu in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_margin_start">6dp</dimen>

    <!-- The margin between pills of the handle menu in desktop mode. -->
    <dimen name="desktop_mode_handle_menu_pill_spacing_margin">2dp</dimen>

    <!-- The radius of the caption menu corners. -->
    <dimen name="desktop_mode_handle_menu_corner_radius">26dp</dimen>

+24 −31
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.wm.shell.windowdecor

import android.annotation.DimenRes
import android.app.ActivityManager
import android.app.WindowConfiguration
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
@@ -75,10 +76,17 @@ class HandleMenu(
    private val isViewAboveStatusBar: Boolean
        get() = (Flags.enableAdditionalWindowsAboveStatusBar() && !taskInfo.isFreeform)

    private var marginMenuTop = 0
    private var marginMenuStart = 0
    private var menuHeight = 0
    private var menuWidth = 0
    private val pillElevation: Int = loadDimensionPixelSize(
        R.dimen.desktop_mode_handle_menu_pill_elevation)
    private val pillTopMargin: Int = loadDimensionPixelSize(
        R.dimen.desktop_mode_handle_menu_pill_spacing_margin)
    private val menuWidth = loadDimensionPixelSize(
        R.dimen.desktop_mode_handle_menu_width) + pillElevation
    private val menuHeight = getHandleMenuHeight()
    private val marginMenuTop = loadDimensionPixelSize(R.dimen.desktop_mode_handle_menu_margin_top)
    private val marginMenuStart = loadDimensionPixelSize(
        R.dimen.desktop_mode_handle_menu_margin_start)

    private var handleMenuAnimator: HandleMenuAnimator? = null

    @VisibleForTesting
@@ -120,7 +128,6 @@ class HandleMenu(
        }

    init {
        loadHandleMenuDimensions()
        updateHandleMenuPillPositions()
    }

@@ -426,49 +433,35 @@ class HandleMenu(
     */
    private fun viewsLaidOut(): Boolean = handleMenuViewContainer?.view?.isLaidOut ?: false

    private fun loadHandleMenuDimensions() {
        val resources = context.resources
        menuWidth = loadDimensionPixelSize(resources, R.dimen.desktop_mode_handle_menu_width)
        menuHeight = getHandleMenuHeight(resources)
        marginMenuTop = loadDimensionPixelSize(
            resources,
            R.dimen.desktop_mode_handle_menu_margin_top
        )
        marginMenuStart = loadDimensionPixelSize(
            resources,
            R.dimen.desktop_mode_handle_menu_margin_start
        )
    }

    /**
     * Determines handle menu height based on if windowing pill should be shown.
     * Determines handle menu height based the max size and the visibility of pills.
     */
    private fun getHandleMenuHeight(resources: Resources): Int {
        var menuHeight = loadDimensionPixelSize(resources, R.dimen.desktop_mode_handle_menu_height)
    private fun getHandleMenuHeight(): Int {
        var menuHeight = loadDimensionPixelSize(
            R.dimen.desktop_mode_handle_menu_height) + pillElevation
        if (!shouldShowWindowingPill) {
            menuHeight -= loadDimensionPixelSize(
                resources,
                R.dimen.desktop_mode_handle_menu_windowing_pill_height
            )
                R.dimen.desktop_mode_handle_menu_windowing_pill_height)
            menuHeight -= pillTopMargin
        }
        if (!SHOULD_SHOW_MORE_ACTIONS_PILL) {
            menuHeight -= loadDimensionPixelSize(
                resources,
                R.dimen.desktop_mode_handle_menu_more_actions_pill_height
            )
                R.dimen.desktop_mode_handle_menu_more_actions_pill_height)
            menuHeight -= pillTopMargin
        }
        if (!shouldShowBrowserPill) {
            menuHeight -= loadDimensionPixelSize(resources,
            menuHeight -= loadDimensionPixelSize(
                R.dimen.desktop_mode_handle_menu_open_in_browser_pill_height)
            menuHeight -= pillTopMargin
        }
        return menuHeight
    }

    private fun loadDimensionPixelSize(resources: Resources, resourceId: Int): Int {
    private fun loadDimensionPixelSize(@DimenRes resourceId: Int): Int {
        if (resourceId == Resources.ID_NULL) {
            return 0
        }
        return resources.getDimensionPixelSize(resourceId)
        return context.resources.getDimensionPixelSize(resourceId)
    }

    fun close() {
+16 −3
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ class HandleMenuTest : ShellTestCase() {

    private lateinit var handleMenu: HandleMenu

    private val menuWidthWithElevation = MENU_WIDTH + MENU_PILL_ELEVATION

    @Before
    fun setUp() {
        val mockAdditionalViewHostViewContainer = AdditionalViewHostViewContainer(
@@ -117,6 +119,9 @@ class HandleMenuTest : ShellTestCase() {
            addOverride(R.dimen.desktop_mode_handle_menu_height, MENU_HEIGHT)
            addOverride(R.dimen.desktop_mode_handle_menu_margin_top, MENU_TOP_MARGIN)
            addOverride(R.dimen.desktop_mode_handle_menu_margin_start, MENU_START_MARGIN)
            addOverride(R.dimen.desktop_mode_handle_menu_pill_elevation, MENU_PILL_ELEVATION)
            addOverride(
                R.dimen.desktop_mode_handle_menu_pill_spacing_margin, MENU_PILL_SPACING_MARGIN)
        }
        mockDesktopWindowDecoration.mDecorWindowContext = mContext
    }
@@ -129,7 +134,7 @@ class HandleMenuTest : ShellTestCase() {
        assertTrue(handleMenu.handleMenuViewContainer is AdditionalSystemViewContainer)
        // Verify menu is created at coordinates that, when added to WindowManager,
        // show at the top-center of display.
        val expected = Point(DISPLAY_BOUNDS.centerX() - MENU_WIDTH / 2, MENU_TOP_MARGIN)
        val expected = Point(DISPLAY_BOUNDS.centerX() - menuWidthWithElevation / 2, MENU_TOP_MARGIN)
        assertEquals(expected.toPointF(), handleMenu.handleMenuPosition)
    }

@@ -152,7 +157,10 @@ class HandleMenuTest : ShellTestCase() {
        assertTrue(handleMenu.handleMenuViewContainer is AdditionalSystemViewContainer)
        // Verify menu is created at coordinates that, when added to WindowManager,
        // show at the top-center of split left task.
        val expected = Point(SPLIT_LEFT_BOUNDS.centerX() - MENU_WIDTH / 2, MENU_TOP_MARGIN)
        val expected = Point(
            SPLIT_LEFT_BOUNDS.centerX() - menuWidthWithElevation / 2,
            MENU_TOP_MARGIN
        )
        assertEquals(expected.toPointF(), handleMenu.handleMenuPosition)
    }

@@ -164,7 +172,10 @@ class HandleMenuTest : ShellTestCase() {
        assertTrue(handleMenu.handleMenuViewContainer is AdditionalSystemViewContainer)
        // Verify menu is created at coordinates that, when added to WindowManager,
        // show at the top-center of split right task.
        val expected = Point(SPLIT_RIGHT_BOUNDS.centerX() - MENU_WIDTH / 2, MENU_TOP_MARGIN)
        val expected = Point(
            SPLIT_RIGHT_BOUNDS.centerX() - menuWidthWithElevation / 2,
            MENU_TOP_MARGIN
        )
        assertEquals(expected.toPointF(), handleMenu.handleMenuPosition)
    }

@@ -220,5 +231,7 @@ class HandleMenuTest : ShellTestCase() {
        private const val MENU_HEIGHT = 400
        private const val MENU_TOP_MARGIN = 10
        private const val MENU_START_MARGIN = 20
        private const val MENU_PILL_ELEVATION = 2
        private const val MENU_PILL_SPACING_MARGIN = 4
    }
}