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

Commit 4515dcbd authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

Merge "Add immersive option to maximize menu" into main

parents 6dfcf7bc 6439678d
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -17,20 +17,53 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    android:id="@+id/maximize_menu"
    android:layout_width="@dimen/desktop_mode_maximize_menu_width"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/desktop_mode_maximize_menu_height"
    android:background="@drawable/desktop_mode_maximize_menu_background"
    android:elevation="1dp">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="@dimen/desktop_mode_maximize_menu_width"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/desktop_mode_maximize_menu_height"
        android:orientation="horizontal"
        android:padding="16dp"
        android:gravity="center">

        <LinearLayout
            android:id="@+id/maximize_menu_immersive_toggle_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button
                android:layout_width="94dp"
                android:layout_height="60dp"
                android:id="@+id/maximize_menu_immersive_toggle_button"
                style="?android:attr/buttonBarButtonStyle"
                android:stateListAnimator="@null"
                android:importantForAccessibility="yes"
                android:contentDescription="@string/desktop_mode_maximize_menu_immersive_button_text"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="4dp"
                android:alpha="0"/>

            <TextView
                android:id="@+id/maximize_menu_immersive_toggle_button_text"
                android:layout_width="94dp"
                android:layout_height="18dp"
                android:textSize="11sp"
                android:layout_marginBottom="76dp"
                android:gravity="center"
                android:fontFamily="google-sans-text"
                android:importantForAccessibility="no"
                android:text="@string/desktop_mode_maximize_menu_immersive_button_text"
                android:textColor="?androidprv:attr/materialColorOnSurface"
                android:alpha="0"/>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/maximize_menu_size_toggle_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
@@ -43,7 +76,6 @@
                android:stateListAnimator="@null"
                android:importantForAccessibility="yes"
                android:contentDescription="@string/desktop_mode_maximize_menu_maximize_button_text"
                android:layout_marginRight="8dp"
                android:layout_marginBottom="4dp"
                android:alpha="0"/>

@@ -62,6 +94,7 @@
        </LinearLayout>

        <LinearLayout
            android:id="@+id/maximize_menu_snap_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
@@ -73,6 +106,7 @@
                android:padding="4dp"
                android:background="@drawable/desktop_mode_maximize_menu_layout_background"
                android:layout_marginBottom="4dp"
                android:layout_marginStart="8dp"
                android:alpha="0">
                <Button
                    android:id="@+id/maximize_menu_snap_left_button"
@@ -115,7 +149,7 @@
     used to monitor input events over the entire menu. -->
    <View
        android:id="@+id/maximize_menu_overlay"
        android:layout_width="@dimen/desktop_mode_maximize_menu_width"
        android:layout_width="match_parent"
        android:layout_height="@dimen/desktop_mode_maximize_menu_height"/>
</FrameLayout>
+8 −2
Original line number Diff line number Diff line
@@ -479,8 +479,10 @@
    <!-- The default minimum allowed window height when resizing a window in desktop mode. -->
    <dimen name="desktop_mode_minimum_window_height">352dp</dimen>

    <!-- The width of the maximize menu in desktop mode. -->
    <dimen name="desktop_mode_maximize_menu_width">228dp</dimen>
    <!-- The width of the maximize menu in desktop mode, depending on the number of options -->
    <dimen name="desktop_mode_maximize_menu_width_one_options">126dp</dimen>
    <dimen name="desktop_mode_maximize_menu_width_two_options">228dp</dimen>
    <dimen name="desktop_mode_maximize_menu_width_three_options">330dp</dimen>

    <!-- The height of the maximize menu in desktop mode. -->
    <dimen name="desktop_mode_maximize_menu_height">114dp</dimen>
