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

Commit 2fbfc28f authored by Maryam Dehaini's avatar Maryam Dehaini Committed by Android (Google) Code Review
Browse files

Merge "Make fullscreen caption the size of the caption handle" into main

parents f1e25135 248b442c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -18,13 +18,13 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/desktop_mode_caption"
    android:layout_width="match_parent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal">

    <ImageButton
        android:id="@+id/caption_handle"
        android:layout_width="128dp"
        android:layout_width="@dimen/desktop_mode_fullscreen_decor_caption_width"
        android:layout_height="@dimen/desktop_mode_fullscreen_decor_caption_height"
        android:paddingVertical="16dp"
        android:contentDescription="@string/handle_text"
+3 −0
Original line number Diff line number Diff line
@@ -413,6 +413,9 @@
    <!-- Height of desktop mode caption for fullscreen tasks. -->
    <dimen name="desktop_mode_fullscreen_decor_caption_height">36dp</dimen>

    <!-- Width of desktop mode caption for fullscreen tasks. -->
    <dimen name="desktop_mode_fullscreen_decor_caption_width">128dp</dimen>

    <!-- Required empty space to be visible for partially offscreen tasks. -->
    <dimen name="freeform_required_visible_empty_space_in_header">48dp</dimen>

+3 −2
Original line number Diff line number Diff line
@@ -726,7 +726,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
    private void handleEventOutsideFocusedCaption(MotionEvent ev,
            DesktopModeWindowDecoration relevantDecor) {
        // Returns if event occurs within caption
        if (relevantDecor == null || relevantDecor.checkTouchEventInCaption(ev)) {
        if (relevantDecor == null || relevantDecor.checkTouchEventInCaptionHandle(ev)) {
            return;
        }

@@ -761,7 +761,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                                || windowingMode == WINDOWING_MODE_MULTI_WINDOW;
                    }

                    if (dragFromStatusBarAllowed && relevantDecor.checkTouchEventInHandle(ev)) {
                    if (dragFromStatusBarAllowed
                            && relevantDecor.checkTouchEventInCaptionHandle(ev)) {
                        mTransitionDragActive = true;
                    }
                }
+26 −30
Original line number Diff line number Diff line
@@ -317,6 +317,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        relayoutParams.mLayoutResId =
            getDesktopModeWindowDecorLayoutId(taskInfo.getWindowingMode());
        relayoutParams.mCaptionHeightId = getCaptionHeightIdStatic(taskInfo.getWindowingMode());
        relayoutParams.mCaptionWidthId = getCaptionWidthId(relayoutParams.mLayoutResId);
        if (DesktopModeStatus.useWindowShadow(/* isFocusedWindow= */ taskInfo.isFocused)) {
            relayoutParams.mShadowRadiusId = taskInfo.isFocused
                    ? R.dimen.freeform_decor_shadow_focused_thickness
@@ -345,6 +346,17 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        }
    }

    /**
     * If task has focused window decor, return the caption id of the fullscreen caption size
     * resource. Otherwise, return ID_NULL and caption width be set to task width.
     */
    private static int getCaptionWidthId(int layoutResId) {
        if (layoutResId == R.layout.desktop_mode_focused_window_decor) {
            return R.dimen.desktop_mode_fullscreen_decor_caption_width;
        }
        return Resources.ID_NULL;
    }


    private PointF calculateMaximizeMenuPosition() {
        final PointF position = new PointF();
@@ -558,7 +570,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                .setOnClickListener(mOnCaptionButtonClickListener)
                .setOnTouchListener(mOnCaptionTouchListener)
                .setLayoutId(mRelayoutParams.mLayoutResId)
                .setCaptionPosition(mRelayoutParams.mCaptionX, mRelayoutParams.mCaptionY)
                .setWindowingButtonsVisible(DesktopModeStatus.isEnabled())
                .setCaptionHeight(mResult.mCaptionHeight)
                .build();
@@ -635,35 +646,25 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                mTaskOrganizer.getRunningTaskInfo(mTaskInfo.taskId);
        if (taskInfo == null) return result;
        final Point positionInParent = taskInfo.positionInParent;
        result.offset(-mRelayoutParams.mCaptionX, -mRelayoutParams.mCaptionY);
        result.offset(-positionInParent.x, -positionInParent.y);
        return result;
    }

    /**
     * Determine if a passed MotionEvent is in a view in caption
     * Checks if motion event occurs in the caption handle area. 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
     * @param layoutId the id of the view
     * @return {@code true} if event is inside the specified view, {@code false} if not
     */
    private boolean checkEventInCaptionView(MotionEvent ev, int layoutId) {
        if (mResult.mRootView == null) return false;
        final PointF inputPoint = offsetCaptionLocation(ev);
        final View view = mResult.mRootView.findViewById(layoutId);
        return view != null && pointInView(view, inputPoint.x, inputPoint.y);
    }

    boolean checkTouchEventInHandle(MotionEvent ev) {
        if (isHandleMenuActive()) return false;
        return checkEventInCaptionView(ev, R.id.caption_handle);
    boolean checkTouchEventInCaptionHandle(MotionEvent ev) {
        if (isHandleMenuActive() || !(mWindowDecorViewHolder
                instanceof DesktopModeFocusedWindowDecorationViewHolder)) {
            return false;
        }

    /**
     * Returns true if motion event is within the caption's root view's bounds.
     */
    boolean checkTouchEventInCaption(MotionEvent ev) {
        return checkEventInCaptionView(ev, getCaptionViewId());
        final PointF inputPoint = offsetCaptionLocation(ev);
        return ((DesktopModeFocusedWindowDecorationViewHolder) mWindowDecorViewHolder)
                .pointInCaption(inputPoint, mResult.mCaptionX);
    }

    /**
@@ -676,24 +677,19 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    void checkClickEvent(MotionEvent ev) {
        if (mResult.mRootView == null) return;
        if (!isHandleMenuActive()) {
            // 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);
            clickIfPointInView(new PointF(ev.getX(), ev.getY()), handle);
            if (checkTouchEventInCaptionHandle(ev)) {
                mOnCaptionButtonClickListener.onClick(handle);
            }
        } else {
            mHandleMenu.checkClickEvent(ev);
            closeHandleMenuIfNeeded(ev);
        }
    }

    private boolean clickIfPointInView(PointF inputPoint, View v) {
        if (pointInView(v, inputPoint.x, inputPoint.y)) {
            mOnCaptionButtonClickListener.onClick(v);
            return true;
        }
        return false;
    }

    boolean pointInView(View v, float x, float y) {
    private boolean pointInView(View v, float x, float y) {
        return v != null && v.getLeft() <= x && v.getRight() >= x
                && v.getTop() <= y && v.getBottom() >= y;
    }
+9 −22
Original line number Diff line number Diff line
@@ -64,8 +64,6 @@ class HandleMenu {
    private final View.OnTouchListener mOnTouchListener;
    private final RunningTaskInfo mTaskInfo;
    private final int mLayoutResId;
    private final int mCaptionX;
    private final int mCaptionY;
    private int mMarginMenuTop;
    private int mMarginMenuStart;
    private int mMenuHeight;
@@ -74,16 +72,13 @@ class HandleMenu {
    private HandleMenuAnimator mHandleMenuAnimator;


    HandleMenu(WindowDecoration parentDecor, int layoutResId, int captionX, int captionY,
            View.OnClickListener onClickListener, View.OnTouchListener onTouchListener,
            Bitmap appIcon, CharSequence appName, boolean shouldShowWindowingPill,
            int captionHeight) {
    HandleMenu(WindowDecoration parentDecor, int layoutResId, View.OnClickListener onClickListener,
            View.OnTouchListener onTouchListener, Bitmap appIcon, CharSequence appName,
            boolean shouldShowWindowingPill, int captionHeight) {
        mParentDecor = parentDecor;
        mContext = mParentDecor.mDecorWindowContext;
        mTaskInfo = mParentDecor.mTaskInfo;
        mLayoutResId = layoutResId;
        mCaptionX = captionX;
        mCaptionY = captionY;
        mOnClickListener = onClickListener;
        mOnTouchListener = onTouchListener;
        mAppIconBitmap = appIcon;
@@ -225,12 +220,12 @@ class HandleMenu {
        if (mLayoutResId
                == R.layout.desktop_mode_app_controls_window_decor) {
            // Align the handle menu to the left of the caption.
            menuX = mCaptionX + mMarginMenuStart;
            menuY = mCaptionY + mMarginMenuTop;
            menuX = mMarginMenuStart;
            menuY = mMarginMenuTop;
        } else {
            // Position the handle menu at the center of the caption.
            menuX = mCaptionX + (captionWidth / 2) - (mMenuWidth / 2);
            menuY = mCaptionY + mMarginMenuStart;
            menuX = (captionWidth / 2) - (mMenuWidth / 2);
            menuY = mMarginMenuStart;
        }

        // Handle Menu position setup.
@@ -346,8 +341,6 @@ class HandleMenu {
        private View.OnClickListener mOnClickListener;
        private View.OnTouchListener mOnTouchListener;
        private int mLayoutId;
        private int mCaptionX;
        private int mCaptionY;
        private boolean mShowWindowingPill;
        private int mCaptionHeight;

@@ -381,12 +374,6 @@ class HandleMenu {
            return this;
        }

        Builder setCaptionPosition(int captionX, int captionY) {
            mCaptionX = captionX;
            mCaptionY = captionY;
            return this;
        }

        Builder setWindowingButtonsVisible(boolean windowingButtonsVisible) {
            mShowWindowingPill = windowingButtonsVisible;
            return this;
@@ -398,8 +385,8 @@ class HandleMenu {
        }

        HandleMenu build() {
            return new HandleMenu(mParent, mLayoutId, mCaptionX, mCaptionY, mOnClickListener,
                    mOnTouchListener, mAppIcon, mName, mShowWindowingPill, mCaptionHeight);
            return new HandleMenu(mParent, mLayoutId, mOnClickListener, mOnTouchListener,
                    mAppIcon, mName, mShowWindowingPill, mCaptionHeight);
        }
    }
}
Loading