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

Commit 6ac865e0 authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Fixing issues in Maximize Menu

The following issues are adressed in this CL:
1) Maximize menu closes after long press.
2) If maximize menu is open and a user clicks the maximize button, the
   maximize menu closes and the task maximizes while it is expected that
   the menu closes and the task remains the same size.

Bug: 319735069
Test: Manual Testing
Change-Id: I807aeab0a317f30d05c1ae6ee22d59eda9f1006f
parent 9fded33b
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -421,9 +421,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            }
            moveTaskToFront(mTaskOrganizer.getRunningTaskInfo(mTaskId));

            if (!mHasLongClicked) {
            if (!mHasLongClicked && id != R.id.maximize_window) {
                final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
                decoration.closeMaximizeMenu();
                decoration.closeMaximizeMenuIfNeeded(e);
            }

            final long eventDuration = e.getEventTime() - e.getDownTime();
@@ -643,7 +643,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                handleCaptionThroughStatusBar(ev, relevantDecor);
            }
        }
        handleEventOutsideFocusedCaption(ev, relevantDecor);
        handleEventOutsideCaption(ev, relevantDecor);
        // Prevent status bar from reacting to a caption drag.
        if (DesktopModeStatus.isEnabled()) {
            if (mTransitionDragActive) {
@@ -652,11 +652,17 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        }
    }

    // If an UP/CANCEL action is received outside of caption bounds, turn off handle menu
    private void handleEventOutsideFocusedCaption(MotionEvent ev,
    /**
     * If an UP/CANCEL action is received outside of the caption bounds, close the handle and
     * maximize the menu.
     *
     * @param relevantDecor the window decoration of the focused task's caption. This method only
     *                      handles motion events outside this caption's bounds.
     */
    private void handleEventOutsideCaption(MotionEvent ev,
            DesktopModeWindowDecoration relevantDecor) {
        // Returns if event occurs within caption
        if (relevantDecor == null || relevantDecor.checkTouchEventInCaptionHandle(ev)) {
        if (relevantDecor == null || relevantDecor.checkTouchEventInCaption(ev)) {
            return;
        }

@@ -692,7 +698,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                    }

                    if (dragFromStatusBarAllowed
                            && relevantDecor.checkTouchEventInCaptionHandle(ev)) {
                            && relevantDecor.checkTouchEventInFocusedCaptionHandle(ev)) {
                        mTransitionDragActive = true;
                    }
                }
+21 −8
Original line number Diff line number Diff line
@@ -612,8 +612,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    void closeMaximizeMenuIfNeeded(MotionEvent ev) {
        if (!isMaximizeMenuActive()) return;

        final PointF inputPoint = offsetCaptionLocation(ev);
        if (!mMaximizeMenu.isValidMenuInput(inputPoint)) {
        if (!mMaximizeMenu.isValidMenuInput(ev)) {
            closeMaximizeMenu();
        }
    }
@@ -639,20 +638,34 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    }

    /**
     * Checks if motion event occurs in the caption handle area. This should be used in cases where
     * Checks if motion event occurs in the caption handle area of a focused caption (the caption on
     * a task in fullscreen or in multi-windowing mode). This should be used in cases where
     * onTouchListener will not work (i.e. when caption is in status bar area).
     *
     * @param ev       the {@link MotionEvent} to check
     * @return {@code true} if event is inside the specified view, {@code false} if not
     * @return {@code true} if event is inside caption handle view, {@code false} if not
     */
    boolean checkTouchEventInCaptionHandle(MotionEvent ev) {
    boolean checkTouchEventInFocusedCaptionHandle(MotionEvent ev) {
        if (isHandleMenuActive() || !(mWindowDecorViewHolder
                instanceof DesktopModeFocusedWindowDecorationViewHolder)) {
            return false;
        }

        return checkTouchEventInCaption(ev);
    }

    /**
     * Checks if touch event occurs in caption.
     *
     * @param ev       the {@link MotionEvent} to check
     * @return {@code true} if event is inside caption view, {@code false} if not
     */
    boolean checkTouchEventInCaption(MotionEvent ev) {
        final PointF inputPoint = offsetCaptionLocation(ev);
        return ((DesktopModeFocusedWindowDecorationViewHolder) mWindowDecorViewHolder)
                .pointInCaption(inputPoint, mResult.mCaptionX);
        return inputPoint.x >= mResult.mCaptionX
                && inputPoint.x <= mResult.mCaptionX + mResult.mCaptionWidth
                && inputPoint.y >= 0
                && inputPoint.y <= mResult.mCaptionHeight;
    }

    /**
@@ -668,7 +681,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            // Click if point in caption handle view
            final View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption);
            final View handle = caption.findViewById(R.id.caption_handle);
            if (checkTouchEventInCaptionHandle(ev)) {
            if (checkTouchEventInFocusedCaptionHandle(ev)) {
                mOnCaptionButtonClickListener.onClick(handle);
            }
        } else {
+8 −11
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@ import android.content.res.Resources
import android.graphics.PixelFormat
import android.graphics.PointF
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import android.view.SurfaceControlViewHost
import android.view.View
import android.view.View.OnClickListener
import android.view.WindowManager
import android.view.WindowlessWindowManager
@@ -62,6 +62,8 @@ class MaximizeMenu(
    private val cornerRadius = loadDimensionPixelSize(
            R.dimen.desktop_mode_maximize_menu_corner_radius
    ).toFloat()
    private val menuWidth = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_width)
    private val menuHeight = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_height)

    /** Position the menu relative to the caption's position. */
    fun positionMenu(position: PointF, t: Transaction) {
@@ -95,8 +97,6 @@ class MaximizeMenu(
                .setName("Maximize Menu")
                .setContainerLayer()
                .build()
        val menuWidth = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_width)
        val menuHeight = loadDimensionPixelSize(R.dimen.desktop_mode_maximize_menu_height)
        val lp = WindowManager.LayoutParams(
                menuWidth,
                menuHeight,
@@ -160,14 +160,11 @@ class MaximizeMenu(
     *
     * @param inputPoint the input to compare against.
     */
    fun isValidMenuInput(inputPoint: PointF): Boolean {
        val menuView = maximizeMenu?.mWindowViewHost?.view ?: return true
        return !viewsLaidOut() || pointInView(menuView, inputPoint.x - menuPosition.x,
                inputPoint.y - menuPosition.y)
    }

    private fun pointInView(v: View, x: Float, y: Float): Boolean {
        return v.left <= x && v.right >= x && v.top <= y && v.bottom >= y
    fun isValidMenuInput(ev: MotionEvent): Boolean {
        val x = ev.rawX
        val y = ev.rawY
        return !viewsLaidOut() || (menuPosition.x <= x && menuPosition.x + menuWidth >= x &&
                menuPosition.y <= y && menuPosition.y + menuHeight >= y)
    }

    /**
+7 −4
Original line number Diff line number Diff line
@@ -279,11 +279,12 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        }

        outResult.mCaptionHeight = loadDimensionPixelSize(resources, params.mCaptionHeightId);
        final int captionWidth = params.mCaptionWidthId != Resources.ID_NULL
        outResult.mCaptionWidth = params.mCaptionWidthId != Resources.ID_NULL
                ? loadDimensionPixelSize(resources, params.mCaptionWidthId) : taskBounds.width();
        outResult.mCaptionX = (outResult.mWidth - captionWidth) / 2;
        outResult.mCaptionX = (outResult.mWidth - outResult.mCaptionWidth) / 2;

        startT.setWindowCrop(mCaptionContainerSurface, captionWidth, outResult.mCaptionHeight)
        startT.setWindowCrop(mCaptionContainerSurface, outResult.mCaptionWidth,
                        outResult.mCaptionHeight)
                .setPosition(mCaptionContainerSurface, outResult.mCaptionX, 0 /* y */)
                .setLayer(mCaptionContainerSurface, CAPTION_LAYER_Z_ORDER)
                .show(mCaptionContainerSurface);
@@ -356,7 +357,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        // Caption view
        mCaptionWindowManager.setConfiguration(taskConfig);
        final WindowManager.LayoutParams lp =
                new WindowManager.LayoutParams(captionWidth, outResult.mCaptionHeight,
                new WindowManager.LayoutParams(outResult.mCaptionWidth, outResult.mCaptionHeight,
                        WindowManager.LayoutParams.TYPE_APPLICATION,
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSPARENT);
        lp.setTitle("Caption of Task=" + mTaskInfo.taskId);
@@ -578,6 +579,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>

    static class RelayoutResult<T extends View & TaskFocusStateConsumer> {
        int mCaptionHeight;
        int mCaptionWidth;
        int mCaptionX;
        int mWidth;
        int mHeight;
@@ -587,6 +589,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            mWidth = 0;
            mHeight = 0;
            mCaptionHeight = 0;
            mCaptionWidth = 0;
            mCaptionX = 0;
            mRootView = null;
        }
+0 −12
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import android.app.ActivityManager.RunningTaskInfo
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PointF
import android.view.View
import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
import android.widget.ImageButton
@@ -47,17 +46,6 @@ internal class DesktopModeFocusedWindowDecorationViewHolder(
        animateCaptionHandleAlpha(startValue = 0f, endValue = 1f)
    }

    /**
     * Returns true if input point is in the caption's view.
     * @param inputPoint the input point relative to the task in full "focus" (i.e. fullscreen).
     */
    fun pointInCaption(inputPoint: PointF, captionX: Int): Boolean {
        return inputPoint.x >= captionX &&
                inputPoint.x <= captionX + captionView.width &&
                inputPoint.y >= 0 &&
                inputPoint.y <= captionView.height
    }

    private fun getCaptionHandleBarColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
            context.getColor(R.color.desktop_mode_caption_handle_bar_light)