@@ -502,10 +504,14 @@
    <dimen name="desktop_mode_maximize_menu_buttons_fill_radius">4dp</dimen>
    <!-- The padding between the outline and fill of the maximize menu snap and maximize buttons. -->
    <dimen name="desktop_mode_maximize_menu_snap_and_maximize_buttons_fill_padding">4dp</dimen>
    <!-- The padding between the outline and fill of the maximize menu snap and maximize buttons. -->
    <dimen name="desktop_mode_maximize_menu_snap_and_maximize_buttons_fill_padding_bottom">8dp</dimen>
    <!-- The vertical padding between the outline and fill of the maximize menu restore button. -->
    <dimen name="desktop_mode_maximize_menu_restore_button_fill_vertical_padding">13dp</dimen>
    <!-- The horizontal padding between the outline and fill of the maximize menu restore button. -->
    <dimen name="desktop_mode_maximize_menu_restore_button_fill_horizontal_padding">21dp</dimen>
    <!-- The padding between the outline and fill of the maximize menu immersive button. -->
    <dimen name="desktop_mode_maximize_menu_immersive_button_fill_padding">4dp</dimen>

    <!-- The corner radius of the maximize menu. -->
    <dimen name="desktop_mode_maximize_menu_corner_radius">8dp</dimen>
+4 −1
Original line number Diff line number Diff line
@@ -317,7 +317,10 @@
    <string name="desktop_mode_maximize_menu_snap_text">Snap Screen</string>
    <!-- Snap resizing non-resizable string. -->
    <string name="desktop_mode_non_resizable_snap_text">App can\'t be moved here</string>
    <!-- Accessibility text for the Maximize Menu's maximize button [CHAR LIMIT=NONE] -->
    <!-- Accessibility text for the Maximize Menu's immersive button [CHAR LIMIT=NONE] -->
    <string name="desktop_mode_maximize_menu_immersive_button_text">Immersive</string>
    <!-- Accessibility text for the Maximize Menu's immersive restore button [CHAR LIMIT=NONE] -->
    <string name="desktop_mode_maximize_menu_immersive_restore_button_text">Restore</string>
    <string name="desktop_mode_maximize_menu_maximize_button_text">Maximize</string>
    <!-- Accessibility text for the Maximize Menu's restore button [CHAR LIMIT=NONE] -->
    <string name="desktop_mode_maximize_menu_restore_button_text">Restore</string>
