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

Commit 99b22694 authored by Omar Elmekkawy's avatar Omar Elmekkawy Committed by Android (Google) Code Review
Browse files

Merge "Update visual indicator on tiling to match tiled size." into main

parents aa751737 8126a645
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.wm.shell.shared.annotations.ShellMainThread;
import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper;
import com.android.wm.shell.shared.bubbles.BubbleDropTargetBoundsProvider;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler;

/**
 * Animated visual indicator for Desktop Mode windowing transitions.
@@ -98,7 +99,9 @@ public class DesktopModeVisualIndicator {
                return FROM_SPLIT;
            } else if (taskInfo.isFreeform()) {
                return FROM_FREEFORM;
            } else return null;
            } else {
                return null;
            }
        }
    }

@@ -110,6 +113,7 @@ public class DesktopModeVisualIndicator {

    private IndicatorType mCurrentType;
    private final DragStartState mDragStartState;
    private final SnapEventHandler mSnapEventHandler;

    public DesktopModeVisualIndicator(@ShellDesktopThread ShellExecutor desktopExecutor,
            @ShellMainThread ShellExecutor mainExecutor,
@@ -118,18 +122,20 @@ public class DesktopModeVisualIndicator {
            Context context, SurfaceControl taskSurface,
            RootTaskDisplayAreaOrganizer taskDisplayAreaOrganizer,
            DragStartState dragStartState,
            @Nullable BubbleDropTargetBoundsProvider bubbleBoundsProvider) {
            @Nullable BubbleDropTargetBoundsProvider bubbleBoundsProvider,
            SnapEventHandler snapEventHandler) {
        SurfaceControl.Builder builder = new SurfaceControl.Builder();
        taskDisplayAreaOrganizer.attachToDisplayArea(taskInfo.displayId, builder);
        mVisualIndicatorViewContainer = new VisualIndicatorViewContainer(
                DesktopModeFlags.ENABLE_DESKTOP_INDICATOR_IN_SEPARATE_THREAD_BUGFIX.isTrue()
                        ? desktopExecutor : mainExecutor,
                mainExecutor, builder, syncQueue, bubbleBoundsProvider);
                mainExecutor, builder, syncQueue, bubbleBoundsProvider, snapEventHandler);
        mTaskInfo = taskInfo;
        mDisplayController = displayController;
        mContext = context;
        mCurrentType = NO_INDICATOR;
        mDragStartState = dragStartState;
        mSnapEventHandler = snapEventHandler;
        mVisualIndicatorViewContainer.createView(
                mContext,
                mDisplayController.getDisplay(mTaskInfo.displayId),
@@ -143,7 +149,8 @@ public class DesktopModeVisualIndicator {
    public void fadeOutIndicator(
            @NonNull Runnable callback) {
        mVisualIndicatorViewContainer.fadeOutIndicator(
                mDisplayController.getDisplayLayout(mTaskInfo.displayId), mCurrentType, callback
                mDisplayController.getDisplayLayout(mTaskInfo.displayId), mCurrentType, callback,
                mTaskInfo.displayId, mSnapEventHandler
        );
    }

+1 −0
Original line number Diff line number Diff line
@@ -3051,6 +3051,7 @@ class DesktopTasksController(
                    rootTaskDisplayAreaOrganizer,
                    dragStartState,
                    bubbleController.getOrNull()?.bubbleDropTargetBoundsProvider,
                    snapEventHandler,
                )
        if (visualIndicator == null) visualIndicator = indicator
        return indicator.updateIndicatorType(PointF(inputX, taskTop))
+79 −14
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.wm.shell.shared.annotations.ShellDesktopThread
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.shared.bubbles.BubbleDropTargetBoundsProvider
import com.android.wm.shell.windowdecor.WindowDecoration.SurfaceControlViewHostFactory
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler

/**
 * Container for the view / viewhost of the indicator, ensuring it is created / animated off the
@@ -60,6 +61,7 @@ constructor(
    private val surfaceControlViewHostFactory: SurfaceControlViewHostFactory =
        object : SurfaceControlViewHostFactory {},
    private val bubbleBoundsProvider: BubbleDropTargetBoundsProvider?,
    private val snapEventHandler: SnapEventHandler,
) {
    @VisibleForTesting var indicatorView: View? = null
    private var indicatorViewHost: SurfaceControlViewHost? = null
@@ -164,9 +166,15 @@ constructor(
                displayController.getDisplayLayout(taskInfo.displayId)
                    ?: error("Expected to find DisplayLayout for taskId${taskInfo.taskId}.")
            if (currentType == IndicatorType.NO_INDICATOR) {
                fadeInIndicator(layout, newType)
                fadeInIndicator(layout, newType, taskInfo.displayId, snapEventHandler)
            } else if (newType == IndicatorType.NO_INDICATOR) {
                fadeOutIndicator(layout, currentType, /* finishCallback= */ null)
                fadeOutIndicator(
                    layout,
                    currentType,
                    /* finishCallback= */ null,
                    taskInfo.displayId,
                    snapEventHandler,
                )
            } else {
                val animStartType = IndicatorType.valueOf(currentType.name)
                val animator =
@@ -177,6 +185,8 @@ constructor(
                            animStartType,
                            newType,
                            bubbleBoundsProvider,
                            taskInfo.displayId,
                            snapEventHandler,
                        )
                    } ?: return@execute
                animator.start()
