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

Commit aa837f7b authored by Ivan Tkachenko's avatar Ivan Tkachenko Committed by Android (Google) Code Review
Browse files

Merge "Reformat drag to desktop transition handler" into main

parents 1ef1c0b8 4c84a943
Loading
Loading
Loading
Loading
+39 −40
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ import android.window.TransitionInfo.Change
import android.window.TransitionRequestInfo
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import com.android.internal.protolog.ProtoLog
import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD
import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_RELEASE
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT
import com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT
@@ -225,7 +225,9 @@ class DragToDesktopTransitionHandler(
        ) {
            // We have a valid dragged task, but the animation will be handled by
            // SplitScreenController; request the transition here.
            @SplitPosition val splitPosition = if (cancelState == CancelState.CANCEL_SPLIT_LEFT) {
            @SplitPosition
            val splitPosition =
                if (cancelState == CancelState.CANCEL_SPLIT_LEFT) {
                    SPLIT_POSITION_TOP_OR_LEFT
                } else {
                    SPLIT_POSITION_BOTTOM_OR_RIGHT
@@ -252,15 +254,15 @@ class DragToDesktopTransitionHandler(
        wct: WindowContainerTransaction
    ) {
        val state = requireTransitionState()
        val taskInfo = state.draggedTaskChange?.taskInfo
            ?: error("Expected non-null taskInfo")
        val taskInfo = state.draggedTaskChange?.taskInfo ?: error("Expected non-null taskInfo")
        val taskBounds = Rect(taskInfo.configuration.windowConfiguration.bounds)
        val taskScale = state.dragAnimator.scale
        val scaledWidth = taskBounds.width() * taskScale
        val scaledHeight = taskBounds.height() * taskScale
        val dragPosition = PointF(state.dragAnimator.position)
        state.dragAnimator.cancelAnimator()
        val animatedTaskBounds = Rect(
        val animatedTaskBounds =
            Rect(
                dragPosition.x.toInt(),
                dragPosition.y.toInt(),
                (dragPosition.x + scaledWidth).toInt(),
@@ -286,12 +288,7 @@ class DragToDesktopTransitionHandler(
        }
        wct.setWindowingMode(taskInfo.token, WINDOWING_MODE_MULTI_WINDOW)
        wct.setDensityDpi(taskInfo.token, context.resources.displayMetrics.densityDpi)
        splitScreenController.requestEnterSplitSelect(
            taskInfo,
            wct,
            splitPosition,
            taskBounds
        )
        splitScreenController.requestEnterSplitSelect(taskInfo, wct, splitPosition, taskBounds)
    }

    override fun startAnimation(
@@ -438,13 +435,14 @@ class DragToDesktopTransitionHandler(
            // requesting split select. Similar to the above, this can happen due to quick fling
            // gestures. We can simply request split here without needing to calculate animated
            // task bounds as the task has not shrunk at all.
            val splitPosition = if (state.cancelState == CancelState.CANCEL_SPLIT_LEFT) {
            val splitPosition =
                if (state.cancelState == CancelState.CANCEL_SPLIT_LEFT) {
                    SPLIT_POSITION_TOP_OR_LEFT
                } else {
                    SPLIT_POSITION_BOTTOM_OR_RIGHT
                }
            val taskInfo = state.draggedTaskChange?.taskInfo
                ?: error("Expected non-null task info.")
            val taskInfo =
                state.draggedTaskChange?.taskInfo ?: error("Expected non-null task info.")
            val wct = WindowContainerTransaction()
            restoreWindowOrder(wct)
            state.startTransitionFinishTransaction?.apply()
@@ -463,8 +461,10 @@ class DragToDesktopTransitionHandler(
    ) {
        val state = requireTransitionState()
        // We don't want to merge the split select animation if that's what we requested.
        if (state.cancelState == CancelState.CANCEL_SPLIT_LEFT ||
            state.cancelState == CancelState.CANCEL_SPLIT_RIGHT) {
        if (
            state.cancelState == CancelState.CANCEL_SPLIT_LEFT ||
                state.cancelState == CancelState.CANCEL_SPLIT_RIGHT
        ) {
            clearState()
            return
        }
@@ -574,7 +574,8 @@ class DragToDesktopTransitionHandler(
                                startTransitionFinishCb.onTransitionFinished(null /* null */)
                                clearState()
                                interactionJankMonitor.end(
                                    CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_RELEASE)
                                    CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_RELEASE
                                )
                            }
                        }
                    )
@@ -673,9 +674,7 @@ class DragToDesktopTransitionHandler(
        val wct = WindowContainerTransaction()
        restoreWindowOrder(wct, state)
        state.cancelTransitionToken =
            transitions.startTransition(
                TRANSIT_DESKTOP_MODE_CANCEL_DRAG_TO_DESKTOP, wct, this
            )
            transitions.startTransition(TRANSIT_DESKTOP_MODE_CANCEL_DRAG_TO_DESKTOP, wct, this)
    }

    private fun restoreWindowOrder(