+5 −0
Original line number Diff line number Diff line
@@ -586,6 +586,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            return;
        }
        mDesktopTasksController.toggleDesktopTaskFullImmersiveState(decoration.mTaskInfo);
        decoration.closeMaximizeMenu();
    }

    private void onSnapResize(int taskId, boolean left, MotionEvent motionEvent) {
@@ -1537,6 +1538,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                    touchEventListener.mMotionEvent);
            return Unit.INSTANCE;
        });
        windowDecoration.setOnImmersiveOrRestoreClickListener(() -> {
            onEnterOrExitImmersive(taskInfo.taskId);
            return Unit.INSTANCE;
        });
        windowDecoration.setOnLeftSnapClickListener(() -> {
            onSnapResize(taskInfo.taskId, /* isLeft= */ true, touchEventListener.mMotionEvent);
            return Unit.INSTANCE;
+41 −19
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    private View.OnLongClickListener mOnCaptionLongClickListener;
    private View.OnGenericMotionListener mOnCaptionGenericMotionListener;
    private Function0<Unit> mOnMaximizeOrRestoreClickListener;
    private Function0<Unit> mOnImmersiveOrRestoreClickListener;
    private Function0<Unit> mOnLeftSnapClickListener;
    private Function0<Unit> mOnRightSnapClickListener;
    private Consumer<DesktopModeTransitionSource> mOnToDesktopClickListener;
@@ -293,6 +294,14 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mOnMaximizeOrRestoreClickListener = listener;
    }

    /**
     * Registers a listener to be called back when one of the tasks' immersive/restore action is
     * triggered.
     */
    void setOnImmersiveOrRestoreClickListener(Function0<Unit> listener) {
        mOnImmersiveOrRestoreClickListener = listener;
    }

    /** Registers a listener to be called when the decoration's snap-left action is triggered.*/
    void setOnLeftSnapClickListener(Function0<Unit> listener) {
        mOnLeftSnapClickListener = listener;
@@ -718,7 +727,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        if (!mTaskInfo.isVisible()) {
            closeMaximizeMenu();
        } else {
            mMaximizeMenu.positionMenu(calculateMaximizeMenuPosition(), startT);
            final int menuWidth = calculateMaximizeMenuWidth();
            mMaximizeMenu.positionMenu(calculateMaximizeMenuPosition(menuWidth), startT);
        }
    }

@@ -939,8 +949,27 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        return Resources.ID_NULL;
    }


    private PointF calculateMaximizeMenuPosition() {
    private int calculateMaximizeMenuWidth() {
        final boolean showImmersive = Flags.enableFullyImmersiveInDesktop()
                && TaskInfoKt.getRequestingImmersive(mTaskInfo);
        final boolean showMaximize = true;
        final boolean showSnaps = mTaskInfo.isResizeable;
        int showCount = 0;
        if (showImmersive) showCount++;
        if (showMaximize) showCount++;
        if (showSnaps) showCount++;
        return switch (showCount) {
            case 1 -> loadDimensionPixelSize(mContext.getResources(),
                    R.dimen.desktop_mode_maximize_menu_width_one_options);
            case 2 -> loadDimensionPixelSize(mContext.getResources(),
                    R.dimen.desktop_mode_maximize_menu_width_two_options);
            case 3 -> loadDimensionPixelSize(mContext.getResources(),
                    R.dimen.desktop_mode_maximize_menu_width_three_options);
            default -> throw new IllegalArgumentException("");
        };
    }

    private PointF calculateMaximizeMenuPosition(int menuWidth) {
        final PointF position = new PointF();
        final Resources resources = mContext.getResources();
        final DisplayLayout displayLayout =
@@ -956,8 +985,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        final int[] maximizeButtonLocation = new int[2];
        maximizeWindowButton.getLocationInWindow(maximizeButtonLocation);

        final int menuWidth = loadDimensionPixelSize(
                resources, R.dimen.desktop_mode_maximize_menu_width);
        final int menuHeight = loadDimensionPixelSize(
                resources, R.dimen.desktop_mode_maximize_menu_height);

@@ -1188,11 +1215,19 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     * Create and display maximize menu window
     */
    void createMaximizeMenu() {
        final int menuWidth = calculateMaximizeMenuWidth();
        mMaximizeMenu = mMaximizeMenuFactory.create(mSyncQueue, mRootTaskDisplayAreaOrganizer,
                mDisplayController, mTaskInfo, mContext,
                calculateMaximizeMenuPosition(), mSurfaceControlTransactionSupplier);
                calculateMaximizeMenuPosition(menuWidth), mSurfaceControlTransactionSupplier);
        mMaximizeMenu.show(
                /* isTaskInImmersiveMode= */ Flags.enableFullyImmersiveInDesktop()
                        && mDesktopRepository.isTaskInFullImmersiveState(mTaskInfo.taskId),
                /* menuWidth= */ menuWidth,
                /* showImmersiveOption= */ Flags.enableFullyImmersiveInDesktop()
                        && TaskInfoKt.getRequestingImmersive(mTaskInfo),
                /* showSnapOptions= */ mTaskInfo.isResizeable,
                mOnMaximizeOrRestoreClickListener,
                mOnImmersiveOrRestoreClickListener,
                mOnLeftSnapClickListener,
                mOnRightSnapClickListener,
                hovered -> {
@@ -1433,19 +1468,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        }
    }

    /**
     * Close an open maximize menu if input is outside of menu coordinates
     *
     * @param ev the tapped point to compare against
     */
    void closeMaximizeMenuIfNeeded(MotionEvent ev) {
        if (!isMaximizeMenuActive()) return;

        if (!mMaximizeMenu.isValidMenuInput(ev)) {
            closeMaximizeMenu();
        }
    }

    boolean isFocused() {
        return mHasGlobalFocus;
    }
Loading