@@ -188,12 +198,24 @@ constructor(
     * Fade indicator in as provided type. Animator fades it in while expanding the bounds outwards.
     */
    @VisibleForTesting
    fun fadeInIndicator(layout: DisplayLayout, type: IndicatorType) {
    fun fadeInIndicator(
        layout: DisplayLayout,
        type: IndicatorType,
        displayId: Int,
        snapEventHandler: SnapEventHandler,
    ) {
        desktopExecutor.assertCurrentThread()
        indicatorView?.let {
            it.setBackgroundResource(R.drawable.desktop_windowing_transition_background)
            val animator =
                VisualIndicatorAnimator.fadeBoundsIn(it, type, layout, bubbleBoundsProvider)
                VisualIndicatorAnimator.fadeBoundsIn(
                    it,
                    type,
                    layout,
                    bubbleBoundsProvider,
                    displayId,
                    snapEventHandler,
                )
            animator.start()
        }
    }
@@ -207,6 +229,8 @@ constructor(
        layout: DisplayLayout,
        currentType: IndicatorType,
        finishCallback: Runnable?,
        displayId: Int,
        snapEventHandler: SnapEventHandler,
    ) {
        if (currentType == IndicatorType.NO_INDICATOR) {
            // In rare cases, fade out can be requested before the indicator has determined its
@@ -223,6 +247,8 @@ constructor(
                        animStartType,
                        layout,
                        bubbleBoundsProvider,
                        displayId,
                        snapEventHandler,
                    )
                animator.addListener(
                    object : AnimatorListenerAdapter() {
@@ -328,8 +354,17 @@ constructor(
                type: IndicatorType,
                displayLayout: DisplayLayout,
                bubbleBoundsProvider: BubbleDropTargetBoundsProvider?,
                displayId: Int,
                snapEventHandler: SnapEventHandler,
            ): VisualIndicatorAnimator {
                val endBounds = getIndicatorBounds(displayLayout, type, bubbleBoundsProvider)
                val endBounds =
                    getIndicatorBounds(
                        displayLayout,
                        type,
                        bubbleBoundsProvider,
                        displayId,
                        snapEventHandler,
                    )
                val startBounds = getMinBounds(endBounds)
                view.background.bounds = startBounds

@@ -345,11 +380,19 @@ constructor(
                type: IndicatorType,
                displayLayout: DisplayLayout,
                bubbleBoundsProvider: BubbleDropTargetBoundsProvider?,
                displayId: Int,
                snapEventHandler: SnapEventHandler,
            ): VisualIndicatorAnimator {
                val startBounds = getIndicatorBounds(displayLayout, type, bubbleBoundsProvider)
                val startBounds =
                    getIndicatorBounds(
                        displayLayout,
                        type,
                        bubbleBoundsProvider,
                        displayId,
                        snapEventHandler,
                    )
                val endBounds = getMinBounds(startBounds)
                view.background.bounds = startBounds

                val animator = VisualIndicatorAnimator(view, startBounds, endBounds)
                animator.interpolator = DecelerateInterpolator()
                setupIndicatorAnimation(animator, AlphaAnimType.ALPHA_FADE_OUT_ANIM)
@@ -375,9 +418,25 @@ constructor(
                origType: IndicatorType,
                newType: IndicatorType,
                bubbleBoundsProvider: BubbleDropTargetBoundsProvider?,
                displayId: Int,
                snapEventHandler: SnapEventHandler,
            ): VisualIndicatorAnimator {
                val startBounds = getIndicatorBounds(displayLayout, origType, bubbleBoundsProvider)
                val endBounds = getIndicatorBounds(displayLayout, newType, bubbleBoundsProvider)
                val startBounds =
                    getIndicatorBounds(
                        displayLayout,
                        origType,
                        bubbleBoundsProvider,
                        displayId,
                        snapEventHandler,
                    )
                val endBounds =
                    getIndicatorBounds(
                        displayLayout,
                        newType,
                        bubbleBoundsProvider,
                        displayId,
                        snapEventHandler,
                    )
                val animator = VisualIndicatorAnimator(view, startBounds, endBounds)
                animator.interpolator = DecelerateInterpolator()
                setupIndicatorAnimation(animator, AlphaAnimType.ALPHA_NO_CHANGE_ANIM)
@@ -389,6 +448,8 @@ constructor(
                layout: DisplayLayout,
                type: IndicatorType,
                bubbleBoundsProvider: BubbleDropTargetBoundsProvider?,
                displayId: Int,
                snapEventHandler: SnapEventHandler,
            ): Rect {
                val desktopStableBounds = Rect()
                layout.getStableBounds(desktopStableBounds)
@@ -417,21 +478,25 @@ constructor(
                        )
                    }

                    IndicatorType.TO_SPLIT_LEFT_INDICATOR ->
                    IndicatorType.TO_SPLIT_LEFT_INDICATOR -> {
                        val currentLeftBounds = snapEventHandler.getLeftSnapBoundsIfTiled(displayId)
                        return Rect(
                            padding,
                            padding,
                            desktopStableBounds.width() / 2 - padding,
                            currentLeftBounds.right - padding,
                            desktopStableBounds.height(),
                        )

                    IndicatorType.TO_SPLIT_RIGHT_INDICATOR ->
                    }
                    IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
                        val currentRightBounds =
                            snapEventHandler.getRightSnapBoundsIfTiled(displayId)
                        return Rect(
                            desktopStableBounds.width() / 2 + padding,
                            currentRightBounds.left + padding,
                            padding,
                            desktopStableBounds.width() - padding,
                            desktopStableBounds.height(),
                        )
                    }
                    IndicatorType.TO_BUBBLE_LEFT_INDICATOR ->
                        return bubbleBoundsProvider?.getBubbleBarExpandedViewDropTargetBounds(
                            /* onLeft= */ true
+29 −12
Original line number Diff line number Diff line
@@ -159,6 +159,8 @@ import kotlin.Pair;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

import org.jetbrains.annotations.NotNull;

import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.ExperimentalCoroutinesApi;
import kotlinx.coroutines.MainCoroutineDispatcher;
@@ -935,6 +937,18 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        return mDesktopTilingDecorViewModel.moveTaskToFrontIfTiled(taskInfo);
    }

    @Override
    @NotNull
    public Rect getLeftSnapBoundsIfTiled(int displayId) {
        return mDesktopTilingDecorViewModel.getLeftSnapBoundsIfTiled(displayId);
    }

    @Override
    @NotNull
    public Rect getRightSnapBoundsIfTiled(int displayId) {
        return mDesktopTilingDecorViewModel.getRightSnapBoundsIfTiled(displayId);
    }

    private class DesktopModeTouchEventListener extends GestureDetector.SimpleOnGestureListener
            implements View.OnClickListener, View.OnTouchListener, View.OnLongClickListener,
            View.OnGenericMotionListener, DragDetector.MotionEventHandler {
@@ -1321,6 +1335,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        /**
         * Perform a task size toggle on release of the double-tap, assuming no drag event
         * was handled during the double-tap.
         *
         * @param e The motion event that occurred during the double-tap gesture.
         * @return true if the event should be consumed, false if not
         */
@@ -1346,6 +1361,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    class EventReceiver extends InputEventReceiver {
        private InputMonitor mInputMonitor;
        private int mTasksOnDisplay;

        EventReceiver(InputMonitor inputMonitor, InputChannel channel, Looper looper) {
            super(channel, looper);
            mInputMonitor = inputMonitor;
@@ -1397,6 +1413,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    /**
     * Check if an EventReceiver exists on a particular display.
     * If it does, increment its task count. Otherwise, create one for that display.
     *
     * @param displayId the display to check against
     */
    private void incrementEventReceiverTasks(int displayId) {
+42 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.window.DisplayAreaInfo
import android.window.WindowContainerTransaction
import androidx.core.util.valueIterator
import com.android.internal.annotations.VisibleForTesting
import com.android.wm.shell.R
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayChangeController
@@ -148,4 +149,45 @@ class DesktopTilingDecorViewModel(
        if ((fromRotation % 2 == toRotation % 2)) return
        tilingTransitionHandlerByDisplayId.get(displayId)?.resetTilingSession()
    }

    fun getRightSnapBoundsIfTiled(displayId: Int): Rect {
        val tilingBounds =
            tilingTransitionHandlerByDisplayId.get(displayId)?.getRightSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
        val snapBounds =
            Rect(
                stableBounds.left +
                    stableBounds.width() / 2 +
                    context.resources.getDimensionPixelSize(R.dimen.split_divider_bar_width) / 2,
                stableBounds.top,
                stableBounds.right,
                stableBounds.bottom,
            )
        return snapBounds
    }

    fun getLeftSnapBoundsIfTiled(displayId: Int): Rect {
        val tilingBounds =
            tilingTransitionHandlerByDisplayId.get(displayId)?.getLeftSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
        val snapBounds =
            Rect(
                stableBounds.left,
                stableBounds.top,
                stableBounds.left + stableBounds.width() / 2 -
                    context.resources.getDimensionPixelSize(R.dimen.split_divider_bar_width) / 2,
                stableBounds.bottom,
            )
        return snapBounds
    }
}
Loading